Messenger Routing
Bottender offers a bunch of helpers to route within your Messenger or multi-platform app. 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.reaction.react(HandleReactionReact),
messenger.reaction.unreact(HandleReactionUnreact),
messenger.reaction(HandleReaction),
messenger.read(HandleRead),
messenger.referral(HandleReferral),
messenger.standby(HandleStandby),
messenger.any(HandleMessenger),
]);
}
/* Note: You need to implement those functions */
async function HandleMessage(context) {}
async function HandleAccountLinkingLinked(context) {}
async function HandleAccountLinkingUnlinked(context) {}
async function HandleAccountLinking(context) {}
async function HandleDelivery(context) {}
async function HandleEcho(context) {}
async function HandleGamePlay(context) {}
async function HandlePassThreadControl(context) {}
async function HandleTakeThreadControl(context) {}
async function HandleRequestThreadControl(context) {}
async function HandleAppRoles(context) {}
async function HandleOptin(context) {}
async function HandlePolicyEnforcement(context) {}
async function HandlePostback(context) {}
async function HandleReactionReact(context) {}
async function HandleReactionUnreact(context) {}
async function HandleReaction(context) {}
async function HandleRead(context) {}
async function HandleReferral(context) {}
async function HandleStandby(context) {}
async function HandleMessenger(context) {}
All available routes in messenger
that recognize different kind of events:
messenger.any
- triggers the action when receiving any Messenger events.messenger.message
- triggers the action when receiving Messengermessage
events.messenger.accountLinking.linked
- triggers the action when receiving Messengeraccount_linking
events with statuslinked
.messenger.accountLinking.unlinked
- triggers the action when receiving Messengeraccount_linking
events with statusunlinked
.messenger.accountLinking
- triggers the action when receiving Messengeraccount_linking
events.messenger.delivery
- triggers the action when receiving Messengerdelivery
events.messenger.echo
- triggers the action when receiving Messengerecho
events.messenger.gamePlay
- triggers the action when receiving Messengergame_play
events.messenger.passThreadControl
- triggers the action when receiving Messengerpass_thread_control
events.messenger.takeThreadControl
- triggers the action when receiving Messengertake_thread_control
events.messenger.requestThreadControl
- triggers the action when receiving Messengerrequest_thread_control
events.messenger.appRoles
- triggers the action when receiving Messengerapp_roles
events.messenger.optin
- triggers the action when receiving Messengeroptin
events.messenger.policyEnforcement
- triggers the action when receiving Messengerpolicy_enforcement
events.messenger.postback
- triggers the action when receiving Messengerpostback
events.messenger.preCheckout
- triggers the action when receiving Messengerpre_checkout
events.messenger.reaction.react
- triggers the action when receiving Messengerreaction
events with actionreact
.messenger.reaction.unreact
- triggers the action when receiving Messengerreaction
events with actionunreact
.messenger.reaction
- triggers the action when receiving Messengerreaction
events.messenger.read
- triggers the action when receiving Messengerread
events.messenger.referral
- triggers the action when receiving Messengerreferral
events.messenger.standby
- triggers the action when receiving Messengerstandby
events.
Note: You must subscribe corresponding events for your page to receive the events.