我正在尝试使用django和pyTelegramBotApi在python中创建一个简单的tg bot,它在a/start上回答“Hello”。我已经设置了webhook,bot可以正确地获得更新,但是当它发送消息时,它只是走下坡路,什么也不发送
@csrf_exempt
def update_bot(request):
json_str = request.body.decode("UTF-8")
update = types.Update.de_json(json_str)
tele_bot.process_new_updates([update])
return HttpResponse({'code': 200})
@tele_bot.message_handler(commands=['start'])
def start_message(message):
print("sending message")
print(tele_bot.send_message(message.chat.id, "Hello"))
控制台输出是
sending message
[24/Dec/2020 10:54:46] "POST /bot/imagesmanager/ HTTP/1.1" 200 4
我已经解决了这个问题。我刚刚用结尾处的\n阅读了我的令牌(在
repr(token)
中找到),idk为什么更新工作正常,但简单的strip对我帮助很大)我不确定错误是什么,因为消息没有被打印出来,但我已经使用这个:
https://api.telegram.org/{bot_id}/sendMessage
很久了,它工作得很好。documentation在如何使用这种形式的api方面提供了大量信息相关问题 更多 >
编程相关推荐