Facebook Messenger detects webview closure (mobile)

I have a bot messenger that provides users with links to a web page. Is there any way to detect when the user closed the webview and therefore returned to the bot conversation?

This question only applies to the Messenger app on mobile phones, the desktop is fine.

window.onbeforeunload not supported, window.pagehide only works on reboot, but does not close the window.unload , as well as window.unload .

+10
source share
3 answers

You can try using this.

 MessengerExtensions.requestCloseBrowser(function success() { // webview closed }, function error(err) { // an error occurred }); 

This is not the same as what you are looking for. But you could manage your users this way if you implement the website as well.

For More Information: Messenger Extension Webview

0
source

It really depends on what you want to achieve in your flow.

If the user closes the webview with close-x (top right), you should think of it as a normal closing event and not process anything at all. Instead, you should use a special save / confirm and / or close button in your webview.

Then, the close button launches the requestCloseBrowser function of the Messenger Extension SDK, and the save / confirm button handles the actual save / confirm / process action.

If you really need to find the user closing the webview with close-x in the upper right corner, this can only be achieved by a long poll (polling a user session from your webview).

0
source

It's quite simple, we have to use the Facebook Messenger SDK extension, last year I implemented this. here you can find the corresponding code,

https://github.com/vickymicky/botkit-messenger-express-demo/commit/4aa91d12167daa322bdaddb158289b74ee9610c7

We need to use window.extAsyncInit to detect the event, and then we can pass the information to the server.

Use MessengerExtensions.getUserID to get the user ID, if necessary.

Contact https://github.com/vickymicky/botkit-messenger-express-demo/blob/master/views/webview.ejs

Note The above example runs in Node.js.

-2
source

Source: https://habr.com/ru/post/1015608/


All Articles