Search code examples
serverpostbackfacebook-messenger

Send Button Template in Facebook Messenger Platform: web_url Button Clicked Event


I am developing on the Facebook Messenger Platform, the documentation shows that when I am sending a button template, I can specify the button type to be web_url, which, when clicked by the user, takes user to a webpage in the built-in browser of the messenger.

My question is: is there any way for my application server (postback server) to know if a user clicks a web_url button? E.g. as a postback server call? Thank you!


Solution

  • I think your best option is to proxy that URL through your application server and then redirect to the real URL so that you can detect if the user navigated to that link.

    You'll also want to detect the UserAgent for the "facebook bot" as Facebook will try to scrape your URL first (even if the user doesn't click it).

    So say you want to point your user to:

    You'll want to setup an endpoint on your application server:

    • https://{your-application-server}/url_click?url=https%3A%2F%2Ffoo.com&id=XYZ
      • url is the urlencoded url they'll end up
      • id is some id that you can identify that facebook messenger user session with

    You can then use that information to lookup the Messenger session with that id and perform a click handling callback.