Examples
Echo Bot
Echoes back any text message. Try in Playground →
import { createBot } from "@effect-ak/tg-bot"
export default createBot() .onMessage(({ text }) => [ text(({ update, ctx }) => ctx.reply(update.text!)) ])Command Bot
Handles /start, /help, and /echo. The /echo command dumps the raw update as JSON — handy for debugging. Try in Playground →
import { createBot } from "@effect-ak/tg-bot"
export default createBot() .onMessage(({ command, text }) => [ command("/start", ({ ctx }) => ctx.reply("Hello! Try /help or /echo") ), command("/help", ({ ctx }) => ctx.reply( "Available commands:\n/start — welcome message\n/help — this message\n/echo — your message as JSON" ) ), command("/echo", ({ update, ctx }) => ctx.reply( `<pre language="json">${JSON.stringify(update, null, 2)}</pre>`, { parse_mode: "HTML" } ) ), text(({ ctx }) => ctx.reply("Unknown command. Try /help")) ])File Bot
Converts any text message into a .txt file and sends it back. Shows how to use ctx.replyWithDocument. Try in Playground →
import { createBot } from "@effect-ak/tg-bot"
export default createBot() .onMessage(({ command, text }) => [ command("/start", ({ ctx }) => ctx.reply("Send me any text and I'll save it as a file") ), text(({ update, ctx }) => ctx.replyWithDocument( { file_content: new TextEncoder().encode(update.text!), file_name: "message.txt" }, { caption: "Here's your text as a file" } ) ) ])