src/telegram/client.ts — telegraf factory
One-liner factory for the telegraf Bot client. Used as an outbound transport
only — we never call bot.launch(), because that would start telegraf’s own
inbound polling/webhook loop and conflict with our Fastify route.
Public surface
| Export | Shape | Purpose |
|---|---|---|
createBot(token) | (string) => Telegraf | Construct the client |
Why a factory
Telegraf holds connection-pool state. Production wiring (one instance
shared across the dispatcher), tests (synthetic instances or mocks), and the
register-webhook script (a transient one for the setWebhook call) all
need their own; a module-level singleton would couple them.
Phase 2+ note
Phase 2’s outbound MCP tools (send_message, send_image, edit_message,
send_buttons) will call methods on this same Telegraf instance via
bot.telegram.<method>. That extra surface will move into a dedicated
src/telegram/outbound.ts module — this file stays at one line.