The Messenger Platform allows you to open a standard webview, where you can load webpages inside Messenger. This lets you offer experiences and features that might be difficult to offer with message bubbles, such as picking products to buy, seats to book, or dates to reserve.
You can open the webview with any of the following:
In each of these instances, you can specify how the webview should look and behave.
If your experience uses the Messenger Extensions described in this section, remember to set the messenger_extensions
parameter to true
in the menu item or button you are invoking it from!
To display a webpage with the Messenger Extensions SDK enabled in the Messenger webview you must whitelist the domain, including sub-domain, in the whitelisted_domains
property of your bot's Messenger Profile. This ensures that only trusted domains have access to user information available via SDK functions.
For more information on whitelisting domains, see the whitelisted_domains
reference.
As with any webpage, the <title>
tag sets the text displayed in the title bar for the webview.
<html> <head> <title>My Awesome Webview</title> </head> ... </html>
It is a good idea to close the webview after a transaction is complete, especially if actions the user took will result in a message in the thread. This can be done with the Messenger Extensions SDK or by using a redirect URL.
To close the webview using the Messenger Extensions SDK, call MessengerExtensions.requestCloseBrowser()
. You can also optionally implement success and error callbacks functions.
MessengerExtensions.requestCloseBrowser(function success() { // webview closed }, function error(err) { // an error occurred });
You can also close the webview by redirecting the user to a URL with the following format:
https://www.messenger.com/closeWindow/?image_url=<IMAGE_URL>&display_text=<DISPLAY_TEXT>
The values set for the display_text
and image_url
parameters will be displayed briefly until the window closes. Note that this method will only close if you redirect from your URL/Page. Directly opening the URL will not close the browser.
This only works on Android. On iOS, the text and image will be displayed, but the browser will not close automatically.
To give you the ability to tightly integrate experiences in the webview with the Messenger experience, we also have made the Messenger Extensions JS SDK available, which makes added functionality accessible in the webview, such as information about the thread context.
For more information, see Adding the Messenger Extensions SDK.
Use it for longer interactions (more than three steps) where people might want to edit their input or otherwise proceed in a non-linear fashion.
Use it for content that's especially visual.
Use it for user preferences, or to allow on-demand changes to previous selections.
Use it in combination with more conversational interactions.
Configure the height of your webview to match its content — and preserve the context of the thread beneath.
Take advantage of Messenger's webview extensions to bring the thread's context into the webview.
Don't feel limited to collecting all form information at once. You can capture it piece by piece conversationally, then use a form in the webview for later edits.
Mix conversational and webview interactions, and keep any given interaction brief. Combine thread and webview interactions for a "Messenger-native" experience.