Skip to content

TypeScript Types

VibeGram exports TypeScript declarations for the main Telegram Bot API 10.1 objects, framework helpers, middleware options, and error classes.

ts
import type { Update, Message, User, Chat, Context } from 'vibegram';

Core Types

TypeDescription
UpdateIncoming update from Telegram.
MessageMessage payload.
UserTelegram user.
ChatCompact chat identity from updates.
ChatFullInfoFull chat metadata returned by getChat.
CallbackQueryInline button callback.
InlineQueryInline mode query.
Context<S>Per-update handler context, optionally typed with session data.

Media Types

TypeDescription
PhotoSizePhoto metadata with dimensions.
AudioAudio file.
DocumentGeneric file.
VideoVideo file.
VoiceVoice note.
VideoNoteCircular video note.
AnimationGIF or H.264 animation.
LivePhotoBot API 10.0 live photo payload.
StickerSticker metadata.
ContactShared contact.
LocationGeographic coordinates.

Interactive Types

TypeDescription
PollPoll or quiz payload.
PollOptionSingle poll option.
PollMediaBot API 10.0 media attached to polls.
DiceAnimated dice result.
VenueVenue with location.
GameTelegram game payload.
WebAppDataData sent from a Mini App.

Keyboard Types

TypeDescription
ReplyMarkupUnion of supported reply markup payloads.
InlineKeyboardMarkupInline keyboard layout.
InlineKeyboardButtonInline keyboard button.
ReplyKeyboardMarkupNative reply keyboard layout.
KeyboardButtonNative reply keyboard button.
ReplyKeyboardRemoveRemove keyboard payload.
ForceReplyForce reply payload.

Entity Types

TypeDescription
MessageEntityText entity such as command, link, bold, code, spoiler, or blockquote.

Supported entity strings include mention, hashtag, bot_command, url, email, phone_number, bold, italic, underline, strikethrough, spoiler, code, pre, text_link, text_mention, custom_emoji, blockquote, expandable_blockquote, and date_time.

Update Types

TypeDescription
ChatMemberUpdatedMember status change.
ChatJoinRequestChat join request.
ShippingQueryPayment shipping query.
PreCheckoutQueryPayment pre-checkout query.
ChatBoostUpdatedChat boost event.
ChatBoostRemovedRemoved chat boost event.
PaidMediaPurchasedPaid media purchase event.

Extra Types

Extra types describe optional request parameters for shortcut methods.

ts
import type {
    ExtraReplyMessage,
    ExtraMedia,
    ExtraEditMessage,
    ExtraPoll,
    ExtraBanMember,
    ExtraRestrictMember,
    ExtraPromoteMember,
    ExtraInviteLink,
} from 'vibegram';

State and Helper Types

ts
import type {
    BotOptions,
    BotLaunchOptions,
    Middleware,
    NextFunction,
    SessionStore,
    RateLimitStore,
    UpdateDedupeStore,
} from 'vibegram';

Use these types when writing middleware, plugins, stores, or strongly typed bot instances.

Bot API 10.0 Types

TypeDescription
SentGuestMessageResult returned by answerGuestQuery.
BotAccessSettingsManaged bot access settings.
LivePhotoLive photo object returned in messages.
InputMediaLivePhotoLive photo input media payload.
PollMediaMedia payload for polls and poll explanations.
DeleteMessageReactionOptionsOptions for removing one message reaction.
DeleteAllMessageReactionsOptionsOptions for removing recent reactions.
SendLivePhotoOptionsExtra options for sendLivePhoto.

Bot API 10.1 Types

Rich Messages

TypeDescription
RichMessageRich formatted message (blocks + optional is_rtl).
InputRichMessageRich message to send; use exactly one of html or markdown.
InputRichMessageContentRich message content for inline query results.
RichTextPlain string, array of RichText, or a RichText* element.
RichBlockUnion of rich block types such as paragraph, heading, table, and photo.
RichBlockCaptionCaption (text + optional credit) for media blocks.
RichBlockTableCellA cell in a RichBlockTable.
RichBlockListItemAn item in a RichBlockList.

The inline RichText* and block RichBlock* types are exported individually for fine-grained typing.

Join Request Queries and Polls

TypeDescription
ChatJoinRequestQueryResult'approve' | 'decline' | 'queue' result for answerChatJoinRequestQuery.
LinkHTTP link object (url).
InputMediaLinkLink media usable as poll option media.

New fields on existing types include User.supports_join_request_queries, ChatFullInfo.guard_bot, ChatJoinRequest.query_id, and Message.rich_message.

Pagination Interfaces

ts
import type { PaginationItem, PaginationOptions } from 'vibegram';

const item: PaginationItem = {
    text: 'Product',
    callback_data: 'product:1',
};

PaginationOptions configures page number, page size, navigation callback data, optional page label pattern, and optional grid columns.

Session Interfaces

ts
import type { SessionStore } from 'vibegram';

class RedisSessionStore implements SessionStore {
    async get(key: string) {
        const value = await redis.get(key);
        return value ? JSON.parse(value) : undefined;
    }

    async set(key: string, value: unknown) {
        await redis.set(key, JSON.stringify(value));
    }

    async delete(key: string) {
        await redis.del(key);
    }
}

Use MemorySessionStore for local in-memory storage or implement SessionStore for Redis, SQL, or another external store.

Typed Sessions

ts
type MySession = {
    count: number;
    language: string;
};

bot.use(
    session<MySession>({
        initial: () => ({ count: 0, language: 'en' }),
    })
);

Typing the session middleware makes ctx.session strongly typed in downstream handlers.

Extending Context

ts
import type { Context } from 'vibegram';

interface AppContext extends Context<MySession> {
    user?: { id: string; role: 'admin' | 'member' };
}

const bot = new Bot<AppContext>(process.env.BOT_TOKEN!);

Use a custom context type when middleware attaches application-specific data.

Error Types

ts
import {
    ConversationTimeoutError,
    InvalidTokenError,
    NetworkError,
    RateLimitError,
    TelegramApiError,
    VibeGramError,
    WebAppValidationError,
} from 'vibegram';

Catch specific subclasses when the recovery behavior differs by error category.

Released under the ISC License.