Facebook Messenger-关闭WebView并通知Webhook [英] facebook messenger - close webview and notify webhook

查看:97
本文介绍了Facebook Messenger-关闭WebView并通知Webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Messenger聊天中将用户发送到我的应用程序中的付款页面. Messenger会在Web视图中打开页面. 现在,我想关闭Web视图,然后将用户发送回Messenger,同时还向Webhook发送一些消息,以通知它用户已完成付款页面.

I'm sending the user from the messenger chat to a payment page in my application. Messenger opens the page in a webview. Now I'd like to close the webview and send the user back to Messenger while also sending something to the webhook in order to notify it that the user has finished the payment page.

完成此任务的最佳方法是什么?

What is the best way to accomplish this?

推荐答案

只有在付款页面受您控制(由您开发)的情况下,您才能实现此目的;如果它是第三方付款网关,则您无能为力.如果付款页面由您控制,则可以通过web_url传递发件人ID作为参数,也可以通过

You can only achieve this if the payment page is controlled(developed by you), if it is a third party payment gateway there is nothing you can do. 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 via

<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>  

使用发件人ID,然后可以将消息文本发送回机器人. 在发送完所有包含此脚本的脚本后关闭webview 发短信给机器人

using the sender ID you can then send a message text back to the bot. to close the webview after all of this include 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>

就像在Bot中一样,您必须确保在发送文本之前可以使用页面访问令牌,还必须确保将Web视图中使用的域列入白名单,并在web_url按钮中设置"messenger_extensions":true否则您将无法使用Messenger扩展程序获取发件人ID

Just like from within your Bot you have to ensure that the page access token is available before you send the text, also ensure that you whitelist the domain used in you webview and you set "messenger_extensions": true, in your web_url button or you won't be able to get the Sender ID using messenger Extension

引用

网址按钮

信使扩展名

这篇关于Facebook Messenger-关闭WebView并通知Webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆