- [new] Implement basic usage:
const bottenderXState = require('bottender-xstate');
const config = {
key: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow',
},
onEntry: 'enterGreen',
onExit: 'leaveGreen',
},
yellow: {
on: {
TIMER: 'red',
},
onEntry: 'enterYellow',
onExit: 'leaveYellow',
},
red: {
on: {
TIMER: 'green',
},
onEntry: 'enterRed',
onExit: 'leaveRed',
},
},
};
const mapContextToXStateEvent = () => 'TIMER';
const actionMap = {
enterGreen: context => context.sendText('enter green'),
enterYellow: context => context.sendText('enter yellow'),
enterRed: context => context.sendText('enter red'),
leaveGreen: context => context.sendText('leave green'),
leaveYellow: context => context.sendText('leave yellow'),
leaveRed: context => context.sendText('leave red'),
};
bot.onEvent(
bottenderXState({
config,
mapContextToXStateEvent,
actionMap,
})
);