我是一个拥有各种主题的超级群组的管理员。我想发送一条给定的消息,说“嗨!”到主题之一。发送到该主题的第一条消息的消息链接是 https://t.me/c/211XXXXXXX/16/17
如何发送“嗨!”到这个话题?
如果您是管理员,那么您有权获取您所在组的访问令牌。
如果您遇到机器人令牌问题,可以查看这篇文章:https://helpdesk.bitrix24.com/open/17622486/
替换下面代码中的机器人令牌和聊天 ID,
import requests
bottoken = 'BOT_TOKEN'
chat_id = '211XXXXXXX'
message = 'Hi!'
根据上述信息创建以下 URL,
url = f'https://api.telegram.org/bot{bottoken}/sendMessage'
# Set the parameters
params = {
'chat_id': chat_id,
'text': message
}
在这里,您可以查看已发送消息的回复:
resp = requests.post(url, params=params)
# Check the response
if resp.status_code == 200:
print('Message sent successfully!')
else:
print('Failed to send message:', response.text)
如果代码不起作用,请在评论中告诉我。