将DialogFlow会话ID作为按钮上的url参数传递

时间:2019-05-27 15:47:06

标签: webview dialogflow facebook-messenger

我正在尝试使用Dialogflow chatbot实现Facebook Webview

我找不到将数据从Web视图传递回对话的方法。

我现在正在探讨的是,是否有可能将单击按钮的位置的对话线程的会话ID作为按钮URL上的查询参数传递。

这样,我可以使用detect-intent对数据进行处理,然后将响应发布回线程

2 个答案:

答案 0 :(得分:0)

`MessengerExtensions.getSupportedFeatures(函数成功(结果){                 让功能= result.supported_features;                 console.log(features);

            if (features.includes("context")) {
                MessengerExtensions.getContext('APPID',
                    function success(thread_context) {
                        console.log(thread_context.psid);
                        // success
                        document.getElementById("psid").value = thread_context.psid;
                    },
                    function error(err) {
                        // error
                        console.log(err);
                    }
                );
            }
        }, function error(err) {
            // error retrieving supported features
            console.log(err);
        });`

<input type="hidden" name="psid" id="psid">

您将获得发件人ID,并在此基础上找到会话ID(如果您将发件人与会话ID映射在一起)。

答案 1 :(得分:0)

您可以使用Messenger Extensions SDK中的getContext()函数。 getContext()为您提供thread_context对象,其中包含tid(打开Webview的线程的ID。)。

请参阅以下参考资料:MessengerExtensions.getContext()