SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os, sys
  2. from flask import Flask, request
  3. from pymessenger import Bot
  4.  
  5. app = Flask(__name__)
  6.  
  7. PAGE_ACCESS_TOKEN = "EAAGdsANLN0wBAGQDHLxzgTAfDQCubTe6r3gZBlYVtVTmVTKAYcxcVLKFxHJxx2VZBVv7ZCp9Y553jRPQMwumCb4niYbQYpi0ZCjBgbOrcHwdaZCd8TNuZB92KsccjHlv8qZBIgOZC8LBjnkZBy2aexU0ezPS4qmSzRPofucvyhBKLTgZDZD"
  8.  
  9. bot = Bot(PAGE_ACCESS_TOKEN)
  10.  
  11.  
  12. @app.route('/', methods=['GET'])
  13. def verify():
  14.     # Webhook verification
  15.     if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
  16.         if not request.args.get("hub.verify_token") == "hello":
  17.             return "Verification token mismatch", 403
  18.         return request.args["hub.challenge"], 200
  19.     return "Hello world", 200
  20.  
  21.  
  22. @app.route('/', methods=['POST'])
  23. def webhook():
  24.     data = request.get_json()
  25.     log(data)
  26.  
  27.     if data['object'] == 'page':
  28.         for entry in data['entry']:
  29.             for messaging_event in entry['messaging']:
  30.  
  31.                 # IDs
  32.                 sender_id = messaging_event['sender']['id']
  33.                 recipient_id = messaging_event['recipient']['id']
  34.  
  35.                 if messaging_event.get('message'):
  36.                     # Extracting text message
  37.                     if 'text' in messaging_event['message']:
  38.                         messaging_text = messaging_event['message']['text']
  39.                     else:
  40.                         messaging_text = 'no text'
  41.  
  42.                     # Echo
  43.                     response = messaging_text
  44.                     bot.send_text_message(sender_id, response)
  45.  
  46.         return "ok", 200
  47.  
  48.  
  49. def log(message):
  50.     print(message)
  51.     sys.stdout.flush()
  52.  
  53.  
  54. if __name__ == "__main__":
  55.     app.run(debug=True, port=80)
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. Traceback (most recent call last):
  63.   File "/Volumes/Datos/Bot facebook/bot.py", line 55, in <module>
  64.     app.run(debug=True, port=80)
  65.   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 772, in run
  66.     run_simple(host, port, self, **options)
  67.   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/werkzeug/serving.py", line 968, in run_simple
  68.     s.bind(server_address)
  69. PermissionError: [Errno 13] Permission denied
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top