The application I am working on relies heavily on notifying users. I want to leverage the power of messenger by giving the user the ability to subscribe to notifications sent right to their Facebook Messenger. This only became an option for me when Facebook opened up the Facebook Messenger Platform, but I think it is a great way to use Facebook's fantastic product to my advantage and give the luxury to my users.
I have strong understanding of how the platform works and have created my own webhook receiver for the callbacks that are fired when the user selects the "Send to Messenger" plugin. I have also added the Facebook Javascript SDK and rendered the plugin on my page.
I have a few questions regarding the functionality:
Once the user goes through the flow that results in pressing the "Send To Messenger" button I am able to retrieve their sender_id from the webhook callback that is fired and make calls to the Send API using it to send them a message, when the user goes through the flow the plugin has a checkmark. But when I reload the page the plugin gets reset to the default state and does not have the checkmark, how can I render the plugin to have checked state? Because I know the users sender_id now, I don't need them to go through the flow again and fire the same callback. I have the ability to check if the user has gone through the flow, but how can I render the plugin in the correct state, looking for something like this:
if (user.sender_id?) { # show the check marked "Send To Messenger" plugin state } else { # show the default "Send To Messenger" plugin state <div class="fb-send-to-messenger" messenger_app_id="APP_ID" page_id="PAGE_ID" data-ref="PASS_THROUGH_PARAM" color="blue" size="standard"> </div> }
Can I store a users sender_id in my database once they have gone through the entry point once? Does the sender_id ever change?
Any insight is greatly appreciated, thanks!
The way I solved this was to set my User ID from my database as the 'ref' or 'pass through params' for the Messenger OptIn. Then in my webhook, when I received the request, I added the Sender ID to the database collection for my User.
When the user reloaded the page, if the user had an associated Sender ID, I didn't render the messenger plug in at all. The Sender ID doesn't change.