簡體   English   中英

電報機器人 - 網絡鈎子

[英]Telegram Bot - 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)))

文件:

在此處輸入圖片說明

你在推送到heroku之前提交了Procfile嗎?

我也忘了提交 Procfile,所以應用程序沒有運行。

如果這沒有幫助,請在此處分享完整的 git push 日志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM