0

Я пытаюсь написать бота с помощью вебхуков телеграмма на django. С помощью ссылки добавляю вебхук и все обновления поступают:

https://api.telegram.org/bot<token>/setWebhook?url=https://example.com/api/<token>

Однако все POST запросы приходят пустые.

Код:

# views.py
@csrf_exempt
def tgwebhook(request: WSGIRequest, token):
    if request.method == "POST":
        print(token, dict(request.POST.lists()))
        return HttpResponse()

# urls.py
urlpatterns = [
    path('<str:token>', views.tgwebhook, name="telegram_webhook")
]

Консоль сервера:

System check identified no issues (0 silenced).
June 07, 2021 - 10:56:44
Django version 3.1.4, using settings 'web.settings'
Starting ASGI/Channels version 3.0.3 development server at http://localhost:8080/
Quit the server with CTRL-BREAK.
<token> {}
HTTP POST /api/<token> 200 [0.02, 127.0.0.1:54289]

1 ответ 1

0

Я не от туда брал инфу :\

# views.py
@csrf_exempt
def tgwebhook(request: WSGIRequest, token):
    if request.method == "POST":
        print(token, json.loads(request.read()))
        return HttpResponse()

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.