I'm listening to the optin event fired by Facebook Messenger. The docs say I should receive an object with { 'sender': { 'id': 'USER_ID' } }
in it. However, the data I get is missing this information. I do receive the optin event, and I get the rest of the data, but I'm missing the sender
.
The response I get looks like this:
"messaging"=>[{
"recipient"=>{"id"=>"MY_PAGE_ID"},
"timestamp"=>1503480281655,
"optin"=>{"ref"=>"PASS_THROUGH_PARAM", "user_ref"=>"5019"}
}]
I'm using the facebook-messenger gem to handle the webhook events. However I decided to intercept the request directly to check the data I was getting, which is what I used to generate the above response. The object the gem gives me looks like this:
#<Facebook::Messenger::Incoming::Optin:0x007fe2829a4928
@messaging={ "recipient"=>{"id"=>"MY_PAGE_ID"},
"timestamp"=>1503480091027,
"optin"=>{"ref"=>"PASS_THROUGH_PARAM", "user_ref"=>"58326"}
}>
Here's where I listen to the optin event.
Finally the click handler to fire the optin event is exactly per Facebook's documentation:
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
'app_id':'<%= Figaro.env.facebook_app_id %>',
'page_id':'<%= Figaro.env.facebook_page_id %>',
'ref':'PASS_THROUGH_PARAM',
'user_ref':'<%= @uniq_user_ref %>'
});
Here's the rest of that file in case it's valuable.
Is there anything else I need to set up or pass through to tell Facebook I want this information?
Is it possible you're using the Checkbox plugin instead of the Send to Messenger plugin? On the Checkbox documentation, they mention the following (emphasis mine):
Callback
After the opt-in event, we will post a webhook event to your server if the checkbox state was checked. This callback has the same format as the opt-in callback, but instead of a sender field, it has an optin object with a user_ref field.