import { Composer, TeleBibz, rich, type TelegramMethodName, type TelegramMethodPayload, TelegramTypes } from '..'; const bot = new TeleBibz('123456:TESTTOKEN', { silent: true }); const privateRoutes = new Composer(); privateRoutes.filter((ctx) => ctx.chat?.type === 'private').command('profile', (ctx) => ctx.reply('profile')); bot.use(privateRoutes); bot.filter((ctx) => ctx.chat?.type === 'private', (ctx) => ctx.reply('private filter')); bot.drop((ctx) => ctx.from?.is_bot === true, (ctx) => ctx.reply('drop route')); bot.branch((ctx) => Boolean(ctx.chat), (ctx) => ctx.reply('chat'), (ctx) => ctx.reply('no chat')); bot.route((ctx) => ctx.chat?.type ?? 'unknown', { private: (ctx) => ctx.reply('private') }); bot.lazy(() => (ctx) => ctx.reply('lazy')); bot.fork((ctx) => ctx.reply('fork')); bot.inlineQuery('*', (ctx) => ctx.answerInlineQuery([])); const message = rich.blocks([ rich.heading('Typed rich content', 2), rich.paragraph(['Status: ', rich.bold('ready')]), rich.table([[{ text: 'Count', align: 'right', valign: 'middle' }]]), ]); bot.api.callApi('sendRichMessage', { chat_id: 42, rich_message: message }); bot.api.callApi('sendMessageDraft', { chat_id: 42, draft_id: 1, text: 'Draft', can_stop: true }); bot.api.callApi('sendLivePhoto', { chat_id: 42, live_photo: 'video-id', photo: 'photo-id' }); const method: TelegramMethodName = 'answerGuestQuery'; const payload: TelegramMethodPayload<'answerGuestQuery'> = { guest_query_id: 'guest-query-id', result: { type: 'article', id: '1', title: 'Answer', input_message_content: { message_text: 'Hello' } }, }; void method; void payload; const draft: TelegramTypes.InputRichMessage = rich.draftMarkdown('**streamed text**'); const blockDraft = rich.draftBlocks([rich.paragraph('partial'), rich.thinking('working')]); bot.on('message', (ctx) => { void ctx.sendRichMessageDraft(2, draft); void ctx.sendRichMessageDraft(4, blockDraft); }); // A normal rich message can contain media uploads; drafts have the stricter, no-upload schema. // @ts-expect-error regular rich builder type may include uploadable media, so it is not a draft payload. void bot.on('message', (ctx) => ctx.sendRichMessageDraft(3, rich.markdown('draft'))); type RichBlock = TelegramTypes.InputRichBlock; const block: RichBlock = { type: 'paragraph', text: 'Typed by the vendored Telegram API schema' }; void block; // Invalid parameters must remain rejected by method-specific TypeScript typing. // @ts-expect-error sendRichMessage requires chat_id and rich_message, not text. bot.api.callApi('sendRichMessage', { chat_id: 42, text: 'not a rich message' }); // @ts-expect-error method name must exist in the official Bot API method schema. bot.api.callApi('sendNotARealMethod', {});