definePlugin() ·
before('message') hooks ·
ctx.abort() ·
ctx.onDispose() and unplug ·
plugin config
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; the fifth message is dropped
silently, so the user is warned only once per window:
How it works
definePlugin({ name, install })packages the feature;installgets the plugin context and the config passed tobot.plug(plugin, config). It must be synchronous.ctx.bot.before('message', (msg, next) => ...)runs before routing. Callnext()to continue;msg.abort()stops the message, so no handler, flow or catch-all sees it.- Per sender.
msg.senderis the user’s stable id, so in a group each participant has their own counter. - Cleanup. Hooks and handlers registered through
ctx.botare undone by the functionbot.plug()returns; timers and outside resources go inctx.onDispose(). - Outbound too. A
before('send')hook sees every message the bot sends ({ chatId, content }) and canabort()it in the same way. For WhatsApp anti-ban pacing,@botmesh/baileysalready rate-limits sends (see Rate limiting).
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
plugin works the same on every channel.
Next steps
- Plugins:
requires,multipleand plugin packages - Hooks: every hook point and its payload
- Handoff & access lists: block or allow senders without code