Skip to main content

Requirements

  • Node.js 22.12 or newer (download). Check with node -v.
  • npm (bundled with Node) or pnpm. The commands below use npm; with pnpm, write pnpm add, pnpm create and pnpm exec. On pnpm 11, installing @botmesh/baileys first stops with ERR_PNPM_IGNORED_BUILDS; see Troubleshooting.
  • To connect for real: a phone with WhatsApp (its number becomes the bot) or a Telegram bot token from @BotFather. The terminal simulator needs neither.
Betabotmesh is in beta: a plain install gets the beta, and @beta always resolves to the newest one (latest is moved by hand after each publish). This site documents the beta, then @botmesh/core 2.0.0 stable.

Option A: scaffold a project (recommended)

create-botmesh generates a project that runs both in the simulator and on the real channel:
Type hola, then menu, then /help. When you are happy with it, connect the real channel:
If .env lacks a variable the project needs, npm start stops with one line naming it (Missing TELEGRAM_TOKEN: copy .env.example to .env ...) before connecting anything. The templates are written in Spanish and set lang: 'es'. The full list of templates, the CLI flags and the generated files are in Project templates.

Option B: set it up by hand

1. Install

For Telegram, install @botmesh/telegram instead of @botmesh/baileys, and use the Telegram version of bot.js from Or connect Telegram: the file below imports @botmesh/baileys, so it does not load without it. botmesh ships only ES modules, so the project needs "type": "module" (or .mjs files) and you load the packages with import.

2. Write the bot

Create bot.js. The bot is a factory (defineBot): it receives a provider and returns the configured Bot. The same file then runs in the simulator and on the real channel:

3. Try it in the terminal

The simulator injects an in-memory provider, so nothing leaves your machine, and it reloads the bot when you save the file. :help lists its commands and :quit exits. More in Terminal simulator.

4. Connect a real channel

A QR code appears in the terminal. On the phone whose number will be the bot:
  1. Open WhatsApp → Settings → Linked devices.
  2. Tap Link a device and scan the QR.
When ✅ Connected prints, send hi to that number from another phone. The login is saved in ./sessions/my-bot/, so the next start reconnects without a QR. Keep that folder private and out of git: whoever has it controls the account.
Unofficial protocolBaileys speaks the WhatsApp Web protocol, which Meta does not support for bots: the linked number can be restricted or banned. Use a spare number while you try things, and the official Cloud API for production.
No camera at hand?Link with a code instead: pass the bot’s number to the provider and print the code it receives.
Then in WhatsApp: Linked devices → Link a device → Link with phone number instead, and type the code.

Or connect Telegram

Create a bot with @BotFather (/newbot) and copy its token. In bot.js, change two places: the provider import at the top and the start block at the bottom. The factory in between stays the same.
Create a file named .env next to bot.js with your editor, containing one line:
Avoid echo ... > .env in Windows PowerShell: it writes the file as UTF-16 or with a BOM, Node does not read the variable, and the provider stops with `token` is required. Then start the bot:
Open your bot in Telegram and send hi. The provider uses long polling by default, so no public URL is needed.

Other channels

Only the provider changes: handlers, flows, hooks and plugins are the same on every transport. The official WhatsApp Cloud API, for example:
It is webhook-based: your HTTP server passes the raw body of each POST to provider.ingest(rawBody, headers). See Webhook server to mount it and Channels for what each transport supports.

Troubleshooting

Project templates

The use-case templates (games to ai-full) run on Baileys. The transport templates (baileys, meta, telegram, ai) install the built-in slash commands, so /reset or /cancel escapes their sample menu flow. Every project contains package.json (with npm start and npm run dev), src/bot.js, .env.example, .gitignore, a README.md and an AGENTS.md that tells AI coding agents which API to use and which commands to run.

Next steps