Skip to content

Instantly share code, notes, and snippets.

@vunb
Last active October 31, 2019 10:22
Show Gist options
  • Save vunb/0fcb7d2d50e82612de1c4d3ba8df2fe3 to your computer and use it in GitHub Desktop.
Save vunb/0fcb7d2d50e82612de1c4d3ba8df2fe3 to your computer and use it in GitHub Desktop.
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'botscript',
initial: 'digest',
context: {
retries: 0
},
states: {
digest: {
on: {
DIALOG: 'dialogue',
FLOW: 'flow',
DEFECT: 'nomatch'
}
},
dialogue: {
on: {
FLOW: 'flow',
RESOLVE: 'output',
}
},
flow: {
on: {
NEXT: 'flow',
RESOLVE: 'dialogue',
//REPLY: 'output' (cannot go straight to output, must resolve and back to the dialogue)
}
},
nomatch: {
on: {
RETRY: {
target: 'digest',
actions: assign({
retries: (context, event) => context.retries + 1
})
},
RESOLVE: 'output'
}
},
command: {
on: {
RESOLVE: 'output'
}
},
populate: {
on: {
RESOLVE: 'output'
}
},
output: {
on: {
POPULATE: 'populate',
COMMAND: 'command',
REPLY: 'response',
}
},
response: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment