Closed pavei closed 5 years ago
You can use the Move to Main
and Mark as done
buttons of Messenger platform to control your bot manually, instead of listening to echo event.
To do this, you need to assign app roles first: https://developers.facebook.com/docs/messenger-platform/handover-protocol/assign-app-roles
Let your bot app be Primary Receiver
, and let the inbox be Secondary Receiver
.
After the roles be assigned, your users will be in Done
when they interact with your bot.
When you press the Move to Main
button, the inbox will send a request_thread_control
event to your bot, and move user from Done
to Main
, then you can do
if (context.event.isRequestThreadControlFromPageInbox) {
await context.passThreadControlToPageInbox();
await context.sendText("The chatbot has been stopped")
}
When you press the Mark as done
button, the inbox will send a pass_thread_control
event to your bot, and move user from Main
to Done
, then you can do
if (context.event.isPassThreadControl) {
await context.sendText("🤖 Chatbot is ready!")
}
You don't need to call context.takeThreadControl()
in this scenario, because the inbox has already passed thread control back to your bot.
Hi @pavei, It seems that @Calvin-Lin has already provided a great answer, so I'm going to close this.
Hi,
In facebook messenger i give the power of "stoping" the bot to the Inbox. So, to do this i treat all echo messages to find this comands like "stop", "continue". It was working, on old version of bottender. But now on new version there is a code block that not let me advise the user that the bot was stopped or continued.
So, is there a way to send a message to user, that chatbot is stopped when Inbox send a command?
Code block on https://github.com/Yoctol/bottender/blob/36981aa7b4fb2690f136b5dbaa50c3cab0ff5c03/src/context/MessengerContext.js#L98
My Code