Search code examples
facebook-messengerfacebook-webhooks

Testing Facebook Messenger Opt-in callback


I am trying to test my webhook that subscribes to the messaging_optins event, but I am struggling to manually trigger the event.

The documentation seems to indicate that using the "Send to Messenger" plugin should fire this event, but after setting up the button no event is triggered. The user is redirected to messenger website and asked to login, and then directed to an empty conversation with my page. I have tried this as my admin user, a random real Facebook account and a test account for my app.

When should this event be fired? And how can i trigger the event manually?

Edit

I would like to note that my webhooks are working and I am able to receive events for messages being received. Just not the opt-ins event.


Solution

  • You can use the curl request below, if you are checking sha1 signature then replace the SHA1OFTHEBODY with sha1 signature of the payload and replace the https://chabotproxy.com/messenger/webhooks with your webhook endpoint url:

    curl -X POST -H "x-hub-signature: sha1=SHA1OFTHEBODY" -H "content-type: application/json" -d '{
      "object":"page",
      "entry":[
        {
          "id":"PAGE_ID",
          "time":1458692752478,
          "messaging":[
            {
              "sender":{
                "id":"USER_ID"
              },
              "recipient":{
                "id":"PAGE_ID"
              },
              "timestamp":1234567890,
              "optin":{
                "ref":"chatbotproxy.com"
              }
            }    
          ]
        }
      ]
    }' https://chabotproxy.com/messenger/webhooks