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.
2
Answers
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
Method 1 (WebZ)
Method 2 (Private Supergroups)
If the chat is a private channel/supergroup, you can do the following:
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.