Telegram Bot “chat not found”

[亡魂溺海] 提交于 2020-04-10 07:41:46

问题


I have the following code in Python to send a message to myself from a bot.

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}

What am I doing wrong? I got myuserid by sending /getid to @myidbot and I got my token from @BotFather


回答1:


As @maak pointed out, you need to first send a message to the bot before the bot can send messages to you.




回答2:


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

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.

Hope that helps.



来源:https://stackoverflow.com/questions/41174831/telegram-bot-chat-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!