-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
39 lines (31 loc) · 1.06 KB
/
main.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
# !/usr/bin/env python3
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "vision_key.json"
import sys
import json
import logging
from telegram import Update
from bot_info import TOKEN, APP_URL
from flask import Flask, request
from bot_setup import setup
app = Flask(__name__)
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
update_queue, dispatcher = setup(TOKEN)
@app.route('/set_webhook')
def set_webhook():
if dispatcher.bot.set_webhook(APP_URL + '/' + TOKEN):
return "Webhook set"
else:
return "Webhook setup failed"
@app.route("/{}".format(TOKEN), methods=["POST"])
def webhook_handler():
# Retrieve the message in JSON and then transform it to Telegram object
update = Update.de_json(request.get_json(), dispatcher.bot)
update_queue.put(update)
return "ok!", 200
if __name__ == "__main__":
# Execute app on localhost instead of app engine.
# Be sure to update APP_URL on bot_info.py (not tracked)
app.run(host='127.0.0.1', port=8080, debug=True)