Skip to main content
Level: Intermediate · Tags: WhatsApp, Telegram, Flows Features shown: .choose() menus · then sub-flows · goto · c.state · .timeout() and timeoutMessage · bot.lint()

Prerequisites

Node.js 22.12 or newer and a folder with "type": "module" (see Getting started). Then install:

The complete bot

Sample transcript

Captured with npx botmesh dev bot.js:

How it works

  • .choose(prompt, options, key) sends a numbered menu, accepts the number, the key or the label, and stores the chosen key in c.state[key]. Without a key it goes to c.state.choice.
  • then: address runs the address flow inline when “Yes” is picked; it shares c.state, so the last .say() reads street and city. flow([]) has no trigger: it only runs from here.
  • goto: 'shop' leaves the current flow and starts the named one (here, the same shop from the top). bot.lint() reports a goto to a flow that is not registered as an error (goto-target-missing).
  • A function .say() can compute and store values (c.state.total) for later steps.
  • .timeout('2m') applies to every wait of the flow; when it fires the bot sends conversation.timeoutMessage. A then sub-flow uses its own .timeout() (or the bot-wide default).

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