Messenger Routing
Bottender offers a bunch of helpers to route within your Messenger or multi-platform application. For example, you may use Messenger particular routes within your router
:
const { router, messenger } = require('bottender/router');
function App() {
return router([
messenger.message(HandleMessage),
messenger.accountLinking.linked(HandleAccountLinkingLinked),
messenger.accountLinking.unlinked(HandleAccountLinkingUnlinked),
messenger.accountLinking(HandleAccountLinking),
messenger.delivery(HandleDelivery),
messenger.echo(HandleEcho),
messenger.gamePlay(HandleGamePlay),
messenger.passThreadControl(HandlePassThreadControl),
messenger.takeThreadControl(HandleTakeThreadControl),
messenger.requestThreadControl(HandleRequestThreadControl),
messenger.appRoles(HandleAppRoles),
messenger.optin(HandleOptin),
messenger.policyEnforcement(HandlePolicyEnforcement),
messenger.postback(HandlePostback),
messenger.read(HandleRead),
messenger.referral(HandleReferral),
messenger.standby(HandleStandby),
messenger(HandleMessenger),
]);
}
async function HandleMessage(context) {
/* skip... */
}
async function HandleAccountLinkingLinked(context) {
/* skip... */
}
async function HandleAccountLinkingUnlinked(context) {
/* skip... */
}
async function HandleAccountLinking(context) {
/* skip... */
}
async function HandleDelivery(context) {
/* skip... */
}
async function HandleEcho(context) {
/* skip... */
}
async function HandleGamePlay(context) {
/* skip... */
}
async function HandlePassThreadControl(context) {
/* skip... */
}
async function HandleTakeThreadControl(context) {
/* skip... */
}
async function HandleRequestThreadControl(context) {
/* skip... */
}
async function HandleAppRoles(context) {
/* skip... */
}
async function HandleOptin(context) {
/* skip... */
}
async function HandlePolicyEnforcement(context) {
/* skip... */
}
async function HandlePostback(context) {
/* skip... */
}
async function HandleRead(context) {
/* skip... */
}
async function HandleReferral(context) {
/* skip... */
}
async function HandleStandby(context) {
/* skip... */
}
async function HandleMessenger(context) {
/* skip... */
}
All available routes in messenger
that recognize different kind of events:
messenger
- matches when receiving any messenger events.messenger.message
- matches when receiving messengermessage
events.messenger.accountLinking.linked
- matches when receiving messengeraccount_linking
events with statuslinked
.messenger.accountLinking.unlinked
- matches when receiving messengeraccount_linking
events with statusunlinked
.messenger.accountLinking
- matches when receiving any messengeraccount_linking
events.messenger.delivery
- matches when receiving messengerdelivery
events.messenger.echo
- matches when receiving messengerecho
events.messenger.gamePlay
- matches when receiving messengergame_play
events.messenger.passThreadControl
- matches when receiving messengerpass_thread_control
events.messenger.takeThreadControl
- matches when receiving messengertake_thread_control
events.messenger.requestThreadControl
- matches when receiving messengerrequest_thread_control
events.messenger.appRoles
- matches when receiving messengerapp_roles
events.messenger.optin
- matches when receiving messengeroptin
events.messenger.policyEnforcement
- matches when receiving messengerpolicy_enforcement
events.messenger.postback
- matches when receiving messengerpostback
events.messenger.preCheckout
- matches when receiving messengerpre_checkout
events.messenger.read
- matches when receiving messengerread
events.messenger.referral
- matches when receiving messengerreferral
events.messenger.standby
- matches when receiving messengerstandby
events.
Note: You must subscribe corresponding events for your page to receive the events.