diff --git a/examples/web-hosted/heroku/Procfile b/examples/web-hosted/heroku/Procfile new file mode 100644 index 0000000..c79a8f9 --- /dev/null +++ b/examples/web-hosted/heroku/Procfile @@ -0,0 +1 @@ +web: gunicorn -b 0.0.0.0:$PORT app:app diff --git a/examples/web-hosted/heroku/app.py b/examples/web-hosted/heroku/app.py new file mode 100644 index 0000000..22449c6 --- /dev/null +++ b/examples/web-hosted/heroku/app.py @@ -0,0 +1,30 @@ +import os +from flask import Flask, request +import telepot + +try: + from Queue import Queue +except ImportError: + from queue import Queue + +app = Flask(__name__) +TOKEN = os.environ['PP_BOT_TOKEN'] # put your token in heroku app as environment variable +SECRET = '/bot' + TOKEN +URL = '' # paste the url of your application + +UPDATE_QUEUE = Queue() +BOT = telepot.Bot(TOKEN) + +def on_chat_message(msg): + content_type, chat_type, chat_id = telepot.glance(msg) + BOT.sendMessage(chat_id, 'hello!') + +BOT.message_loop({'chat': on_chat_message}, source=UPDATE_QUEUE) # take updates from queue + +@app.route(SECRET, methods=['GET', 'POST']) +def pass_update(): + UPDATE_QUEUE.put(request.data) # pass update to bot + return 'OK' + +BOT.setWebhook() # unset if was set previously +BOT.setWebhook(URL + SECRET) diff --git a/examples/web-hosted/heroku/requirements.txt b/examples/web-hosted/heroku/requirements.txt new file mode 100644 index 0000000..31ac699 --- /dev/null +++ b/examples/web-hosted/heroku/requirements.txt @@ -0,0 +1,3 @@ +flask +telepot +gunicorn \ No newline at end of file diff --git a/examples/web-hosted/heroku/runtime.txt b/examples/web-hosted/heroku/runtime.txt new file mode 100644 index 0000000..40e1f55 --- /dev/null +++ b/examples/web-hosted/heroku/runtime.txt @@ -0,0 +1 @@ +python-3.5.1 \ No newline at end of file