messaging_optins webhook event not working for messenger
MahbbRah opened this issue · 40 comments
Hi, I'm trying to get the event when the developer/tester/admin click on the messenger plugin to start chat chat
these are the selected event with my app:
Selected events: messages, messaging_postbacks, messaging_optins
from these 3 events, two are working perfectly. but messaging_optins
isn't working.
https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messaging_optins
from that link above it is mentioned:
This callback will occur when the send to Messenger plugin has been tapped, a user has accepted a message request using customer matching, or a user has opted in to receive messages via the checkbox plugin.
I'm tapping on the start chat button with different developer account. but everytime it fails to send me the webhook for this.
Can you guys please help me on that?
This webhook has worked in the past, and I presume it still works and is handled. I do not believe Facebook has altered the format/behavior of this webhook.
However, as recently as today, I've seen that my facebook apps are not receiving this particular webhook anymore. I do not think they are being sent to my app like they used to. It may be a Facebook issue, not a gem issue.
I've submitted a bug ticket: https://developers.facebook.com/support/bugs/741132709584536/?disable_redirect=0
Someone else submitted a similar one in July 2018: https://developers.facebook.com/support/bugs/412333332610803/?disable_redirect=0
Facebook has not resolved these issues, or commented recently on the bugs reported.
This webhook, and this gem, definitely was working within the last month for me. It has been working most of the year without any issue. Facebook may have made changes, or introduced a new bug on their end. Unsure at this time.
from these 3 events, two are working perfectly. but
messaging_optins
isn't working.
Similar here.
messages
works, but messaging_optins
doesn't.
( Have not tried messaging_postbacks
yet )
Facebook has not resolved these issues, or commented recently on the bugs reported.
Does this mean messaging_optins
works for most people (or Facebook App/Pages) other than us/ours?
Or maybe only few people use this webhook??
Does this mean messaging_optins works for most people (or Facebook App/Pages) other than us/ours Or maybe only few people use this webhook??
It does seem to work for most people. In our own testing/analytics, we see that the percentage of FB Messenger Checkbox checked vs the messaging_optin
received from Facebook is over 90%. Meaning that 90% of the time, if a user checks the Facebook Messenger Checkbox and submits a form on the page, we receive a messaging_optin
webhook from Facebook like we expect. The other 10% of the time something went wrong, and we are still investigating whether it's on our side, or FB.
But, since there is that outstanding Facebook bug around the messaging_optin
webhook, it could be on their side, but they have not identified the issue yet, but have added more logging on their end.
Thank you for your response! That helps a lot!!
In our own testing/analytics, we see that the percentage of FB Messenger Checkbox checked vs the messaging_optin received from Facebook is over 90%.
I would appreciate if you could help us once again 🙇
Do you mean this percentage is independent of which Facebook App/Page (/account?) you use?
We (actually, mainly one of my colleagues) tried with one or a few Facebook Apps/Pages from his personal Facebook account.
He says messaging_optin
webhook worked only once, among like a hundred trials.
I wonder if we should try with other Facebook Apps/Pages/accounts, or the situation indicates the problem seems to be in our (me and my colleague's) side in this case.
Thanks again & Thanks in advance!!
Do you mean this percentage is independent of which Facebook App/Page (/account?) you use?
Yes, kind of. We have multiple users on our site, and each one has a different Facebook account, and Facebook Pages through our SINGLE Facebook app.
He says messaging_optin webhook worked only once, among like a hundred trials.
Oddly enough, my own personal account and FB pages do not seem to send the messaging_optin
webhooks anymore to our app server. It is not clear why Facebook is no longer sending optins that should fire due to my FB account clicking a FB Checkbox on a page, but, I'm one of the 10% of users where the messaging_optin
webhooks simply does not arrive anymore. Prior to about November 2018, I did not have this issue at all, and it seemed like we received 100% of the webhooks we expected. But, we did not have our own analytics tracking setup at the time, so I cannot be certain about the percentage of "successful" webhooks then. We only recently added analytic tracking of our own that tracks when the FB Messaging Checkbox is checked, and then when we receive a webhook for the checkbox.
I hope that is somewhat helpful.
messaging_optin
webhook worked only once, among like a hundred trials.
In our case, it was our fault.
My colleague says it was something like a combined problem caused by ngrok and await import
in React.
Thank you very much for sharing your experience @cfurrow ! I think we managed to find the cause earlier by your knowledge.
We don't suffer from this issue #227 now, but I think we might in the future, like after we start testing with more variation of FB account.
In that case, we will report about our case here, hoping that helps this issue fixed.
Hello Everyone,
I'm encountering this issue. Any updates so far for any fix or workaround? I've been spending lots of hours trying to solve this one out and also doing research for possible fix to no avail.
Thanks
@jesephan It looks like the issues above were resolved and ended up being user/developer error. Can you re-check your settings? Add more logging, perhaps? Maybe that will let you see where the possible error is happening?
I do not think that the facebook-messenger gem is at fault at this time.
Hello everyone;
Did you get any info about this problem? I am encountering same issue too. Sometimes I can get opt-in events but if it is not coming that's it. I can't get any opt-in callbacks any more. Other events or webhooks works perfectly expect this.
@MeteALANLI you might wanna bump the bug ticket the i created related to this one. this issue is still doesn't have any resolution yet until now.
I'm having the same issue here. The send to messenger plugin works fine with the messanging_optins
webhook but the checkbox plugin doesn't even trigger the webhook.
@eebasadre20 Hello. You've followed all the requirements of the Checkbox Plugin ?
- Active Optin (e.g. triggering the
MessengerCheckboxUserConfirmation
after a user checks the checkbox, and then clicks a button, like submitting a form. - Verified the
MessengerCheckboxUserConfirmation
is being sent when the checkbox is checked or form is submitted by looking at your browser's network monitor - Domain is whitelisted (the checkbox won't render without it, so I imagine you've done this step)
@eebasadre20 Hello. You've followed all the requirements of the Checkbox Plugin ?
- Active Optin (e.g. triggering the
MessengerCheckboxUserConfirmation
after a user checks the checkbox, and then clicks a button, like submitting a form.- Verified the
MessengerCheckboxUserConfirmation
is being sent when the checkbox is checked or form is submitted by looking at your browser's network monitor- Domain is whitelisted (the checkbox won't render without it, so I imagine you've done this step)
@cfurrow yup, I have followed that requirements and still it didn't trigger the MessengerCheckboxUserConfirmation
.
To be clear, you, as the developer, need to fire the MessengerCheckboxUserConfirmation
event yourself. It is triggered by doing something like this:
var fbData = {
appID: 123456,
pageID: 999999,
ref: "anything-you-want-that-is-unique-per-user",
userRef: "someting-unique-per-user-per-page-refresh"
};
var eventData = {
'app_id': fbData.appId,
'page_id': fbData.pageId,
'ref': fbData.ref,
'user_ref': fbData.userRef
};
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, eventData);
See the "4. Confirm opt-in" section
To be clear, you, as the developer, need to fire the
MessengerCheckboxUserConfirmation
event yourself. It is triggered by doing something like this:var fbData = { appID: 123456, pageID: 999999, ref: "anything-you-want-that-is-unique-per-user", userRef: "someting-unique-per-user-per-page-refresh" }; var eventData = { 'app_id': fbData.appId, 'page_id': fbData.pageId, 'ref': fbData.ref, 'user_ref': fbData.userRef }; FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, eventData);See the "4. Confirm opt-in" section
This how I fired the event MessengerCheckboxUserConfirmation
.
Once the user ticks the checkbox plugin, it will trigger the function FB.Event.subscribe messenger_checkbox
then in that function I'll check the state and if the state is checked
, I'll call the confirmOptIn
that trigger the FB.AppEvents.logEvent.
FB.Event.subscribe('messenger_checkbox', function(e) {
console.log("messenger_checkbox event");
console.log(e);
if (e.event == 'rendered') {
console.log("Plugin was rendered");
} else if (e.event == 'checkbox') {
var checkboxState = e.state;
console.log("Checkbox state: " + checkboxState);
if(checkboxState == 'checked') {
confirmOptIn();
} else {
console.log("Unchecked");
}
} else if (e.event == 'not_you') {
console.log("User clicked 'not you'");
} else if (e.event == 'hidden') {
console.log("Plugin was hidden");
}
});
function confirmOptIn() {
console.log("Hello, confirm opt-in");
var ruuid = 'crn_' + (new Array(16).join().replace(/(.|$)/g, function() {
return ((Math.random() * 36) | 0).toString(36)[Math.random() < .5 ? "toString" : "toUpperCase"]();
}));
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
app_id: "<APP_ID>",
page_id: "<PAGE_ID>",
ref: "",
user_ref: ruuid
});
}
@cfurrow by the way, is the ref
in FB.AppEvents.logEvent an optional?
Hello again.
RE ref
: The docs say this:
You may pass an optional
ref
parameter if you wish to include additional context to be passed back in the webhook event. It has the same behavior as for the Send To Messenger plugin (as distinct fromuser_ref
).
And additionally, as the docs say, you should not be firing the confirmOptIn
callback when the user checks the checkbox. Please read the docs again. You have to have the user check the checkbox then take some other action, like clicking a button, and on that button click, then you call confirmOptIn()
. Make sense? Follow the FB docs and it says exactly that.
When the form is submitted or when the flow is otherwise done, you must send a
MessengerCheckboxUserConfirmation
event.
Their example:
<html>
<head>
<script>
function confirmOptIn() {
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
'app_id':'<APP_ID>',
'page_id':'<PAGE_ID>',
'ref':'<PASS_THROUGH_PARAM>',
'user_ref':'<UNIQUE_REF_PARAM>'
});
}
</script>
</head>
<body>
<input type="button" onclick="confirmOptIn()" value="Confirm Opt-in"/>
</body>
</html>
<input type="button" onclick="confirmOptIn()" value="Confirm Opt-in"/>
Hi @cfurrow,
The first time I tested it, I did that way but it didn't work then I tried the one I mentioned above. Still, it didn't work.
Can you elaborate?
Can you elaborate?
This is how I first tested in which based on the documentation.
- I have this
FB.Event.subscribe('messenger_checkbox', function(e) { })
function to check if the checkbox triggered. I didn't add theconfirmOptIn()
on thecheckboxState == 'checked'
. - Once I tick the checkbox plugin, I'll press the button in where the
onclick=confirmOptIn()
attached. - I'm expecting that the webhook will be trigger. ( but it did not ).
Let me know if this flow of how I tested it is correct or not.
FB.Event.subscribe('messenger_checkbox', function(e) {
console.log("messenger_checkbox event");
console.log(e);
if (e.event == 'rendered') {
console.log("Plugin was rendered");
} else if (e.event == 'checkbox') {
var checkboxState = e.state;
console.log("Checkbox state: " + checkboxState);
if(checkboxState == 'checked') {
} else {
console.log("Unchecked");
}
} else if (e.event == 'not_you') {
console.log("User clicked 'not you'");
} else if (e.event == 'hidden') {
console.log("Plugin was hidden");
}
});
function confirmOptIn() {
console.log("Hello, confirm opt-in");
var ruuid = 'crn_' + (new Array(16).join().replace(/(.|$)/g, function() {
return ((Math.random() * 36) | 0).toString(36)[Math.random() < .5 ? "toString" : "toUpperCase"]();
}));
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
app_id: "<APP_ID>",
page_id: "<PAGE_ID>",
ref: "",
user_ref: ruuid
});
}
<input type="button" onclick="confirmOptIn()" value="Confirm Opt-in"/>
That should work. I don't see any issues with it as-is. Can you confirm that with that setup, when you clicked the button, your code was sending the event to Facebook? Watch the network tab in your browser's development tools, and watch for that event name (MessengerCheckboxUserConfirmation
) in the body (or URL) of the requests going to Facebook or Facebook's graph api.
That would ensure that your JS is working correctly. Perhaps it is not.
That should work. I don't see any issues with it as-is. Can you confirm that with that setup, when you clicked the button, your code was sending the event to Facebook? Watch the network tab in your browser's development tools, and watch for that event name (
MessengerCheckboxUserConfirmation
) in the body (or URL) of the requests going to Facebook or Facebook's graph api.That would ensure that your JS is working correctly. Perhaps it is not.
I attached a screenshot of my network tab. I didn't see a request that has an event name MessengerCheckboxUserConfirmation
though I got the update
and bz
request.
The update
call is, as you can guess, simply the checked/unchecked behavior. So, once you've checked the checkbox, then submitted your form (clicking a button or whatever), you should see another call like this:
https://www.facebook.com/tr/?id=<someid>&ev=MessengerCheckboxUserConfirmation&dl=<url of page>&rl=<url of referer>&if=false&ts=1561554985457&cd[app_id]=<your fb app id>&cd[page_id]=<your fb page id>&cd[ref]=<your ref you passed in>&cd[user_ref]=<user ref you passed in>&sw=3440&sh=1440
The
update
call is, as you can guess, simply the checked/unchecked behavior. So, once you've checked the checkbox, then submitted your form (clicking a button or whatever), you should see another call like this:
https://www.facebook.com/tr/?id=<someid>&ev=MessengerCheckboxUserConfirmation&dl=<url of page>&rl=<url of referer>&if=false&ts=1561554985457&cd[app_id]=<your fb app id>&cd[page_id]=<your fb page id>&cd[ref]=<your ref you passed in>&cd[user_ref]=<user ref you passed in>&sw=3440&sh=1440
Thanks for this.
hmmm .. I'm not sure why I couldn't make it work. I have the same setup based on the documentation still the FB.AppEvents.logEvent ('MessengerCheckboxUserConfirmation', null, { . . . } )
didn't trigger after pressing the button that has this function confirmOptIn()
. Do you have any idea what might be the cause of this kind of issue? or maybe am I missing pre-requisite setup?
Sincerely thanks for staying helping me on this.
Are there any console error messages after you click the button? Are you sure that your callback (confirmOptIn()
) is being called? Have you added any console.log
messages inside that confirmOptin
function to be sure it is being called?
Are there any console error messages after you click the button? Are you sure that your callback (
confirmOptIn()
) is being called? Have you added anyconsole.log
messages inside thatconfirmOptin
function to be sure it is being called?
Yes, I added a console.log
to know that confirmOptIn()
is being called. And it's being called once I trigger the button.
Hm, interesting. So if there are no errors in your console, and the confirmOptin()
function is being called once the user checks the checkbox, then clicks the button, that should be all you need. I can't think of another issue that may be happening. The event code should fire, and you should see it make the network call or throw an error that it could not make that call due to ad/tracker blocking or something.
Hm, interesting. So if there are no errors in your console, and the
confirmOptin()
function is
being called once the user checks the checkbox, then clicks the button, that should be all you need. I can't think of another issue that may be happening. The event code should fire, and you should see it make the network call or throw an error that it could not make that call due to ad/tracker blocking or something.
For reference here's some of my screenshot of my code and when I clicked the confirmOptIn
button.
Does this issue already solve by the guy who opens this? I saw that he wrote a bug report on Facebook.
The initial issue was for the webhook that happens after MessengerCheckboxUserConfirmation
. So that is different from what you are now seeing.
Your app needs to send that MessengerCheckboxUserConfirmation
to Facebook, or else you'll never get any other webhook related to that user.
- You create a unique
user_ref
(unique per user, per page load) - You render the
facebook-messenger-checkbox
element on the page, with the user_ref, and other attributes filled in - User is logged into FB and checks the
facebook-messenger-checkbox
- The user clicks a button, and you fire the
MessengerCheckboxUserConfirmation
. - Facebook (after a short while, usually seconds) sends your registered server a
messaging_optins
webhook, passing you the user_ref, ref, etc, as part of the webhook payload.
The initial issue was for the webhook that happens after
MessengerCheckboxUserConfirmation
. So that is different from what you are now seeing.Your app needs to send that
MessengerCheckboxUserConfirmation
to Facebook, or else you'll never get any other webhook related to that user.
- You create a unique
user_ref
(unique per user, per page load)- You render the
facebook-messenger-checkbox
element on the page, with the user_ref, and other attributes filled in- User is logged into FB and checks the
facebook-messenger-checkbox
- The user clicks a button, and you fire the
MessengerCheckboxUserConfirmation
.- Facebook (after a short while, usually seconds) sends your registered server a
messaging_optins
webhook, passing you the user_ref, ref, etc, as part of the webhook payload.
Ya, you're correct.
hmmm .. It seems the process that I did is correct based on what you've said too, but still, it didn't work. I'm totally stuck on this.
Anyhow, I appreciate so much your help. Thanks again.
The initial issue was for the webhook that happens after
MessengerCheckboxUserConfirmation
. So that is different from what you are now seeing.Your app needs to send that
MessengerCheckboxUserConfirmation
to Facebook, or else you'll never get any other webhook related to that user.
- You create a unique
user_ref
(unique per user, per page load)- You render the
facebook-messenger-checkbox
element on the page, with the user_ref, and other attributes filled in- User is logged into FB and checks the
facebook-messenger-checkbox
- The user clicks a button, and you fire the
MessengerCheckboxUserConfirmation
.- Facebook (after a short while, usually seconds) sends your registered server a
messaging_optins
webhook, passing you the user_ref, ref, etc, as part of the webhook payload.
Thanks you guys sharing, however, exactly same situation as @eebasadre20 here, no errors on console and found MessengerCheckboxUserConfirmation
requests on dev tool, what's more, facebook analytic tools records the event called. meanwhile, messaging_optins webhook doesn't recieve any msg.
tried a lot of times and checked all answers on stack overflow about messager checbox plugin. sad.
by the way, FB sdk v3.3 the lastest version.
What do your server logs say? Have you seen the request from FB coming into your server? Do any FB webhooks make it to your server? Are they being handled correctly?
If the events are being triggered in the browser (like your screenshot shows) and FB seems to see those MessengerCheckboxUserConfirmation
events in their event debugger, then it may be something on your server. That will be up to you to determine if the HTTP requests are making it to your server, and what happens when they do.
What do your server logs say? Have you seen the request from FB coming into your server? Do any FB webhooks make it to your server? Are they being handled correctly?
If the events are being triggered in the browser (like your screenshot shows) and FB seems to see those
MessengerCheckboxUserConfirmation
events in their event debugger, then it may be something on your server. That will be up to you to determine if the HTTP requests are making it to your server, and what happens when they do.
@cfurrow We have been experiencing this problem for quite some time. Most of MessengerCheckboxUserConfirmation
events result in a successful webhook trigger on our end but unfortunately, some are not at all received. I do not know the exact fail percentage for it is definitely a problem. If we haven't gotten any triggers I would have suspected that the problem is on our end but we do receive many webhook triggers from Facebook telling us that the user is opted-in but some do not even make it to our webhook at all.
Do you have any updates regarding this issue ?
Btw, I filed a new bug report here; https://developers.facebook.com/support/bugs/3483746841700058/
I'm still waiting for them to respond.
Hello @sarpdoruk,
Are you sure that your users have checked the checkbox before clicking the "submit" button on your page? Can you log and get a sense of how many users are
- logged into fb
- are being assigned a unique user_ref every time they refresh the page
- are checking the Facebook Messenger checkbox
- click the "submit" button, which opts them in to receiving FB messages
If you can confirm that all the above are being done, but you are not seeing the webhooks for a certain percentage of user_refs
that you are expecting, then there may be something going on with Facebook.
This gem does not do any type of filtering/blocking of requests coming into it. It handles all facebook events as they come in to the server.
Of course, in rare instances, if your server is overloaded (high cpu, etc), and is not properly handling the requests coming in (dropping requests from facebook, etc), then, obviously, you'd never be able to reply to that webhook data, because it never made it to your app code. But, again, that's probably a very rare instance since most server software handles request queuing pretty well.
When I was debugging this kind of issue for my app, I did something like this:
Created a new table in our db called facebook_messenger_requests
. It had these columns:
id (int, primary key), user_ref (string), checked_checkbox (boolean), submitted_at (datetime), webhook_received_at (datetime)
Then, every time someone requested the page with the FB messenger checkbox on it, I would create a record with the available data: user_ref
.
When they submitted the form on the page, I submitted an AJAX request to our server to update the checked_checkbox
and submitted_at
with the data I had from the front end:
- if they didn't check the checkbox, I'd write
false
into thechecked_checkbox
column - I'd write the current date/time into the
submitted_at
column
When we received the webhook back from Facebook, we'd lookup the user_ref
in the database, and update the webhook_received_at
time.
After a few days of this feature being live for a percentage of our users, I was able to see the issue.
Our tracking code that was keeping track of users "opting in" and the webhooks received from Facebook were not equal, because we were tracking an event internally that was not taking into account that some users may click "submit" without checking the checkbox. After that, when I updated our internal tracking code to ignore those users, the counts were correct. For every user that opted in, we received a webhook back from Facebook.
There was no bug, simply user error on our part.
Hey @cfurrow,
Thank you so much for the detailed explanation. I'll definitely give your ideas a try, put some logs and check these metrics in order to understand the problem. It's probably on our end but we need to make sure because I see so many bug requests on facebook side regarding this very problem.
The initial issue was for the webhook that happens after
MessengerCheckboxUserConfirmation
. So that is different from what you are now seeing.Your app needs to send that
MessengerCheckboxUserConfirmation
to Facebook, or else you'll never get any other webhook related to that user.1. You create a unique `user_ref` (unique per user, per page load) 2. You render the `facebook-messenger-checkbox` element on the page, with the user_ref, and other attributes filled in 3. User is logged into FB and checks the `facebook-messenger-checkbox` 4. The user clicks a button, and you fire the `MessengerCheckboxUserConfirmation`. 5. Facebook (after a short while, usually seconds) sends your registered server a `messaging_optins` webhook, passing you the user_ref, ref, etc, as part of the webhook payload.
I believe this is the solution for this problem.