Skip to content

Support Bot API 10.3 with upstream unified declarations and contract tests - #14

Open
Leask wants to merge 12 commits into
telegraf:masterfrom
Leask:bot-api-9.6-sync
Open

Leask wants to merge 12 commits into
telegraf:masterfrom
Leask:bot-api-9.6-sync

Conversation

@Leask

@Leask Leask commented May 5, 2026 •

Copy link
Copy Markdown

Summary

Updates the official declarations from Bot API 9.2 to Bot API 10.3, the latest specification published at https://core.telegram.org/bots/api as of October 4, 2026. This also resolves the conflict with the current master branch while preserving its unified, documentation-ordered bot-api.ts, compatibility re-exports, direct tsc declaration build, Bun lockfile, and Oxlint/Oxfmt tooling.

The update covers API 9.3 through 10.3: managed bots, rich messages and draft streaming, guest and join-request queries, ephemeral messages, live photos, poll media, communities, subscriptions, reaction moderation, and generation-stopped updates. It incorporates the reviewed contracts from telegraf-hardened/types#6 and #7, with attribution, and preserves the fixes recently merged upstream.

Important contracts include numeric ephemeral IDs and their required receiver; guest replies as InlineQueryResult; live-photo still/video fields; recursive rich-button text constraints; exclusive optional poll media; and thinking blocks restricted to draft input while allowing completed rich messages to be reused as drafts. File upload types remain generic. User includes the documented optional getMe fields, and literal-true response fields are modeled accordingly.

Cross-review follow-up: adopts @MKRhere's no-upload generic for inline rich-message edits from #17, and applies the documented restriction to sendRichMessageDraft as well. Regression contracts cover direct calls, Opts, nested blocks, explicit media, existing file IDs, ordinary chat/ephemeral uploads, plain styled reply buttons, and rich ephemeral edits through Opts. Ordinary strings are not branded file IDs, so these types do not distinguish all prohibited URL strings from valid file IDs.

Validation

  • npm test: four test groups pass, including positive/negative examples against both source files and isolated generated declarations.
  • An independent official-documentation snapshot checks all 185 method names, every method parameter's name and optionality, and the fields and primitive types of 399 object definitions. The remaining InputFile definition is represented by the consumer's generic F.
  • bun install --frozen-lockfile --ignore-scripts, npm run check, npm run lint, and npm run fmt:check pass.
  • npm pack --dry-run: declaration-only package with the expected public entry points.
  • Fork CI passes the contracts at 88aa916 on Node 20, 22, 24, and 26 with read-only repository permissions.

The snapshot is dated and checked in for deterministic offline validation. These checks do not claim to enforce every prose-only API constraint or replace live Telegram integration testing.

Integration

The package version is prepared as 10.3.0; no package has been published by this PR. Companion telegraf/telegraf#2092 now uses these exact declarations and the latest upstream runtime changes, and preserves the upload restrictions through its Telegram/Context helpers. Its fork CI passes all 290 runtime/type tests and lint on Node 22.20, 24.12, and 26. Its temporary HTTPS dependency pin must be replaced by the official registry release before publication.

MadL0rd and others added 7 commits May 5, 2026 12:20
- add has_topics_enabled in getMe user
- add sendMessageDraft method
- update Message topic field wording
- widen message_thread_id docs for send methods
- update sendChatAction topic wording
- mention private chats in topic admin methods
- add is_name_implicit topic fields
- add getUserGifts and getChatGifts
- replace UniqueGiftInfo resale fields
- split getBusinessAccountGifts limited filters
- add gifted_upgrade origin value
- add offer origin value
- add message.gift_upgrade_sent service type
- add UniqueGift.gift_id
- add UniqueGift.is_from_blockchain
- add getBusinessAccountGifts blockchain filter
- add personal gift quota fields
- add premium markers for gifts
- add is_upgrade_separate fields
- add UniqueGiftColors type
- add Gift.has_colors
- add UniqueGift.colors
- add GiftBackground and Gift.background
- add Gift.unique_gift_variant_count
- add unique_gift_number fields
- add AcceptedGiftTypes.gifts_from_channels
- add repostStory method
- add UserRating and chat rating field
- add ChatFullInfo.paid_message_star_count
- add message_effect_id to forward/copy
- add ChatFullInfo.unique_gift_colors
- add ChecklistTask.completed_by_chat
- update createForumTopic private chat support
- add allows_users_to_create_topics
- add icon_custom_emoji_id to buttons
- add button style field
- add ChatOwnerLeft message type
- add ChatOwnerChanged message type
- add bot profile photo methods
- add VideoQuality and video qualities
- add ChatFullInfo.first_profile_audio
- add UserProfileAudios and getter
- add UniqueGiftModel.rarity
- add UniqueGift.is_burned
@Leask
Leask marked this pull request as ready for review May 5, 2026 17:17
Copilot AI review requested due to automatic review settings May 5, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates @telegraf/types to align with Telegram Bot API 9.6 by adding/adjusting API method typings and the corresponding object/update/message type definitions.

Changes:

  • Add Bot API 9.3–9.6 updates, including managed-bot updates and prepared keyboard button support.
  • Extend message/model types (e.g., poll option persistence, date_time entities, video qualities, tags, gift fields).
  • Bump published package version and update the README Bot API badge.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
update.ts Adds managed_bot update variant to the Update union.
methods.ts Adds/updates Bot API methods and parameter docs for 9.6 (incl. managed bot token methods, profile audios, prepared keyboard button saving, etc.).
message.ts Extends message/service-message unions and message-related objects/entities for 9.6.
markup.ts Adds managed-bot keyboard request button support and prepared keyboard button type.
manage.ts Adds/updates management and chat/user-related types for 9.6 (managed bots, tags, ratings, gifts, etc.).
README.md Updates the Bot API version badge to v9.6.
package.json Bumps package version to 9.6.0.
package-lock.json Aligns lockfile package version to 9.6.0.
.github/workflows/release.yml Reformats workflow steps (not mentioned in PR summary).
Comments suppressed due to low confidence (1)

message.ts:28

  • The JSDoc for from looks detached: there is a “Sender of the message…” comment that isn’t immediately attached to any field, and from ends up undocumented. Consider moving that comment to the from property.
    /** Unique identifier of a message thread or forum topic to which the message belongs; for supergroups and private chats only */
    message_thread_id?: number;
    /** Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */
    /** Information about the direct messages chat topic that contains the message */
    direct_messages_topic?: DirectMessagesTopic;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread manage.ts Outdated
pinned_message?: Message;
/** Information about types of gifts that are accepted by the chat or by the corresponding user for private chats */
accepted_gift_types?: AcceptedGiftTypes[];
/** The number of Telegram Stars a general user have to pay to send a message to the chat */
Comment thread manage.ts Outdated
permissions?: ChatPermissions;
/** Information about types of gifts that are accepted by the chat or by the corresponding user for private chats */
accepted_gift_types?: AcceptedGiftTypes[];
/** The number of Telegram Stars a general user have to pay to send a message to the chat */
Comment thread manage.ts Outdated
permissions?: ChatPermissions;
/** Information about types of gifts that are accepted by the chat or by the corresponding user for private chats */
accepted_gift_types?: AcceptedGiftTypes[];
/** The number of Telegram Stars a general user have to pay to send a message to the chat */
Comment thread manage.ts Outdated
pinned_message?: Message;
/** Information about types of gifts that are accepted by the chat or by the corresponding user for private chats */
accepted_gift_types?: AcceptedGiftTypes[];
/** The number of Telegram Stars a general user have to pay to send a message to the chat */
Comment thread methods.ts Outdated
Comment on lines 231 to 236
@@ -227,7 +232,7 @@ export type ApiMethods<F> = {
copyMessage(args: {
/** Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) */
chat_id: number | string;
/** Unique identifier for the target message thread (topic) of the forum; for forum supergroups only */
/** Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only */
message_thread_id?: number;
Comment thread methods.ts Outdated
Comment on lines 273 to 278
@@ -267,7 +274,7 @@ export type ApiMethods<F> = {
copyMessages(args: {
/** Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) */
chat_id: number | string;
/** Unique identifier for the target message thread (topic) of the forum; for forum supergroups only */
/** Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only */
message_thread_id?: number;
Comment thread .github/workflows/release.yml Outdated
Comment on lines +13 to +21
- uses: actions/checkout@v3
- run: npm ci --ignore-scripts
- run: npm run prepare
- name: Publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
npm publish --ignore-scripts --access=public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Comment thread message.ts Outdated
Comment on lines +719 to +725
export interface DateTime extends Abstract {
type: "date_time";
/** Unix time associated with the entity */
unix_time?: number;
/** String that defines the formatting of the date and time */
date_time_format?: string;
}
Preserve the unified documentation-ordered bot-api.ts layout and tsc/Bun tooling. Port reviewed 10.3 contracts and verify all 185 methods and 399 objects against the official snapshot, plus source and declaration compiler fixtures.

Co-authored-by: siakinnik <siakin.nikita@siakinnik.com>
@Leask Leask changed the title Support Bot API 9.6 types Support Bot API 10.3 with upstream unified declarations and contract tests Oct 4, 2026
@Leask

Leask commented Oct 4, 2026

Copy link
Copy Markdown
Author

Updated this PR to Bot API 10.3 in 30c5b02, merged current master, and resolved the conflicts without rewriting the existing history.

The implementation follows the new upstream direction: one documentation-ordered bot-api.ts, compatibility re-exports, direct tsc declaration output, and the Bun/Oxlint/Oxfmt toolchain. The reviewed 10.3 contracts from the hardened fork are incorporated with attribution, while preserving upstream fixes and both editMessageText overloads.

An independent Telegram documentation snapshot checks all 185 methods and 399 object definitions, including parameter/field names, optionality and primitive types. Positive/negative examples compile against both source and isolated generated declarations. These checks intentionally do not claim to validate every prose-only Telegram constraint.

Fork CI passes on Node 20, 22, 24 and 26. Tests, type checking, lint, formatting, frozen install and declaration-only package dry-run all pass.

The runtime companion telegraf/telegraf#2092 now uses this exact commit and covers all 185 methods; its Node 22.20/24.12/26 CI passes as well. The temporary HTTPS pin remains a release gate until the official 10.3 package is published. The version is prepared as 10.3.0, but no npm publication was performed.

@Leask Leask mentioned this pull request Oct 4, 2026
@Leask

Leask commented Oct 4, 2026

Copy link
Copy Markdown
Author

Cross-review of #13 and #17 identified two additional constraints to track on this PR at 30c5b02; the existing passing tests do not cover them:

I reproduced both with TypeScript 6.0.3 strict probes using ApiMethods<{ upload: true }> and a photo block whose media is { upload: true }. Both compile here, although they should be rejected in those contexts. Follow-up tests should reject these cases, accept existing file IDs, preserve ordinary uploads in sendRichMessage and non-inline edits, and cover the exported Opts surface as well as direct calls.

No fix for these two findings is claimed in this review pass. I have highlighted the corresponding benefit of #17 in its review rather than recommend replacing it wholesale with #14. This does not change the verified method/field coverage or CI results, but it does qualify the remaining payload-constraint work before release.

@Leask Leask mentioned this pull request Oct 4, 2026
Adopt the inline InputRichMessage<never> constraint highlighted by MKRhere in telegraf#17 and apply the documented upload restriction to sendRichMessageDraft. Add source and declaration regression contracts, including plain styled reply buttons and ephemeral rich Opts.
Leask added a commit to Leask/telegraf that referenced this pull request Oct 4, 2026
Pin the tested types follow-up from telegraf/types#14, incorporating the inline restriction from telegraf#17. Keep file uploads for non-inline and ephemeral edits, narrow Context targets, reject uploads in drafts and inline edits, and cover the public compiler contracts without changing request serialization.
@Leask

Leask commented Oct 4, 2026

Copy link
Copy Markdown
Author

Follow-up to the cross-PR comparison: both upload gaps are fixed in 88aa916.

  • Adopted the inline no-upload constraint from @MKRhere's feat/api 10.3 #17, with attribution.
  • Applied the same API restriction to rich-message drafts.
  • Added source/generated-declaration contracts for nested and explicit-media uploads, file-ID success cases, Opts, ordinary chat/ephemeral uploads, and the plain styled reply-button case highlighted while reviewing feat: API 9.3 & 9.4 #13/feat/api 10.3 #17.

Types CI passes on Node 20, 22, 24, and 26. The matching Telegraf commit in telegraf/telegraf#2092 pins this exact types commit and propagates the constraints into Telegram/Context. It passes all 290 local tests and lint, including the previously failing upload regression.

Scope remains compile-time upload-object validation: plain strings are not branded file IDs, so URL-string validity still needs to follow Telegram's documentation. No npm publication or upstream merge was performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants