Facebook messenger - close web notification and notify about it

I send the user from the chat for messaging to the payment page in my application. Messenger opens the page in a web view. Now I would like to close the webview and send the user back to Messenger, as well as send something to the webhook to notify him that the user has completed the payment page.

What is the best way to do this?

+1
source share
1 answer

You can achieve this only if the payment page is controlled (developed by you), if it is a third-party payment gateway, you can do nothing. if the payment page is controlled by you, you can pass the sender ID as a parameter via web_url or get the sender ID through

<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")); window.extAsyncInit = function () { // the Messenger Extensions JS SDK is done loading MessengerExtensions.getUserID(function success(uids) { var psid = uids.psid;//This is your page scoped sender_id alert(psid); }, function error(err) { alert("Messenger Extension Error: " + err); }); }; </script> 

using the sender ID, you can send the message text back to the bot. to close the webview after all this includes this script after sending the text to the bot

  <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")); window.extAsyncInit = function () { // the Messenger Extensions JS SDK is done loading //close the webview MessengerExtensions.requestCloseBrowser(function success() { }, function error(err) { }); }; </script> 

As in your bot, you must make sure that the page access token is available before sending the text, and also make sure that you use the white list of the domain used in your web browser, and you set "messenger_extensions": true, in your button web_url or you won’t be able to get the sender ID using the messenger extension

link

Url

messaging extension

0
source

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


All Articles