flow() DSL ยท
.ask() with validate ยท
.do() actions ยท
c.state ยท
.timeout() ยท
/cancel escapes a flow
Prerequisites
Node.js 22.12 or newer and a folder with"type": "module" (see
Getting started). Then install:
The complete bot
Sample transcript
Captured withnpx botmesh dev bot.js:
How it works
.ask(text, key, { validate })sends the question, waits for the answer and stores it inc.state[key].validatereturnstrueto accept, or the text to send before waiting again..do((ctx, c) => ...)runs code without sending anything: here it saves the user underctx.sender, their stable id on every channel..say((ctx, c) => ...)builds the summary from everything captured..timeout('5m')ends a flow the user abandoned; the bot-wideconversation.timeoutMessagesets what is sent then.- Commands win.
/cancel(fromslashCommandsPlugin) leaves the flow even while it waits for an answer.
Variations
Validate with a schema instead:schema takes any zod-compatible object,
and the parsed value lands in c.state (a number below):
Map. For several
fields in one native form on the WhatsApp Cloud API, see
Forms.
Run it on WhatsApp or Telegram
node bot.js prints a QR: scan it in WhatsApp โ Linked devices. For
Telegram, install @botmesh/telegram and swap the provider as shown in
Or connect Telegram; the
factory does not change.
Next steps
- Shopping flow: menus, sub-flows and
goto - Conversation flows: the whole flow DSL
- Testing: assert this flow with
createTestBot