电报:如何找到组聊天ID?

发布于 2025-02-07 18:55:15 字数 1153 浏览 2 评论 0 原文

我一直在尝试解决这个问题三天,而没有PF我在网上发现的解决方案似乎有效,所以我必须寻求帮助。

我想创建一个电报“小组聊天”,以由我所在的俱乐部成员使用。我创建了带有俱乐部缩写的聊天,例如:“ ABCD”并添加了一些成员。现在,我想自动将偶尔的消息发送给小组以供所有成员查看。天气预报,我们的画廊的随机照片等。

使用@botfather,我创建了一个名为“ Abcdbot”的机器人,并指出了该机器人的令牌。现在,我的浏览器左侧面板上有两个“ ABCD”。选择一个给我“ ABCD bot”,然后选择另一个给我“ ABCD 123成员”。

使用Perl脚本和LWP,我可以使用此作品发送照片

#!/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!";
}

,只要我给它一个合法的CHAT_ID和一个合法的文件即可发送。 但是麻烦是:我找不到与123名成员的小组聊天的chat_id !我现在尝试过的每种方法都被证明是过时的,或者根本不会返回ABCD组聊天所需的CHAT_ID。我可以获取自己的聊天ID或小组的个别成员或机器人本身的聊天ID,并且可以成功地将照片,消息等发送给这些目的地,但是我只是无法将任何东西发送给组。

有人可以带我完成我的小组聊天的CANT_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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

左秋 2025-02-14 18:55:15

方法1( web a

这是基于Jayeshrocks的问题,并具有一些额外的步骤,以使ID与Bot API一起使用。

  1. 登录到 telegram web a
  2. 打开您要获得其ID的聊天。
  3. 您的浏览器的地址应该看起来像 https://web.telegram.org.org/a/a/a https://web.telegram.org.org/a/a/web.-15277777777766602
  4. 删除该方案,主机名和路径,保持锚固,以使您的结果看起来像#-1527776602。
  5. 用“ -100”替换“# - ”,因此看起来像-1001527776602。
  6. 现在,您可以使用最终结果,看起来像-1001527776602。

方法2(私有超级组)

如果聊天是一个私人频道/超级组,则可以执行以下操作:

  1. 复制消息的链接。 (看起来像 https://t.me/c/c/15277766602/1002
  2. 删除协议和域名,因此看起来像C/1527776602/1002。
  3. 删除第一个和最后的路径,因此看起来像1527776602。
  4. 在结果的开始上附加“ -100”,因此看起来像-1001527776602。
  5. 现在,您可以使用最终结果,看起来像-100152776602。

方法3(第三方机器人)

如果您相信第三方机器人,则其中许多。一个已知的是@missrose_bot 您可以将其添加到您的组并使用其/ID命令。另一个是@usinfobot 仅适用于内联,仅适用于公众聊天。

Method 1 (Web A)

This is based on JayeshRocks’s question with some extra steps to make the ID work with Bot API.

  1. Login to Telegram Web A.
  2. Open the chat you want to get its ID.
  3. Your browser’s address should look like https://web.telegram.org/a/#-1527776602.
  4. Remove the scheme, the hostname and the 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.

蓝天 2025-02-14 18:55:15

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

你穿错了嫁妆 2025-02-14 18:55:15

这是一个简单的电报机器人的Python代码,该机器人打印任何聊天ID。将您的机器人添加到组聊天中,然后发送一条消息在组聊天中 @提及bot。

要创建一个机器人并获取API令牌,请写入 @botfather

import telebot
bot = telebot.TeleBot('token')


@bot.message_handler(func=lambda _: True)
def handle(message):
    bot.send_message(message.chat.id, f'{message.chat.id}')


def main():
    bot.infinity_polling()


if __name__ == "__main__":
    main()

Here's a Python code for a simple Telegram bot that prints any chat ID. Add your bot to the group chat and send a message mentioning the bot by @ in the group chat.

To create a bot and get the API token, write to @BotFather.

import telebot
bot = telebot.TeleBot('token')


@bot.message_handler(func=lambda _: True)
def handle(message):
    bot.send_message(message.chat.id, f'{message.chat.id}')


def main():
    bot.infinity_polling()


if __name__ == "__main__":
    main()
你的笑 2025-02-14 18:55:15

我尝试了上面的安格斯,但没有成功。

获取组聊天的正确聊天ID的唯一方法是将@getMyID_bot添加到兴趣组 ,然后向组发送消息
答案是用户聊天ID和组的聊天ID。

警告:验证,您将正确的机器人添加到您的组(如上所述的名称​​完全) - 据我所知,只能在应用程序中区分。

I tried the anwers above but did not succeed.

The only way to get the correct chat id of a group chat was to add @getmyid_bot to the group of interest and then send a message to the group.
The answer is the users chat id and the chat id of the group.

Warning: Verify, that you add the correct bot to your group (name exactly as mentioned above) - which can only be distinguished in the app as far as I know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文