Search code examples
facebook-graph-apifacebook-messengerfacebook-messenger-bot

Trigger User Action from Facebook Messenger Bot


I have a working Facebook messenger bot.

From the Messenger app, I would like my bot to trigger the "camera" action (to snap a new picture or video) for the user.

To clarify with a hypothetical context, I would create persistent menu action which mimics the behavior of clicking the "camera" button under the message text area.

I looked into the "Page Call To Action" operation of the Graph Api but could not find parameters that would produce the desired behavior.


Solution

  • Here is the solution to your problem.

    In Facebook Messenger, you can open a webview and load a webpage. But remeber that good old HTML 5 provides us with a simple way of asking the user to use their camera when they are on mobile.

    These steps below work today

    1. You can use a url button to open a webview as such

      "buttons":[ { "type":"web_url", "url":"https://url_to_your_webpage", "title":"View Item", "webview_height_ratio": "compact" } ]

    2. In your webpage, include this HTML5 element that allows user to take image via camera on mobile

      <input type="file" accept="image/*" capture="camera" />

    3. Submit the image to your servers, close the webview, and do any processing required. For example you can now send the image back to the user from your bot.