Created
May 21, 2017 10:19
-
-
Save PandaWhoCodes/403897715249b976427c1a7f3ba8d6c4 to your computer and use it in GitHub Desktop.
When your facebook page recieves a message, the following code is used to extract the vital information from the message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/', methods=['POST']) | |
def webhook(): | |
# endpoint for processing incoming messaging events | |
data = request.get_json() | |
log(data) # you may not want to log every incoming message in production, but it's good for testing | |
if data["object"] == "page": | |
for entry in data["entry"]: | |
for messaging_event in entry["messaging"]: | |
if messaging_event.get("message"): # someone sent us a message | |
sender_id = messaging_event["sender"]["id"] # the facebook ID of the person sending you the message | |
recipient_id = messaging_event["recipient"]["id"] # the recipient's ID, which should be your page's facebook ID | |
message_text = messaging_event["message"]["text"] # the message's text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment