如何获取私人 Telegram 频道的 chat_id? [英] How to obtain the chat_id of a private Telegram channel?

查看:720
本文介绍了如何获取私人 Telegram 频道的 chat_id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 curl 来更新我的公共频道.这种语法:

I use curl to update my public channels. This kind of syntax:

curl -X POST "https://api.telegram.org/bot144377327:AAGqdElkZ-77zsPRoAXXXXXXXXXX/sendMessage" -d "chat_id=@MyChannel&text=my sample text"

但是私人频道的 chat_id 是什么?这不是您在私人邀请中拥有的那个.

But what's the chat_id of a private channel? It's not the one you have in the private invite.

因为现在我们可以在所有方法中传递一个频道用户名(格式为@channelusername)代替chat_id(而不是forwardMessage中的from_chat_id).但是我管理的私人频道的@channelusername 是什么?

Because now we can pass a channel username (in the format @channelusername) in the place of chat_id in all methods (and instead of from_chat_id in forwardMessage). But what's the @channelusername of a private channel that I administer?

推荐答案

我在私人频道找到了写作的方法.

I found the way to write in private channels.

  1. 你应该使用@channelName 将其转换为公开

  1. You should convert it to public with some @channelName

通过 Bot API 向该频道发送消息

Send message to this channel through Bot API

https://api.telegram.org/bot111:222/sendMessage?chat_id=@channelName&text=123

作为回复,您将获得带有您频道的 chat_id 的信息.

As response you will get info with chat_id of your channel.

{
  "ok" : true,
  "result" : {
    "chat" : {
      **"id" : -1001005582487,**
      "title" : "Test Private Channel",
      "type" : "channel"
    },
    "date" : 1448245538,
    "message_id" : 7,
    "text" : "123ds"
  }
}

  • 现在您可以将频道转换回私人频道(通过删除频道的链接)并直接向此 chat_id -1001005582487"发送消息

  • Now you can convert Channel back to private (by deleting channel's link) and send message directly to this chat_id "-1001005582487"

    https://api.telegram.org/bot111:222/sendMessage?chat_id=-1001005582487&text=123

    这篇关于如何获取私人 Telegram 频道的 chat_id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆