【问题标题】:facebook messenger handover protocol take_thread_controlfacebook messenger 切换协议 take_thread_control
【发布时间】:2018-04-28 17:40:45
【问题描述】:

我创建了一个带有信使和对话流的机器人,效果很好
但是当我尝试实现切换协议时问题就来了

第一种方法:将线程控制传递给 PAGE INBOX
我使用“input.handover”操作设置了对话流的意图,然后当我键入切换时,我调用我的 webhook 并使用 pass_thread_control 调用 fb api 并将控件传递给页面收件箱,我得到一个成功响应和对话从 BOT 传递到 PAGE INBOX。但是这里卡在 PAGE INBOX 上,我无法将_thread_control 转移到 BOT,因为 PAGE INBOX 没有与对话框流或任何其他 webhook 链接。

第二种方法:将线程控制传递给另一个应用程序
使用与第一种方法相同的设置,但这次我将线程控制传递给我创建并与 webhook 链接的 facebook APP(nodejs 托管在 heroku 上),我得到了成功响应,但这次没有消息到达此 APP 收件箱,在 heroku 控制台上,我可以看到消息到达 webhook 但不是 APP 收件箱。

现在我只是卡在这里。如果有人知道如何通过对话流或任何帮助来实现切换协议,我将不胜感激。

谢谢。

【问题讨论】:

  • 同样,我也坚持你的第一种方法,但我的解决方案无法作为答案发布,因为它的代码很长,告诉我应该如何联系你
  • 感谢@NikhilSavaliya,我的电子邮件 fahmichaar@gmail.com

标签: facebook facebook-messenger dialogflow-es


【解决方案1】:

好的,我只是通过混合两种方法找到解决方法

第 1 步:使用第二个应用程序将您的 webhook 订阅到机器人页面
page_subscribe

第 2 步:第二个应用程序 webhook 仅用于当用户键入特殊关键字(如(退出或返回...)时,将线程控制带回主应用程序)

app.post('/webhook', (request, response) => {
    const webhook_events = request.body.entry[0];
    // console.log('webhook_events : ', webhook_events);

    // Secondary Receiver is in control - listen on standby channel
    if (webhook_events.standby) {

        // iterate webhook events from standby channel
        webhook_events.standby.forEach(event => {

            const psid = event.sender.id;
            const message = event.message;

            // check if the user want back to the bot
            if (message && (message.text == 'exit' || message.text == 'back')) {

                // HandoverProtocol.takeThreadControl is just call the facebook api to takeThreadControl
                HandoverProtocol.takeThreadControl(psid).then(reps => {

                    // replay.sendMessage also call facebook api to send a message to the user to let him know he is back chat with the bot 
                    replay.sendMessage(psid, 'Hi, your are back to the BOT');

                }).catch(err => console.log(err));
            }

        });   
    }

    // respond to all webhook events with 200 OK
    response.sendStatus(200);
})

现在所有用户消息都从第二个应用程序 webhook 传递,当他键入“返回”时,例如 webhook 将控制权返回给主应用程序(在本例中为机器人)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2015-04-19
    • 1970-01-01
    相关资源
    最近更新 更多