Answer the question
In order to leave comments, you need to log in
How to make webhook in telegram bot and put it on hosting?
I am using Telebot library. It's time to put the bot on the host (I want to use Pythonanywhere). Now the bot works on bot.polling(), I want to transfer it to Webhook, but after looking at the documentation I didn’t understand anything exactly how to do it.
Tell me how to make a webhook and how to upload it to the hosting?
Answer the question
In order to leave comments, you need to log in
In the secret of some kind of line, so that no one needs to poke once again.
First you need to remove the hook, suddenly it already exists, then re-attach. username - name on pythonanywhere
Then we hang the hook.
secret = '43d2yIyIVM'
username = 'user'
bot.remove_webhook()
time.sleep(1)
bot.set_webhook(url='https://{}.pythonanywhere.com/{}'.format(username, secret))
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def webhook():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return 'ok', 200
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question