Skip to main content
Level: Beginner · Tags: WhatsApp, Telegram, Triggers Features shown: text triggers with normalized matching · keyword lists · contains matching · regex triggers · trigger precedence · catch-all

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

  • Normalized equality. A string trigger matches the whole message after lowercasing, stripping accents and collapsing spaces, so “HÓURS” matches hours, but “hours please” does not: it falls to the catch-all. That keeps short keywords from firing inside unrelated sentences.
  • Punctuation counts. “Where are you?” is not “where are you”, so the catch-all answers it. Add the variant to the list ('where are you?') or use a regex such as /^where are you\??$/i when users type it.
  • Lists. bot.when(['hours', 'opening hours'], ...) matches any entry; the loop registers one handler per FAQ entry.
  • contains. { pattern: 'delivery', match: 'contains' } matches the word anywhere; startsWith and endsWith exist too.
  • Regex. /#\d{4,}/ finds an order number in any sentence.
  • Precedence. When several triggers match, the most specific wins: plain text, then startsWith, endsWith, regex, contains, and the catch-all last.

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

  • Menu bot: guide the user with a numbered menu instead of keywords
  • Special triggers: react to images, locations or calls
  • AI plugin: answer free-form questions with a model