Facebook Page Listener Custom Graph Template
Implement real time Facebook Page tracking with Kitewheel. This allows your brand to link up customer data to power automated real time engagement with customers on Facebook via your Page's feed or Facebook Messenger. Create a messenger bot that integrates NLP with with the central hub bringing context conversation context enriching real time automated responses.
See here for Facebook Messenger API and here for the Facebook Pages API.
Kitewheel listens as a Webhook subscribed to events for your Facebook page(s) and uses the Facebook graphAPI via the webservice adaptor to fetch user details and send messages.
Package contents
- Graphs:
- Facebook Event Listener (API Listener - webhook)
- Process FB Entries
- Process FB Messages
- Process FB Changes
- Process FB Entries
- Application Parameters Graph Template
- Used to store Facebook Page IDs
- Facebook Event Listener (API Listener - webhook)
- Nodes:
- Web Services
- getFacebookProfileMetadata - fetch first name, surname, id type (e.g. user, page, messengerpagescopedid) by Facebook ID
- sendFBMessage - send a message: raw text or template (buttons, images, attachments)
- Web Services
- Schema: transaction:{}, interaction:{}, profile:{}
Setup
Create a Facebook Application
Note: You will need rights to access the Facebook Page as an administrator
- Create a Facebook application https://developers.facebook.com/apps/ (or use existing one)
- Add the Messenger and Webhook Products to your app
- You need to add BOTH products in order to receive a page feed
- Link to a Facebook Page you want to track - recommended guide: Facebook Application Quick Start
- Get the access token for the page - copy this to notepad
- Don't fill out the webhook section yet
Deploy the template
- Create the Facebook Event Listener template
- Create the following tables
- Insert into appParams:
- The fbPageAccessToken - you copied it above
Update this URL to get your page name and page id https://graph.facebook.com/v2.10/me?access_token={your_fbPageAccessToken_here}
Creating Connections
- Set the database connection
- Set the facebook API connection
- Run the graph in listen mode with 10 iterations
Verify the webhook in Facebook
- Create the webhook
- This makes a call to your process to validate with a hub.challenge value that it expects to be echoed in plain text with a 200 response.
- Tip: if using the European hub, ensure your Callback URL contains api-eu.
- The Verify Token can be any value.
- Once validated, you can stop the graph
- Set the subscription to Page
- Subscribe to Feed and Messages
- Once validated, you can stop the graph
- On the Messenger product, subscribe to the following events
- If you have a wit.ai account (free and recommended) then add this to the messenger product for real time Natural Language Processing
- Complete the Facebook Messenger Bot Approval steps - essentially you just need to set up 2 standard responses and FB app testers will confirm your app works.
Using
- Run the listener and test by posting on your brand page (you can use the privacy settings to restrict who can see the post)
Notes:
What is likely to go wrong
- Verify Webhook fails
- Ensure the graph is running when you click verify - the graph must echo back the hub.challenge value as plain text
- I receive duplicate messages
- Receiving the same message twice is common as FB tries to ensure all messages are received by your webhook. However if >2 duplicates are being received then there might be a problem with your graph completing resulting in an HTTP 404 to Facebook who will then try send the message again. Check for unhandled errors stopping the transaction bubbling up to the top process and returning the response object.
- This is common. The graph handles duplicates
Typical Deliverables Plan
Use this plan to agree the requirements from the Kitewheel User and your client/ brand
Privacy Policy
© 2022 CSG International, Inc.