migrate from puregram
puregram is a thin wrapper around update classes. yaebal is a composer framework where handlers share one accumulating context.
mental model
| puregram | yaebal |
|---|---|
Telegram client | Bot / createBot() |
| per-kind update objects | one context object with narrowed fields |
tg.extend(plugin) | bot.install(plugin) |
tg.api.method(params) | bot.api.method(params) or bot.api.call(name, params) |
| filters namespace | filter queries and @yaebal/filters |
initialization
// puregram
import { Telegram } from "puregram";
const tg = Telegram.fromToken(process.env.TOKEN!);
// yaebal
import { createBot } from "yaebal";
const bot = createBot(process.env.BOT_TOKEN!);dispatch
// puregram
tg.onMessage((message) => message.send("hello"));
tg.onCallbackQuery((query) => query.answer({ text: "ok" }));
// yaebal
bot.on("message:text", (ctx) => ctx.reply("hello"));
bot.on("callback_query:data", (ctx) => ctx.answerCallbackQuery({ text: "ok" }));api calls
yaebal has typed direct shortcuts for a growing method set and a generic call path for
every method in the generated schema.
// puregram raw layer
await tg.api.sendMessage({ chat_id: chatId, text: "hello" });
// yaebal typed shortcut if available
await bot.api.sendMessage({ chat_id: chatId, text: "hello" });
// yaebal escape hatch for every bot api method
await bot.api.call("sendMessage", { chat_id: chatId, text: "hello" });plugins
// puregram
const tg = Telegram.fromToken(token).extend(session());
// yaebal
const bot = createBot(token).install(session({ initial: () => ({}) }));filters
// puregram
tg.onMessage(filters.hasText, (message) => message.send(message.text));
// yaebal
bot.on("message:text", (ctx) => ctx.reply(ctx.text));webhooks
// yaebal edge webhook
export default {
fetch: webhook(bot, { secretToken: env.SECRET }),
};migration checklist
- replace update-object handlers with context handlers.
- use
on("message:text"),on("callback_query:data"), and other filter queries for narrowing. - move plugin installs to
.install(). - replace per-update shortcuts with generated
ctx.*shortcuts when usingcreateBot(). - use production for runner/throttle/retry choices.