I am trying to find the API endpoint for telegram… a public one that does not require any login or API keys…
I found this: https://core.telegram.org/schema/json which includes a long JSON list of functions. Not sure if there are other API endpoints that can be used to query just a group and show stats for that group or how exactly to go about it.
I have seen other users suggest creating a telegram bot and then pull this data from the bot however not sure exactly how to do this effectively.
The main goal is to simply display the total users of a group via javascript and add the number via <span id="telegram-users">1</span>
I have seen this being done on coingecko’s coins and token listings under social however can not figure out how to simply show the total number of a telegram group in simple HTML format from JSON data for API..
UPDATE:
I did some research and freshened up on my coding skills.
There is this website: https://tgstat.com/ that pulls data for telegram channels. I am trying to use a simple javascript function to fetch
this url and then use jsoup
to get the data by using the element identifier which is .columns.large-2.medium-4.small-6.margin-bottom15 > div > .align-center > #text
Then use document.getElementById("telegram-members").innerHTML = ()
to display this data in html.
I understand the cosp and will use https://api.allorigins.win/raw?url= to bypass this.
2
Answers
This question has been moved here for easier understanding of the issue. How to pull data from another website using Javascript or jQuery (cross-domain) CORS (no api)
Alright, if I understand your question well. You’re trying to get the total number of users from a telegram group, channel, or chat.
The premise is, you want to avoid using Telegram API which will require auth token.
However, since your main goal is just basically the same. I’ll leave this method here, so you’ll have a "backup plan" later.
At most usage, you just need to send a HTTP request to the Telegram API.
API Example:
https://api.telegram.org/bot<token-here>?<api-method-here>
You can learn more about other API method Here.
Hold Up!
Firstly, what do you want to track? Is it a group? Is it a channel?
Both have different method, please check out the example below!.
To track the number of members that are following a channel
This is fairly easy. Just send a HTTP request to:
https://api.telegram.org/bot<token-here>/getChatMembersCount?chat_id=<channel-name>
For example: the name of the official telegram channel is
@telegram
.Sooo, send a request to:
https://api.telegram.org/bot<token-here>/getChatMembersCount?chat_id=@telegram
You’ll get a response like:
The total number of followers is shown in the
result
key.To track the number of members in a group chat
Before we can get the number of members in a group. You need to find the <chat_id> for your group chat.
Note: Your bot must join the group before you can do anything like tracking, send message etc.
To do that, send a HTTP request to
https://api.telegram.org/bot<token-here>/getUpdates
.Look closely into the response. You need to find the
chat
object, like this.You just need the
id
from thechat
object. Which is-1234567890
in this case.After you got the
chat_id
number.Just send a HTTP request to:
https://api.telegram.org/bot<token-here>/getChatMembersCount?chat_id=<id-number>
You’ll also get the response as:
The number of members is stored in the
result
key. Just parse it out and boom!Full Example