1
votes

i created a bot with messenger and dialogflow, This works good
but the problem comes when i try to implement the handover protocol

First approach : Pass thread control to PAGE INBOX
i set up an intent on dialogflow with 'input.handover' action then when i type handover i call my webhook and make a call to fb api with pass_thread_control and i passe the control to the page inbox, i get a success response and the conversation pass from the BOT to PAGE INBOX. But here a stuck to PAGE INBOX and i cant take_thread_control to the BOT because the PAGE INBOX not linked with the dialogflow or any other webhook.

Second approach : Pass thread control to another app
with the same setup of first approach but this time i pass the thread control to a facebook APP i created and linked with a webhook (with nodejs hosted on heroku), i get a success response but this time no message come to this APP inbox and on heroku console i can see the message come to webhook but not APP inbox.

And now i just stuck here. if any one have an idea how to implement the handover protocol with dialogflow or any help, i appreciate that.

Thanks.

1
same I also stuck on your 1st approach but i have the solution can't post as an answer because of its long code tell me supposed way to contact you - Nikhil Savaliya
Thanks @NikhilSavaliya, my email [email protected] - Mohamed Fahmi Chaar

1 Answers

1
votes

ok i just find a workaround by mixing the two approaches

step 1 : with the second app subscribe your webhook to the bot page
page_subscribe

step 2 : the second app webhook is just for take the thread control back to primary app when the user type a special keyword like (exit or back...)

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);
})

now all user messages pass from the second app webhook and when he type 'back' for example the webhook take the control back to the primary app (the bot in this case)