facebook messenger切换协议take_thread_control

问题描述 投票:1回答:1

我用messenger和dialogflow创建了一个机器人,这很好用 但是当我尝试实现切换协议时问题就出现了

第一种方法:将线程控制传递给PAGE INBOX 我使用'input.handover'动作建立了对话流的意图,然后当我键入切换时,我调用我的webhook并使用pass_thread_control调用fb api并将控件传递到页面收件箱,我获得成功响应和对话从BOT传递到PAGE INBOX。但是这里一直停留在PAGE INBOX并且我不能将take_thread_control带到BOT,因为PAGE INBOX没有与对话流或任何其他webhook链接。

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

而现在我只是被困在这里。如果有人知道如何使用对话流或任何帮助实现切换协议,我很欣赏。

谢谢。

facebook facebook-messenger dialogflow
1个回答
1
投票

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

第1步:第二个应用程序将您的webhook订阅到bot页面 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);
})

现在所有用户消息都从第二个app webhook传递,当他输入'back'时,例如webhook将控制权带回主应用程序(在这种情况下为bot)

© www.soinside.com 2019 - 2024. All rights reserved.