Python 电报机器人“找不到聊天”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41174831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Telegram Bot "chat not found"
提问by Bijan
I have the following code in Python to send a message to myself from a bot.
我在 Python 中有以下代码可以从机器人向自己发送消息。
import requests
token = '320835125:AAFUUC-fdo_EFzsCjvmxu8HBk7qVzZXXXXX'
method = 'sendMessage'
myuserid = 1949275XX
response = requests.post(
url='https://api.telegram.org/bot{0}/{1}'.format(token, method),
data={'chat_id': myuserid, 'text': 'hello friend'}
).json()
print(response)
but this returns {'description': 'Bad Request: chat not found', 'error_code': 400, 'ok': False}
但这会返回 {'description': 'Bad Request: chat not found', 'error_code': 400, 'ok': False}
What am I doing wrong? I got myuserid
by sending /getid
to @myidbot
and I got my token from @BotFather
我究竟做错了什么?我myuserid
通过发送/getid
到@myidbot
我得到了我的令牌@BotFather
回答by Bijan
As @maak pointed out, you need to first send a message to the bot before the bot can send messages to you.
正如@maak 指出的那样,您需要先向机器人发送消息,然后机器人才能向您发送消息。
回答by Martin S.
There is a way to send notifications messages to telegram. It's a bit tricky but the tutorial is great!
有一种方法可以将通知消息发送到电报。这有点棘手,但教程很棒!
http://bernaerts.dyndns.org/linux/75-debian/351-debian-send-telegram-notification
http://bernaerts.dyndns.org/linux/75-debian/351-debian-send-telegram-notification
I just sended a message of my apache state to a privat channel. Works also on public channel but it's not what i wantet. As you call a script (bash) you can prepare the parameters in any script language.
我刚刚将我的 apache 状态的消息发送到了一个私人频道。也适用于公共频道,但这不是我想要的。当您调用脚本 (bash) 时,您可以准备任何脚本语言的参数。
Hope that helps.
希望有帮助。