Answer the question
In order to leave comments, you need to log in
Trouble with telebot + Django. Is it possible to attach a telegram bot to Django?
Hey!
I'm trying to connect a telegram bot and a Django admin panel. Django models described. everything works, but the bot does not want to start! Can you tell me where I took a wrong turn?
My steps:
1) Set a webhook to a domain with a certificate ( https://mydomain.com/bot)
2) Django urls.py resulted in this:
from django.contrib import admin
from django.urls import path
from bot import views as bot
urlpatterns = [
path('admin/', admin.site.urls),
path('bot/', bot.stuff),
]
from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
import telebot
@csrf_exempt
def stuff(message):
bot = telebot.TeleBot(МОЙ ТОКЕН)
@bot.message_handler(content_types=['text'])
def echo(message):
bot.send_message(message.chat.id, message.text)
return HttpResponse("I`m not working like that!")
{"ok":true,<br>
"result":{"url":"https://mydomain.com/bot/",<br>
"has_custom_certificate":false,<br>
"pending_update_count":1,<br>
"last_error_date":1530615883,<br>
"last_error_message":"Wrong response from the webhook: 403 Forbidden",<br>
"max_connections":40}}
Answer the question
In order to leave comments, you need to log in
django-cors-headers are not needed
Here is a working version.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question