Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from queue import Queue
  2. from threading import Thread
  3.  
  4. from flask import Flask, request
  5. import urllib3
  6.  
  7. from telegram import Bot
  8. from telegram.ext import Dispatcher
  9. from telegram.ext import CommandHandler
  10.  
  11. # VARS
  12. TOKEN = "822191328:AAG7cD-SMqtD2i4ZB5NEG3GAOMVAxBKBZVQ"
  13.  
  14. app = Flask(__name__)
  15.  
  16. def start(update, context):
  17.     print(2)
  18.     context.bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
  19.     print(1)
  20.  
  21.  
  22. def setup(TOKEN):
  23.     # Create bot, update queue and dispatcher instances
  24.     bot = Bot(TOKEN)
  25.     update_queue = Queue()
  26.    
  27.     dispatcher = Dispatcher(bot, update_queue, use_context=True)
  28.    
  29.     ##### Register handlers here #####
  30.     start_handler = CommandHandler('start', start)
  31.     dispatcher.add_handler(start_handler)
  32.    
  33.     # Start the thread
  34.     thread = Thread(target=dispatcher.start, name='dispatcher')
  35.     thread.start()
  36.  
  37.     print("setuped")
  38.  
  39.     return update_queue
  40.  
  41. update_queue = setup(TOKEN)
  42.  
  43. @app.route('/{}'.format(TOKEN), methods=["POST"])
  44. def webhook():
  45.     update = request.get_json()
  46.  
  47.     update_queue.put(update)
  48.  
  49.     return "200"
  50.  
  51. if __name__ == '__main__':
  52.     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