Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from queue import Queue
- from threading import Thread
- from flask import Flask, request
- import urllib3
- from telegram import Bot
- from telegram.ext import Dispatcher
- from telegram.ext import CommandHandler
- # VARS
- TOKEN = "822191328:AAG7cD-SMqtD2i4ZB5NEG3GAOMVAxBKBZVQ"
- app = Flask(__name__)
- def start(update, context):
- print(2)
- context.bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
- print(1)
- def setup(TOKEN):
- # Create bot, update queue and dispatcher instances
- bot = Bot(TOKEN)
- update_queue = Queue()
- dispatcher = Dispatcher(bot, update_queue, use_context=True)
- ##### Register handlers here #####
- start_handler = CommandHandler('start', start)
- dispatcher.add_handler(start_handler)
- # Start the thread
- thread = Thread(target=dispatcher.start, name='dispatcher')
- thread.start()
- print("setuped")
- return update_queue
- update_queue = setup(TOKEN)
- @app.route('/{}'.format(TOKEN), methods=["POST"])
- def webhook():
- update = request.get_json()
- update_queue.put(update)
- return "200"
- if __name__ == '__main__':
- app.run(host='0.0.0.0', port="80", ssl_context=('/etc/letsencrypt/live/grinrill.ml/fullchain.pem', '/etc/letsencrypt/live/grinrill.ml/privkey.pem'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement