migrate from puregram

puregram is a thin wrapper around update classes. yaebal is a composer framework where handlers share one accumulating context.

mental model

puregramyaebal
Telegram clientBot / createBot()
per-kind update objectsone 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 namespacefilter queries and @yaebal/filters

initialization

init.ts
// 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

dispatch.ts
// 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.

api.ts
// 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

plugins.ts
// puregram
const tg = Telegram.fromToken(token).extend(session());

// yaebal
const bot = createBot(token).install(session({ initial: () => ({}) }));

filters

filters.ts
// puregram
tg.onMessage(filters.hasText, (message) => message.send(message.text));

// yaebal
bot.on("message:text", (ctx) => ctx.reply(ctx.text));

webhooks

webhook.ts
// 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 using createBot().
  • use production for runner/throttle/retry choices.