Skip to main content
Level: Beginner · Tags: WhatsApp, Telegram, Commands Features shown: WELCOME trigger · text and regex triggers · ctx.pass() · slash commands · catch-all · terminal simulator

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 --name Ana:

How it works

  • WELCOME fires on the first message of each user (per chat in a DM, per participant in a group) and runs before every other trigger. ctx.pass() lets the same message continue, so “Hí” also reaches the hi handler. /reset re-arms the welcome.
  • Text triggers compare the whole message after normalizing it (lowercase, accents stripped, spaces collapsed): 'hi' matches “Hí ” but not “hi there”. A list matches any of its entries.
  • A regex matches anywhere in the text; ctx.body keeps the original text, so the echo keeps the user’s casing.
  • slashCommandsPlugin adds /start, /help, /reset, /cancel, /id and /ping; greeting replaces the text of /start and /help.
  • bot.onMessage() is the catch-all: it only runs when nothing else handled the message.

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

  • FAQ bot: more trigger forms (contains, regex, lists)
  • Special triggers: WELCOME, message types and calls
  • Testing: assert these replies with createTestBot