I deployed my telegram bot via GitHub to Heroku (I use Webhook), the bot is running, but for some reason it does not receive messages through the webhook.
Here's the code:
import os
import telebot
from flask import Flask, request
#I deleted an irrelevant code here for the question ...
server = Flask(__name__)
TOKEN = "..."
bot = telebot.TeleBot(token=TOKEN)
@bot.message_handler(commands=['start']) # welcome message handler
def send_welcome(message):
#I deleted an irrelevant code here for the question ...
@bot.message_handler(commands=['help']) # help message handler
def send_welcome(message):
#I deleted an irrelevant code here for the question ...
@bot.message_handler(func=lambda msg: msg.text)
def converter(message):
#I deleted an irrelevant code here for the question ...
@server.route('/' + TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
@server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url='https://myherokuapp.herokuapp.com/' + TOKEN)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
the files: