mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Add files via upload
This commit is contained in:
parent
747f14216b
commit
d84aa796c0
32
examples/webhook_examples/webhook_flask_heroku_echo.py
Normal file
32
examples/webhook_examples/webhook_flask_heroku_echo.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import telebot
|
||||||
|
import os
|
||||||
|
from flask import Flask, request
|
||||||
|
|
||||||
|
bot = telebot.TeleBot('token')
|
||||||
|
|
||||||
|
server = Flask(__name__)
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start'])
|
||||||
|
def start(message):
|
||||||
|
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
|
||||||
|
|
||||||
|
@bot.message_handler(func=lambda message: True, content_types=['text'])
|
||||||
|
def echo_message(message):
|
||||||
|
bot.reply_to(message, message.text)
|
||||||
|
|
||||||
|
@server.route("/bot", methods=['POST'])
|
||||||
|
def getMessage():
|
||||||
|
bot.process_new_messages(
|
||||||
|
[telebot.types.Update.de_json(request.stream.read().decode("utf-8")).message
|
||||||
|
])
|
||||||
|
return "!", 200
|
||||||
|
|
||||||
|
@server.route("/")
|
||||||
|
def webhook():
|
||||||
|
bot.remove_webhook()
|
||||||
|
bot.set_webhook(url="https://herokuProject_url/bot")
|
||||||
|
return "!", 200
|
||||||
|
|
||||||
|
server.run(host="0.0.0.0", port=os.environ.get('PORT', 5000))
|
||||||
|
|
||||||
|
server = Flask(__name__)
|
Loading…
Reference in New Issue
Block a user