IOS Facebook Messenger, automatically close the link after it opens and complete the task

Using the iOS Facebook Messenger app on my iPad, I create a bot that sends the user a link to the media player.

After the user clicks the link, he will open the inline link inside the Facebook Messenger application (at least this is the behavior of the iPad). At the end of multimedia playback, I would like to automatically close the built-in browser window and return the user to the current conversation.

When I try to make window.close() , which does not close the built-in browser window that opens in iPad Facebook Messenger. Is there any other way to close my Facebook browser window?

+5
source share
1 answer

Widely supported

The Facebook Messenger extension method is the most compatible way to do this. On the mobile device, it closes the web view, on the desktop it closes the tab (web-openers open in new tabs on the desktop messenger).

Firstly, to whitelist your domain, to be able to use Messenger extensions, use an access token for your application. Use the page_access_token generated for your bot.

 curl -X POST -H "Content-Type: application/json" -d '{ "whitelisted_domains":[ "https://petersfancyapparel.com" ] }' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN" 

Upload the Messenger SDK to a webview page using video

 <script> (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.com/en_US/messenger.Extensions.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'Messenger')); </script> 

Then add an event listener to the video element to call the browser close function

 <video src="video.ogv" id="myVideo"> video not supported </video> <script type='text/javascript'> document.getElementById('myVideo').addEventListener('ended',myHandler,false); function myHandler(e) { MessengerExtensions.requestCloseBrowser(function success() { }, function error(err) { }); } </script> 

IOS only

The only quick and dirty way is to redirect to https://www.messenger.com/closeWindow/?image_url=IMAGE_URL&display_text=DISPLAY_TEXT , which will show the specified image and text before closing the window. Docs about it

For this you would do

 window.replace('https://www.messenger.com/closeWindow/?image_url=IMAGE_URL&display_text=DISPLAY_TEXT') 
+1
source

All Articles