Advertisement
doanhtu

Flask app with Telegram bot

Mar 9th, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # pip install flask-cors python-telegram-bot
  2. # - chat with @BotFather, create new bot ==> fill the TOKEN. (https://core.telegram.org/bots#6-botfather)
  3. # - Chat with new bot something ==> access to https://api.telegram.org/bot<TOKEN>/getUpdates ==> Copy the chat ID then      #   fill the argument below.
  4. # - Profits??
  5.  
  6. import json
  7.  
  8. from flask import Flask, request
  9. from flask_cors import CORS
  10.  
  11. import telegram
  12.  
  13. bot = telegram.Bot(token='TOKEN')
  14.  
  15. app = Flask(__name__)
  16. CORS(app)
  17.  
  18. @app.route("/")
  19. def hello_world():
  20.     bot.send_message(chat_id='CHAT_ID', text=json.dumps(request.args))
  21.     return "Hello, cross-origin-world!"
  22.  
  23.  
  24. if __name__ == '__main__':
  25.     app.run(host='0.0.0.0', port=12333)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement