skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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.

    1. Login to Telegram WebZ.
    2. Open the chat you want to get its ID.
    3. Your browser’s address should look like https://web.telegram.org/z/#-1527776602.
    4. Remove the protocol, domain and path keeping the anchor so your result looks like #-1527776602.
    5. Replace "#-" with "-100" so it looks like -1001527776602.
    6. 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:

    1. Copy a link of a message. (It will look like https://t.me/c/1527776602/1002.)
    2. Remove the protocol and domain name, so it looks like c/1527776602/1002.
    3. Remove the first and last path, so it looks like 1527776602.
    4. Append "-100" to the beginning of the result, so it looks like -1001527776602.
    5. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search