From d84aa796c03c657e47d5fc2cbac3d9cf0f5846ae Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 25 May 2016 01:42:25 +0600 Subject: [PATCH 1/4] Add files via upload --- .../webhook_flask_heroku_echo.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/webhook_examples/webhook_flask_heroku_echo.py diff --git a/examples/webhook_examples/webhook_flask_heroku_echo.py b/examples/webhook_examples/webhook_flask_heroku_echo.py new file mode 100644 index 0000000..dcd18e8 --- /dev/null +++ b/examples/webhook_examples/webhook_flask_heroku_echo.py @@ -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__) \ No newline at end of file From e87907f0b85a8845673d2ec8a5587281c2e2e6f8 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 25 May 2016 01:44:09 +0600 Subject: [PATCH 2/4] Update webhook_flask_heroku_echo.py --- examples/webhook_examples/webhook_flask_heroku_echo.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/webhook_examples/webhook_flask_heroku_echo.py b/examples/webhook_examples/webhook_flask_heroku_echo.py index dcd18e8..e16fa1d 100644 --- a/examples/webhook_examples/webhook_flask_heroku_echo.py +++ b/examples/webhook_examples/webhook_flask_heroku_echo.py @@ -17,8 +17,7 @@ def echo_message(message): @server.route("/bot", methods=['POST']) def getMessage(): bot.process_new_messages( - [telebot.types.Update.de_json(request.stream.read().decode("utf-8")).message - ]) + [telebot.types.Update.de_json(request.stream.read().decode("utf-8")).message]) return "!", 200 @server.route("/") @@ -29,4 +28,4 @@ def webhook(): server.run(host="0.0.0.0", port=os.environ.get('PORT', 5000)) -server = Flask(__name__) \ No newline at end of file +server = Flask(__name__) From 59b19fbbc1959e01fe398dbf11181d00962ddf3f Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 25 May 2016 19:15:13 +0600 Subject: [PATCH 3/4] Update webhook_flask_heroku_echo.py --- examples/webhook_examples/webhook_flask_heroku_echo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webhook_examples/webhook_flask_heroku_echo.py b/examples/webhook_examples/webhook_flask_heroku_echo.py index e16fa1d..4db065e 100644 --- a/examples/webhook_examples/webhook_flask_heroku_echo.py +++ b/examples/webhook_examples/webhook_flask_heroku_echo.py @@ -2,7 +2,7 @@ import telebot import os from flask import Flask, request -bot = telebot.TeleBot('token') +bot = telebot.TeleBot('') server = Flask(__name__) From 05f1c87c7d90f9d024898ac39f72c98680e6b70d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 25 May 2016 19:25:46 +0600 Subject: [PATCH 4/4] Update webhook_flask_heroku_echo.py --- examples/webhook_examples/webhook_flask_heroku_echo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/webhook_examples/webhook_flask_heroku_echo.py b/examples/webhook_examples/webhook_flask_heroku_echo.py index 4db065e..4d8d584 100644 --- a/examples/webhook_examples/webhook_flask_heroku_echo.py +++ b/examples/webhook_examples/webhook_flask_heroku_echo.py @@ -27,5 +27,4 @@ def webhook(): return "!", 200 server.run(host="0.0.0.0", port=os.environ.get('PORT', 5000)) - server = Flask(__name__)