@codexverified/tgpro
v1.0.0-codexverified.1
Published
A friendlier, fully-typed Telegram Bot API library for Node.js/TypeScript, maintained by Codex (DevCodex) for CodexVerified.
Maintainers
Readme
@codexverified/tgpro
A readable, carefully maintained, fully typed Telegram Bot API library for building reliable Telegram integrations with @codexverified/tgpro.
@codexverified/tgpro is a Node.js and TypeScript library for creating Telegram bots over the official Bot API. It provides a socket-free, typed API for updates, messages, media, keyboards, rich responses, inline queries, payments, stickers, chat administration, forum topics, sessions, scenes, rate limiting, internationalization, webhooks, long polling, serverless adapters, and documented extensions.
The package is maintained by Codex, also known as DevCodex, under the CodexVerified organization. It is intended for developers who want a practical Telegram Bot API foundation with familiar interfaces, public TypeScript declarations, readable source code, explicit behavior, and room for carefully tested improvements.
Table of contents
- At a glance
- Installation
- Quick start
- CommonJS usage
- Core capabilities
- Everyday bot usage
- Keyboard and callback example
- Rich messages and drafts
- Authentication and deployment guidance
- Development workflow
- Recent compatibility updates
- About Codex
- Package layout
- Security and responsible use
- Disclaimer
- Privacy policy
- License and maintenance
- Compatibility additions
- Complete API coverage
At a glance
| Property | Value |
| --- | --- |
| Package | @codexverified/tgpro |
| API coverage | Telegram Bot API 7.0 through 10.3 |
| Runtime | Node.js 18 or newer |
| Module format | ESM, with CommonJS compatibility where supported |
| Type declarations | Included with the package |
| Runtime dependencies | Zero required runtime dependencies |
| Maintainer | Codex / DevCodex |
| Organization | CodexVerified |
| Repository | https://github.com/codexverified/tgpro |
Installation
| Method | Command | Notes |
| --- | --- | --- |
| From npm | npm install @codexverified/tgpro | Standard installation for published releases |
| Source audit | npm install --ignore-scripts | Skips install hooks for local review |
| Optional Redis support | npm install ioredis | Only required for RedisSessionStore |
| Optional SQLite support | npm install better-sqlite3 | Only required for SqliteSessionStore |
Both npm and source installs use the same import name:
import { Bot } from '@codexverified/tgpro'Node.js 18 or newer is required because the package uses native fetch, FormData, and Blob globals.
Quick start
The following example creates a bot, registers common handlers, and starts long polling. Store the bot token in an environment variable and never commit it to a public repository.
import { Bot } from '@codexverified/tgpro'
const bot = new Bot(process.env.BOT_TOKEN)
bot.command('start', (ctx) => ctx.reply(`Hello ${ctx.from?.first_name ?? 'there'}!`))
bot.hears(/^ping$/i, (ctx) => ctx.reply('pong'))
bot.on('photo', (ctx) => ctx.reply('Photo received.'))
bot.catch((error, ctx) => console.error('Update failed:', ctx.updateType, error))
bot.launch().catch(console.error)CommonJS usage
const { Bot } = require('@codexverified/tgpro')
const bot = new Bot(process.env.BOT_TOKEN)If your runtime or bundler does not support this interop path, use the ESM import form instead.
Core capabilities
| Area | What it covers |
| --- | --- |
| Updates and routing | Commands, text matching, actions, update types, predicates, routers, and fallback handlers |
| Messages and media | Text, photos, videos, audio, documents, stickers, polls, locations, contacts, venues, albums, and live locations |
| Interactive content | Inline keyboards, reply keyboards, callback buttons, Web Apps, payments, inline mode, and copy-text buttons |
| Rich content | Markdown, HTML, structured blocks, tables, checklists, media blocks, buttons, details, and expandable quotations |
| Conversations | Sessions, memory stores, Redis and SQLite stores, scenes, wizard scenes, and multi-step flows |
| Reliability | Flood-control retries, throttling, incoming rate limiting, typed API errors, and central error handling |
| Deployment | Long polling, standalone webhooks, raw HTTP callbacks, Vercel, AWS Lambda, and Cloudflare Workers |
| Localization | Locale-aware dictionaries, interpolation, pluralization, fallback locales, and ctx.t() |
| API coverage | Typed wrappers across the Telegram Bot API, with api.call() for newly released methods |
Everyday bot usage
| Update or operation | Key API | Example |
| --- | --- | --- |
| Command | bot.command() | bot.command('start', (ctx) => ctx.reply('Hello')) |
| Text matching | bot.hears() | bot.hears(/^help$/i, (ctx) => ctx.reply('Help')) |
| Message type | bot.on() | bot.on('photo', (ctx) => ctx.reply('Received')) |
| Callback action | bot.action() | bot.action('confirm', (ctx) => ctx.answerCbQuery()) |
| Direct API call | bot.api | bot.api.sendMessage({ chat_id, text }) |
| Current update | ctx | ctx.chat, ctx.from, ctx.text, ctx.match |
bot.command(['help', 'h'], (ctx) => ctx.reply('Available commands: /start, /help'))
bot.command('ban', (ctx) => ctx.reply(`Request: ${ctx.match?.[1] ?? 'no reason'}`))
bot.hears(/^good (morning|evening)$/i, (ctx) => ctx.reply(`Good ${ctx.match[1].toLowerCase()}!`))
bot.on('text', (ctx) => ctx.reply(`You said: ${ctx.text}`))
bot.on('callback_query', (ctx) => ctx.answerCbQuery('Received'))
bot.on('inline_query', (ctx) => ctx.answerInlineQuery([]))
bot.otherwise((ctx) => ctx.reply('I did not understand that message.'))Context helpers resolve the current chat or message where Telegram provides enough information:
await ctx.reply('text')
await ctx.replyWithPhoto({ source: './photo.jpg' })
await ctx.replyWithDocument({ source: './report.pdf' })
await ctx.replyWithPoll('Choose one', ['First', 'Second'])
await ctx.editText('edited text')
await ctx.deleteMessage()Keyboard and callback example
import { Bot, Keyboard } from '@codexverified/tgpro'
const bot = new Bot(process.env.BOT_TOKEN)
bot.command('menu', (ctx) => ctx.reply('Choose an option:', {
reply_markup: Keyboard.inline()
.button('Confirm', 'confirm:yes', { style: 'success' })
.button('Cancel', 'confirm:no', { style: 'danger' })
.row()
.url('Documentation', 'https://example.com/docs')
.row()
.webApp('Open application', 'https://example.com/app')
.build()
}))
bot.action(/^confirm:(yes|no)$/, async (ctx) => {
await ctx.answerCbQuery()
await ctx.editText(ctx.match[1] === 'yes' ? 'Confirmed.' : 'Cancelled.')
})The keyboard builders support inline buttons, URLs, Web Apps, inline switches, payments, copy-text actions, reply buttons, contact requests, location requests, keyboard removal, and force replies.
Rich messages and drafts
RichMessage provides Markdown, HTML, and structured block builders. Telegram rich-message features should be tested against the client versions your application supports.
import { Bot, RichMessage } from '@codexverified/tgpro'
const bot = new Bot(process.env.BOT_TOKEN)
bot.command('report', (ctx) => ctx.replyRich(
RichMessage.markdown()
.heading('Build report', 2)
.text("Today's run:")
.table(['Step', 'Status'], [['Install', 'Done'], ['Test', 'Done'], ['Deploy', 'Pending']])
.checklist(['Install dependencies', 'Run tests', { label: 'Deploy', done: false }])
.codeBlock('npm install @codexverified/tgpro', 'bash')
.blockquote('Generated by the application.')
.build()
))
bot.command('card', (ctx) => ctx.replyRich(
RichMessage.blocks()
.heading('Server status', 2)
.paragraph('All systems operational.')
.divider()
.table([
[{ text: 'Region', is_header: true }, { text: 'Uptime', is_header: true }],
[{ text: 'EU' }, { text: '99.99%' }]
], { bordered: true, striped: true })
.buttons([{ text: 'Open dashboard', url: 'https://example.com' }])
.build()
))For private-chat AI streaming, use draft messages:
await bot.api.sendMessageDraft({ chat_id: 42, draft_id: 1, text: 'Generating a response...' })
await bot.api.sendRichMessageDraft({
chat_id: 42,
draft_id: 1,
rich_message: RichMessage.markdown().text('Response complete.').build()
})Drafts are ephemeral, private-chat only, and require a non-zero draft_id.
Authentication and deployment guidance
| Practice | Detail | | --- | --- | | Token privacy | Keep the bot token in a secret manager or environment variable; never commit it | | Access control | Grant the bot only the Telegram permissions it needs | | Session privacy | Protect session stores and remove sensitive state from logs | | Webhook security | Use HTTPS, validate secret tokens, and restrict the exposed endpoint | | Rate control | Configure incoming rate limits and outgoing flood-control behavior | | Runtime | Use Node.js 18 or newer and pin dependencies for production deployments | | Data handling | Document what updates, files, identifiers, and session data your application retains |
await bot.launch({ dropPendingUpdates: false, allowedUpdates: ['message', 'callback_query'] })
await bot.launchWebhook({
url: 'https://example.com/telegram',
port: 8080,
path: '/telegram',
secretToken: process.env.WEBHOOK_SECRET
})Serverless adapters are available for Vercel, AWS Lambda, and Cloudflare Workers. Applications may also use bot.webhookCallback() or call bot.handleUpdate(update) directly.
Development workflow
npm test
npm run build
npm run docs:apiBefore submitting changes, validate TypeScript declarations, ESM syntax, CommonJS compatibility, generated documentation, mocked API behavior, and package exports. When a Telegram feature is experimental or version-sensitive, document fallback behavior and the client or Bot API versions used during testing.
Recent compatibility updates
| Update | Detail |
| --- | --- |
| Typed Bot API coverage | Typed wrappers cover core, messaging, administration, payments, stickers, forums, business features, and newer Bot API areas |
| Rich messages | Markdown, HTML, structured blocks, media, tables, buttons, and details are available through builders |
| Draft messages | Plain and rich draft-message helpers support private-chat streaming previews |
| Serverless adapters | Webhook helpers support Vercel, AWS Lambda, Cloudflare Workers, and raw HTTP integration |
| Reliability controls | Automatic retry_after handling, outgoing throttling, incoming rate limits, and typed errors are included |
About Codex
This package is built and maintained by Codex, also known as Dev Codex. Codex is a developer from Nigeria who focuses on practical, accessible, and reliable software projects across the JavaScript and TypeScript ecosystem.
| | | | --- | --- | | Tech stack | JavaScript, HTML, TypeScript, Node.js, GitHub, Telegram Bot API, APIs, and key-value stores | | Project types | Application development, websites, Telegram bots, WhatsApp bots, API endpoints, and games | | Telegram | @codexverified | | Email | [email protected] | | Organization | CodexVerified |
The developer's work is driven by a commitment to learning, experimentation, clear documentation, and useful software that developers can understand and extend. This package reflects that commitment through its readable source, public declarations, practical examples, and emphasis on responsible automation.
Package layout
| Path | Contents |
| --- | --- |
| src/ | Bot, context, composer, API, middleware, scene, session, and utility implementations |
| src/client.ts | Typed Telegram Bot API client surface |
| src/context.ts | Update context, accessors, and reply helpers |
| src/composer.ts | Middleware engine, handlers, gates, combinators, and router |
| test/ | Unit, integration, and behavior-focused tests |
| docs/ | Generated API and package documentation |
| package.json | Package metadata, scripts, dependencies, and exports |
| README.md | User-facing installation and usage guide |
Security and responsible use
This library interacts with Telegram bots, chats, users, messages, files, and other platform data.
| Guideline | Detail | | --- | --- | | Authorization | Use only with bot tokens, chats, accounts, and data you are authorized to control | | Compliance | Respect Telegram's terms, applicable law, and the privacy expectations of message participants | | Messaging conduct | Avoid unsolicited messaging, harassment, spam, and deceptive automation | | Credential safety | Protect bot tokens, session stores, webhook secrets, private keys, and personal data | | Data minimization | Collect and retain only the Telegram data required for the application's purpose | | Transparency | Provide clear notice when an application performs automated actions or processes user data | | Dependency review | Review installation scripts and optional dependencies before production; use pinned versions |
Disclaimer
@codexverified/tgpro is an independent, source-available Node.js library that communicates with Telegram using the Telegram Bot API. It is not affiliated with, endorsed by, or officially connected to Telegram or its owners. "Telegram" is a trademark of its respective owner, referenced here only for interoperability description.
No malware, no phishing, no hidden network calls. As a matter of project policy and design:
| Statement | Detail |
| --- | --- |
| No malicious payloads | The package does not contain, download, execute, or otherwise support malware, spyware, ransomware, keyloggers, or similar malicious code. |
| No phishing or credential harvesting | The library does not construct, send, or facilitate phishing messages, fake login prompts, or credential-harvesting flows. It provides generic bot primitives; how an application built on top of them is used is the responsibility of that application's developer. |
| No covert data exfiltration | The package does not silently transmit messages, contacts, media, bot tokens, session state, or user data to Codex, CodexVerified, or any third party. Network calls are made for Telegram API operations and explicitly caller-invoked integrations. |
| No obfuscated code | The source is distributed as readable JavaScript/TypeScript with public type declarations, so it can be inspected. Installs can be run with --ignore-scripts for an audit-first review. |
| Not a guarantee, an invitation to verify | This statement describes project design intent and current source code. It is not a substitute for your own review, a third-party security audit, or a legal warranty. |
Developer responsibility and acceptable use
This package gives developers general-purpose building blocks for Telegram automation, including messaging, administration, files, payments, inline queries, webhooks, and rich responses. Like any general-purpose toolkit, those building blocks can be pointed at abusive uses by a developer who chooses to.
| Prohibited or discouraged use | Why it is a problem | | --- | --- | | Sending unsolicited bulk messages or promotional content | Harms recipients, creates spam, and may violate Telegram policies and applicable anti-spam laws | | Phishing, impersonation, credential harvesting, or fraudulent support flows | Deceives users, creates security risk, and may be unlawful | | Unauthorized collection or surveillance of messages, files, identifiers, or locations | Violates user expectations and may breach privacy and data-protection laws | | Circumventing Telegram restrictions, rate limits, moderation, or account-integrity controls | Undermines platform trust and can result in account restrictions | | Using administration, payment, or file features without appropriate authorization | Can cause financial loss, privacy incidents, or unauthorized changes to chats | | Deploying unreviewed integrations with exposed bot tokens or insecure webhooks | Can allow third parties to control the bot or access application data |
Where responsibility sits. CodexVerified builds and documents the library itself, not the applications developers build with it. If a developer chooses to use this package for abusive, unlawful, or unauthorized conduct, that developer, not CodexVerified or the @codexverified/tgpro project, is solely responsible for that conduct, including any legal, financial, privacy, or platform consequences. The maintainers do not operate, monitor, or have visibility into third-party deployments of this code, and inclusion of a feature is not an endorsement of every way it could be used.
This project's position is the opposite of misuse: CodexVerified is built around respecting user privacy and giving developers transparent, inspectable tools, not around helping anyone spam, deceive, manipulate, surveil, or access systems without authorization.
No warranty. This software is provided "as is," without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, and non-infringement, to the fullest extent permitted by the applicable license and law. Use of this package to interact with Telegram may be subject to Telegram's own terms and policies, which are outside the maintainers' control.
Privacy policy
This section describes what the package itself does and does not do with data. It does not describe how any particular application built on top of this package handles data; that is determined by the developer of that application.
Data the package handles locally or through your configured infrastructure:
| Data type | How it is handled | | --- | --- | | Bot token | Supplied by your application and used to authenticate requests to Telegram. The package does not upload it to Codex or CodexVerified. | | Telegram updates | Received from Telegram through polling, webhooks, or an explicitly invoked update handler, then passed to your application code. | | Messages and media | Sent to and received from Telegram as part of normal Bot API operation. Storage, logging, and retention are controlled by your application. | | Session and scene state | Stored wherever your application configures it, such as memory, Redis, or SQLite. Keep it private. | | Optional integrations | Called only when your application explicitly invokes them. Review each destination, credential, and privacy policy before use. |
What the package does not do:
- It does not phone home, run analytics or telemetry, or transmit usage data to Codex, CodexVerified, or another unrelated party.
- It does not embed hidden credentials, tracking identifiers, remote kill switches, or covert monitoring.
- It does not access data outside what your application explicitly wires it to receive, store, or send.
Your responsibilities as a developer. If you build an application that collects personal data, you are responsible for explaining the processing to users, obtaining required permissions, minimizing collection, securing bot tokens and session stores, defining retention periods, handling applicable access or deletion requests, and complying with applicable privacy laws such as GDPR, CCPA, or Nigeria's NDPA. This package is a communication toolkit, not a compliance framework.
Contact. Questions about this policy or the project can be sent to [email protected] or via @codexverified on Telegram.
License and maintenance
This distribution is provided under the license declared in package.json and the accompanying license file. Review those terms before redistributing or combining this package with third-party code.
@codexverified/tgpro is built and maintained by Codex under the CodexVerified organization. Contributions, bug reports, and carefully documented improvements are welcome through the project repository.
Compatibility additions
The current source includes independently implemented compatibility helpers and package-owned improvements for Telegram Bot API behavior. These additions preserve the Codex package identity and do not copy package-specific attribution enforcement or remote licensing checks.
Typed API and escape hatch
Every documented Bot API method has a typed wrapper. Newly released or temporarily undocumented methods can be called through api.call().
const me = await bot.api.getMe()
const sent = await bot.api.sendMessage({ chat_id: 42, text: 'Hello' })
await bot.api.call('someNewTelegramMethod', { chat_id: 42, value: true })Sessions and localization
import { createI18n, rateLimit, session } from '@codexverified/tgpro'
bot.use(session())
bot.use(rateLimit({
windowMs: 2000,
limit: 3,
keyFn: (ctx) => ctx.from ? String(ctx.from.id) : undefined
}))
const i18n = createI18n({
defaultLocale: 'en',
locales: {
en: { greeting: (name) => `Hello ${name}!` },
fr: { greeting: (name) => `Bonjour ${name}!` }
}
})
bot.use(i18n.middleware())
bot.command('start', (ctx) => ctx.reply(ctx.t('greeting', ctx.from?.first_name ?? 'there')))Complete API coverage
bot.api exposes typed methods across the following categories. The exact generated method list is defined by the package source and declarations.
| Category | Representative methods |
| --- | --- |
| Core and updates | call, fileUrl, getMe, getUpdates, setWebhook, deleteWebhook, getWebhookInfo |
| Messages | sendMessage, sendMessageDraft, sendRichMessage, forwardMessage, copyMessage |
| Media | sendPhoto, sendVideo, sendAudio, sendDocument, sendAnimation, sendSticker, sendVoice, sendVideoNote |
| Location and interaction | sendLocation, sendVenue, sendContact, sendPoll, sendQuiz, sendDice, sendChatAction |
| Editing and deletion | editMessageText, editMessageCaption, editMessageMedia, editMessageReplyMarkup, stopPoll, deleteMessage, deleteMessages |
| Files | getFile, getFileLink, getUserProfilePhotos, getUserProfileAudios |
| Chat administration | banChatMember, restrictChatMember, promoteChatMember, setChatPermissions, getChatMember |
| Topics and forums | createForumTopic, editForumTopic, closeForumTopic, reopenForumTopic, deleteForumTopic |
| Bot profile and commands | setMyCommands, getMyCommands, setMyName, setMyDescription, setChatMenuButton |
| Inline and callbacks | answerCallbackQuery, answerInlineQuery, answerWebAppQuery, savePreparedInlineMessage |
| Payments | sendInvoice, createInvoiceLink, answerShippingQuery, answerPreCheckoutQuery |
| Stickers and newer features | getStickerSet, createNewStickerSet, addStickerToSet, reactions, gifts, stars, boosts, and other supported Bot API areas |
Maintainer note
Telegram Bot API behavior, client rendering, platform policies, and third-party integrations can change independently of this package. Review the changelog, generated declarations, tests, Telegram documentation, and your own deployment before relying on a feature in production.
The package is provided as a transparent developer tool. Inspect it, test it in an isolated environment, protect your credentials, and use it only for lawful, authorized, and responsible automation.
