首页 > 解决方案 > Django 没有收到电报 webhook

问题描述

我正在尝试构建一个电报机器人。我正在使用 django 应用程序。我托管了我的 django 应用程序,它运行良好。我正在使用 https 的 pythonanywhere 服务器上运行。我成功设置了我的网络钩子,它工作得很好。但我不知道为什么我的 django 服务器没有收到任何响应。这是我的views.py 代码

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import requests

@csrf_exempt
def telegram_bot(request):
    # print(request.GET)
    # print(request.POST)
    print("this is sample")
    if request.method == 'POST':
        requests.get('https://api.telegram.org/bot<token>/sendMessage?chat_id=<id>&text=this is a sample text')
return HttpResponse(status=200)

我只是在我的日志中打印一些示例消息,并将示例消息发送回电报到相应的聊天 ID。但是这段代码没有被触发,我不确定为什么会这样。

最后,我尝试了这个 https://api.telegram.org/bot /getWebhookInfo

它显示我在 pending_update_count 中尚未发送大约 22 条消息。

任何帮助都是可以接受的,谢谢

标签: pythondjangotelegram-bot

解决方案


推荐阅读