Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Created May 21, 2017 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PandaWhoCodes/403897715249b976427c1a7f3ba8d6c4 to your computer and use it in GitHub Desktop.
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.
@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