Get TELEGRAM Channel/Group ID - telegram

Let's say, I've joined TELEGRAM group...
I am just a typical member of GROUP (and thus, cant use any bots there.. ?) so, I am unable to find out the way, how to get GROUP ID.

New Update
Just Simply Forward a message from your channel to This Bot: (https://telegram.me/getidsbot)
Update
1: Goto (https://web.telegram.org)
2: Goto your Gorup and Find your link of Gorup(https://web.telegram.org/#/im?p=g154513121)
3: Copy That number after g and put a (-) Before That -154513121
4: Send Your Message to Gorup
bot.sendMessage(-154513121, "Hi")
I Tested Now and Work like a Charm
Node.js:
Try using TelegramBot#getChat():
bot.getChat("#channelusername").then(function(chat) {
// 'chat' is a Chat object
console.log(chat.id);
});
See API getChat() method and Chat object.
Hope that helps.

There is a unofficicl Plus Messenger client for Android users, and you can see ID in group/channel info.
Supergroup and Channel will looks like 1068773197, which is -1001068773197 for bots (with -100 prefix).
If you just want to obtain channel/user ID, forward message to #RawDataBot.

there are lots of ways to do so.
simplest one: download plus messenger which is a fork of telegram. it shows every channel's id in the about page of that channel.
https://play.google.com/store/apps/details?id=org.telegram.plus&hl=en
thanks to #Sean:
Supergroup and Channel will looks like 1068773197, which is -1001068773197 for bots (with -100 prefix).
Above method works for channels, for groups you may use this method:
Just forward a single message from that chat to #RawDataBot. it will reply you with a json data containing chatid.

via code:
If you are a member of a group, you should receive updates from that group when ever there is any activity from that group. The updates will contain a chats list-element from which you can get a Channel which has the following relevant fields:
id: group_id,
title: "the_group_title",
username: "group_username"

As of my experience ,there are two popular libraries,
python-Telethon --->Telegram Client Library(uses api_id,api_hash)
python-Telegram-bot ---->Telegram Bot (uses api token)
There are lot of ways to get the user_id ,group_id,channel_id .
To get the these ids use Telethon client library
from telethon import TelegramClient,sync
api_id="xxx" #get from telegram website
api_hash="yyy" #get from telegram website
client=TelegramClient(session_object,api_id,api_hash)
client.start()
#To get the channel_id,group_id,user_id
for chat in client.get_dialogs():
print('name:{0} ids:{1} is_user:{2} is_channel{3} is_group:{4}'.format(chat.name,chat.id,chat.is_user,chat.is_channel,chat.is_group))
That is all about, it will print name and id of channel,group,user.
Also, it will check wheather the id is belong to channel or group or user
generally, Channel id starts with negrative(eg:-1001109500936) starts with (-100)
group id is normal and starts with negative
user id starts with positve
Another way is to use 'plus messanger app'
To see all the group,channel,user id
Cheers
Another Simple Way,
client=TelegramClient(session,api_id,api_hash)
client.start()
destination_entity_name="Type User(may be bot) or group or channel name"
entity=client.get_entity(destination_entity_name)
print(entity.stringify()) #All paratmeters
print(entity.id) #user(bot also considered as user) or group

That should be obtainable using tg-messenger-cli: https://github.com/vysheng/tg I haven't had time to try it out yet but friend has made some automated messages for his daughter. Should be quite versatile.

After hours spent, I was able to find the ID of GROUPS using CuteGram app.
Open group there, and click "COPY" icon, that opens a folder, and in the address you will see the ID.

Invite your bot to your group
and use ur bot to text /myid
then use the GetUpdates api, you shall have your group ID

Related

How to get topic id for telegram group chat?

Recently Telegram added support for Topics in Groups in Bot API version 6.3 and this support added into python-telegram-bot version 13.15 (please find changelog https://docs.python-telegram-bot.org/en/stable/changelog.html)
It's not clear how to get a Topic ID (message_thread_id) for topics in Grpups where topics enabeled.
Any suggestion?
I'm trying to find a way how to get topic id for telegram group chats. Please be aware that I talking about message_thread_id, please do not confuse with chat_id.
You can try to get the message_thread_id from the message link
send a message to the topic you need from the application
right click on the sent message and choose "Copy message link"
paste link somewhere
you will see something like this: https://t.me/c/1112223334/25/33
the value 25(value after long number) from the link will be message_thread_id
I assume that -100 + 1112223334 - will be equal chat_id
The number after will be message_thread_id
And the last one should be message_id

Telegram: How to find Group Chat ID?

I've been trying to solve this for three days and none pf the solutions I've found online seem to work, so I am going to have to ask for help.
I want to create a Telegram "Group Chat" to be used by members of a club I'm in. I created the chat named with the initials of the club, like: "ABCD" and added some members. Now I want to automate the sending of occasional messages to the group for all members to see. Weather forecast, random photograph from our gallery, etc.
Using #BotFather I created a bot called "ABCDbot" and noted the token for that bot. Now I have two "ABCD"s on my browser left side-panel. Selecting one gives me "ABCD bot" and selecting the other gives me "ABCD 123 members".
Using a perl script and LWP I can send a photo using
#!/usr/bin/perl -w
use feature 'say';
use LWP;
my $api = LWP::UserAgent->new ();
my $chat_id = '1234567890';
my $photo = '/home/user/gallery/photo999.jpg';
my $response = $api->post(
"https://api.telegram.org/bot<ABCDbot's token>/sendPhoto",
[ 'chat_id' => $chat_id,
'caption' => 'Photo Randomly Selected by the gallery',
'photo' => $photo,
],
'Content_Type' => 'form-data',
);
if ($response->is_success) {
say "Response..... Success!";
} else {
say "Response..... Failure!";
}
This works, providing I give it a legitimate chat_id and a legitimate file to send.
But the trouble is: I can't find the chat_id for the group chat with 123 members! Every method I've tried now proves to be obsolete or simply doesn't return the desired chat_id for the ABCD group chat. I can get my own chat ID or that of individual members of the group, or of the bot itself, and can successfully send photos, messages, etc to those destinations, but I just can't send anything to the group.
Can anybody walk me through the process of getting the chat_id for my group chat? Or direct me to a document describing an up-to-date, working method for obtaining same?
Assistance much appreciated.
Method 1 (WebZ)
This is based on JayeshRocks's question with some extra steps to make the ID work with Bot API. Thanks to him first.
Login to Telegram WebZ.
Open the chat you want to get its ID.
Your browser's address should look like https://web.telegram.org/z/#-1527776602.
Remove the protocol, domain and path keeping the anchor so your result looks like #-1527776602.
Replace "#-" with "-100" so it looks like -1001527776602.
You can now use your final result which should look like -1001527776602.
Method 2 (Private Supergroups)
If the chat is a private channel/supergroup, you can do the following:
Copy a link of a message. (It will look like https://t.me/c/1527776602/1002.)
Remove the protocol and domain name, so it looks like c/1527776602/1002.
Remove the first and last path, so it looks like 1527776602.
Append "-100" to the beginning of the result, so it looks like -1001527776602.
You can now use your final result which looks like -1001527776602.
Method 3 (Third-Party Bots)
If you trust 3rd party bots, there are many of them. A known one is #MissRose_bot which you can add it to your group and use its /id command. Another one is #usinfobot which works inline and only for public chats.
To get a telegram group ID you need to open the group on https://web.telegram.org/z/ when you do so click on the group you want to gain the ID of then if you look at the URL it will say something like https://web.telegram.org/z/#-1234567 and the numbers there is the ID of the telegram group!
Hope this helps

Telegram bot /getUpdates does not contain data

I have a bot that I have added to a group. I messages the group to get the group ID from the following:
https://api.telegram.org/bot1856444417:AAH4vG6lkAbFNkM41e4444k-3s42f0-abgs/getUpdates
but I just get the result:
{"ok":true,"result":[]}
I have tried removing the bot and re-addng it and I have tried # the bot but neither gives me a result.
When I originally created the bot I was able to get an ID from a chat I had with it directly but now even that has stopped working.
This method of getting the chatID seems so flakey. Am I doing something wrong or is there any other way to get the chatid?
For anyone having this issue, it is because your bot have the Privacy Group mode enabled.
On BotFather chat, list your created bots and select the respective bot where you to change the Group Privacy setting. Turn it off and there you go, now the result array from Telegram API will be properly displayed.
I got around this by creating another bot, adding it to the group, getting the ID from it and then deleting it.
Use getMe instead of getupdates. It worked for me.

Get telegram group ID

At first i should emphasis that this is a question about telegram GROUP NOT CHANNEL.I need to get group id to send message via telgram api.
I have review this link .
using #rawDataBot needs to add bot to group, that is not possible most of the times. CuteGram does not login (does not send login code) .so i can say none of the proposed method works.
so is there a new method -except adding a bot to the group- to get telgram group ID ?
if the answer is no, i need to know if it is possible to send message to group by using group name?!
the easiest way is to add #chatBotRaw the bot will dump raw data, and you can copy their chat_id or anything else you need,
Remember to remove the bot afterwards because it dumps raw data of every message sent/received in the group.
the simplest way i found is
open web-telegram in a browser
right click on the group name on the left menu
click 'inspect' button
you will see the group id in the attribute data-peer-id="-xxxxxxxxxx" or peer="-xxxxxxxxxx"
You can get chat id throw object "chat"
You can set middleware which handle new update
Example on Node.JS: bot.on('text', ctx => console.log('Chat id is:', ctx.chat.id))
P.S. group id and chat id are same
if using a bot is acceptable, you can use #username_to_id_bot - no need to add it to a group, just send username or invite link and get the id

A way to catch if user leave chat teleram bot

i find new_chat_participant or left_chat_participant but that work only in group chat.
I've used the new_chat_members event to know weather a new user joined the bot or not. But seems that this event will not be emitted.
But using the message event I will get the below result:
{"message_id":4,"from":{"id":324299944,"is_bot":false,"first_name":"foo","last_name":"bar","language_code":"en"},"chat":{"id":324299944,"first_name":"foo","last_name":"bar","type":"private"},"date":1513786467,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]
i write bot with java script and in the google app script .
my oreginal problem is how to find out a user stop or left the bot
For some reason that I was not able to find in the docs telegram doesn't send updates when user leaves the private group. It only does it for public groups (ex supergroups). Another curious thing is that the update message contains "left_chat_participant" and "left_chat_member" objects with the exact same info, probably for some bc
unfortunately currently there is no way to found out the user block the bot. new_chat_participant or left_chat_participant presented in telegram bot API v3 for completely another purpose.

Resources