import telebot
from telebot import types, TeleBot
from flask import Flask, request
class Exception_Handler:
def handle(self, e: Exception):
# Here you can write anything you want for every type of exceptions
if isinstance(e, ApiTelegramException):
if e.description == "Forbidden: bot was blocked by the user":
print("Attention please! The user {} has blocked the bot. I can't send anything to them".format(message.from_user.username))
secret = "RANDOM_NUMBER"
bot: TeleBot = telebot.TeleBot('TOKEN', threaded=False, exception_handler = Exception_Handler())
bot.set_webhook("http://NAME.pythonanywhere.com/{}".format(secret), max_connections=1)
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def webhook():
if flask.request.headers.get('content-type') == 'application/json':
json_string = flask.request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return ''
else:
flask.abort(403)
what needs to be done to make it work?
I expected the webhook to work normally, maybe it's a certificate, if so, how to get it for the pythonanywhere service?