bot.conversation() ·
c.waitText() with timeout and validate ·
c.choose() ·
ConversationTimeout / ConversationCancelled ·
/cancel escapes a conversation
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:
⏰ Support session expired. Send "support" to start again.
How it works
bot.conversation(name, async (c, ctx) => ...)is plain async code: it starts when a message matchesname(or thetriggeroption),ctxis that message andcholds the waits. Use it when the logic does not fit a linearflow().c.waitText({ timeout, validate })waits for the next text of the same user. A rejected answer sends thevalidatetext and waits again.c.choose(prompt, options)sends a numbered menu and resolves with the chosen key.- Errors end the conversation. A silent user makes the wait throw
ConversationTimeout;/cancelconfirms the cancellation itself and makes the wait throwConversationCancelled. Catch them to answer or clean up (here, discard the draft ticket); without acatch, a timeout sends the built-in text, whichconversation.timeoutMessagecustomizes. - Commands always escape.
/canceland/resetbeat an active conversation, so users are never trapped.
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
- Handoff & access lists: pass the chat to a human agent
- Conversation flows: retries, idle timers, persistent flows
- Plugin: rate limiter: protect the bot from floods