Install
Usage
- Polling needs no public URL: use it in development and for a bot that
runs as one process. Only one poller per token may run (a second one gets
409and the provider stops). - Webhook suits serverless and multi-replica deployments behind HTTPS.
Register the URL once with the Bot API’s
setWebhook, passing the same secret assecret_token.
- Inline keyboards, native polls, reactions, message edits.
ctx.stream()uses native drafts in private chats and edits elsewhere.- In webhook mode
ingest(body, headers)takes the raw bytes, the JSON string or the parsed object, and checks theX-Telegram-Bot-Api-Secret-Tokenheader (any case, plain or FetchHeaders).@botmesh/serverneeds no extra option. Afterstop()it answers503and emits nothing, so Telegram redelivers those Updates once the bot is back. - Group commands addressed to the bot (
/menu@MyBot) reachbot.command('menu'), also in a media caption: the provider drops the suffix when it names this bot (username fromgetMe, or theusernameoption when you passselfId). - Mentions of the bot: an
@MyBotin the text and a command addressed as/menu@MyBotput the bot’sselfIdinctx.mentions, sogroupMode: 'mentions'lets them through. Other@usernamementions carry no user id and are not listed; atext_mention(a user without username) is. - Every Bot API request has a client timeout (
requestTimeoutMs, 120 s by default; long polls getpollTimeoutMs(30 s by default) + 15 s; file uploads getuploadTimeoutMs, 5 min by default), errors never carry the bot token, a 429retry_afteris honoured up to 24 h, andbot.stop()cuts the poll loop’s retry waits at once. - Edited messages reach the bot as messages with the new text and the
original
ref.id(replies, reactions and edits target the edited message).isEditedMessage(ctx)tells them apart; the core deduper lets an edit through because its content changed.editedMessages: 'ignore'turns them off. - Poll votes: polls are sent non-anonymous (
is_anonymous: false), so each vote arrives as apoll_answerupdate and becomes a'poll'event with the tally, like on WhatsApp. Chat members can see who voted;anonymousPolls: truesends anonymous polls, whose votes never reach the bot. Votes are tallied for polls this process sent (in memory, the last 500): a vote on a poll sent before a restart is dropped. Channels do not allow public-voter polls: a poll to a channel is retried once as anonymous (no votes) and that channel gets anonymous polls from then on. - Self-hosted Bot API server: set
baseUrlto it. On plain HTTP or a private network, media downloads also needmediaDownload: { allowHttp: true, allowPrivateHosts: true }(plus a largermaxBytes). Run the server without--local, whose file paths are not served over HTTP.
Next steps
- Channels: choosing a channel, the capability matrix and the cross-channel contract.
- Streaming replies: native drafts in private chats.
- Webhook server: webhook mode with
@botmesh/server. - Package README