电报机器人-Webhook

时间:2020-02-09 11:43:14

标签: python github heroku telegram-bot telegram-webhook

我通过GitHub将电报机器人部署到了Heroku(我使用Webhook),该机器人正在运行,但由于某种原因,它无法通过Webhook接收消息。

这是代码:

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)))

文件:

enter image description here

1 个答案:

答案 0 :(得分:0)

您是否在推送到heroku之前提交了Procfile?

我也忘记了提交Procfile,因此该应用程序没有运行。

如果这没有帮助,请在此处共享完整的git push日志。