Simple SDK for archiving Telegram bot events and chats using Telegraf.
npm install @passimx/archiver- Node.js >= 18 (uses native
fetch) telegraf>= 4
You can obtain an API key via Telegram bot:
Send command:
/verify <your_bot_token>
After verification you will receive your API key.
After connecting, it is strongly recommended to revoke your Telegram bot token via @BotFather:
👉 /revoke (в @BotFather)
This will invalidate the old token and protect your bot.
import { Telegraf } from 'telegraf';
import { Archiver } from '@passimx/archiver';
const bot = new Telegraf(process.env.BOT_TOKEN!);
const archiver = new Archiver({
apiKey: 'YOUR_API_KEY',
// endpoint is optional
});
// Start listening and sending events
archiver.listen(bot);
bot.start((ctx) => ctx.reply('Hello'));
bot.launch();const chat = await archiver.exportChat(123456);
console.log(chat);- Forwards all incoming Telegram updates to your API
- Intercepts outgoing Telegram API calls (send*, edit*) by patching Telegraf internals
- Sends all events to your backend for storage or processing
- Provides chat export via API
| Option | Type | Description |
|---|---|---|
| apiKey | string | Authorization key |
| endpoint | string | API base URL (optional) |
If endpoint is not provided, a default value will be used.
Starts tracking:
- incoming updates
- outgoing messages
Fetches chat data from API.
Returns:
Promise<ChatInterface | null>- This library patches Telegraf internally
- Errors are logged to console
- Make sure your API is available and accepts requests
MIT