Skip to content

An experimental package for Messenger Handover Protocol with Bottender.

License

Notifications You must be signed in to change notification settings

bottenderjs/bottender-handovers

Repository files navigation

bottender-handovers

npm Build Status License: MIT

An experimental package for Messenger Handover Protocol with Bottender.

Installation

npm install bottender-handovers

Usage

const { middleware } = require('bottender');
const handovers = require('bottender-handovers');

const handleHandovers = handovers({
  shouldControlPass: context => context.event.text === '/help',
  shouldControlTake: context =>
    context.event.isStandby && context.event.text === '/back',
  willControlPass: async context => {
    await context.sendText('Passing thread control to the page inbox.');
  },
  didControlTake: async context => {
    await context.sendText('Took thread control back.');
  },
});

// This bot should be assigned as primary receiver app
bot.onEvent(
  middleware([
    handleHandovers,
    async context => {
      if (!context.event.isStandby) {
        await context.sendText('Respond by bot.');
      }
    },
  ])
);

Using Request Thread Control

bottender-handovers provide two built-in functions to utilize Messenger Platform's Request Thread Control events. Simply pass them to shouldControlPass option.

const { middleware } = require('bottender');
const handovers = require('bottender-handovers');
const {
  isRequestThreadControlFrom,
  isRequestThreadControlFromPageInbox,
} = handovers;

// request from and pass to 3rd party CRM service
const myCRMAppId = 123456;
const handleHandovers = handovers({
  shouldControlPass: isRequestThreadControlFrom(myCRMAppId),
  targetAppId: myCRMAppId,
});

// request from and pass to Facebook Page Inbox
const handleHandovers = handovers({
  shouldControlPass: isRequestThreadControlFromPageInbox,
});

Options

shouldControlPass(context): boolean

Default: () => false.

shouldControlTake(context): boolean

Default: () => false.

willControlPass(context)

Default: () => {}.

willControlTake(context)

Default: () => {}.

didControlPass(context)

Default: () => {}.

didControlTake(context)

Default: () => {}.

targetAppId

Default: 263902037430900 (Page Inbox).

License

MIT © Yoctol

About

An experimental package for Messenger Handover Protocol with Bottender.

Resources

License

Stars

Watchers

Forks

Packages

No packages published