-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwsgi.py
49 lines (39 loc) · 1.54 KB
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# Copyright (C) 2016 Javier Ayres
#
# This file is part of python-telegram-bot-openshift.
#
# python-telegram-bot-openshift is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# python-telegram-bot-openshift is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with python-telegram-bot-openshift. If not, see <http://www.gnu.org/licenses/>.
import os
import bot
from flask import Flask, request
from telegram import Update
application = Flask(__name__, instance_path=os.environ['OPENSHIFT_REPO_DIR'])
update_queue, bot_instance = bot.setup(webhook_url='https://{}/{}'.format(
os.environ['OPENSHIFT_GEAR_DNS'],
bot.TOKEN
))
@application.route('/')
def not_found():
"""Server won't respond in OpenShift if we don't handle the root path."""
return ''
@application.route('/' + bot.TOKEN, methods=['GET', 'POST'])
def webhook():
if request.json:
update_queue.put(Update.de_json(request.json, bot_instance))
return ''
if __name__ == '__main__':
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
application.run(host=ip, port=port)