mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #463 from dmytrostriletskyi/master
Make the Heroku example actual
This commit is contained in:
commit
a1930e05c2
@ -1,29 +1,35 @@
|
|||||||
import telebot
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import telebot
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
|
|
||||||
bot = telebot.TeleBot('<api_token>')
|
TOKEN = '<api_token>'
|
||||||
|
bot = telebot.TeleBot(TOKEN)
|
||||||
server = Flask(__name__)
|
server = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['start'])
|
@bot.message_handler(commands=['start'])
|
||||||
def start(message):
|
def start(message):
|
||||||
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
|
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=lambda message: True, content_types=['text'])
|
@bot.message_handler(func=lambda message: True, content_types=['text'])
|
||||||
def echo_message(message):
|
def echo_message(message):
|
||||||
bot.reply_to(message, message.text)
|
bot.reply_to(message, message.text)
|
||||||
|
|
||||||
@server.route("/bot", methods=['POST'])
|
|
||||||
|
@server.route('/' + TOKEN, methods=['POST'])
|
||||||
def getMessage():
|
def getMessage():
|
||||||
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
|
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
|
||||||
return "!", 200
|
return "!", 200
|
||||||
|
|
||||||
|
|
||||||
@server.route("/")
|
@server.route("/")
|
||||||
def webhook():
|
def webhook():
|
||||||
bot.remove_webhook()
|
bot.remove_webhook()
|
||||||
bot.set_webhook(url="https://herokuProject_url/bot")
|
bot.set_webhook(url='https://your_heroku_project.com/' + TOKEN)
|
||||||
return "!", 200
|
return "!", 200
|
||||||
|
|
||||||
server.run(host="0.0.0.0", port=os.environ.get('PORT', 5000))
|
|
||||||
server = Flask(__name__)
|
if __name__ == "__main__":
|
||||||
|
server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
|
||||||
|
Loading…
Reference in New Issue
Block a user