Skip to content

fix: update createNewStickerSet/addStickerToSet to current Bot API (#1236)#1314

Open
yagop wants to merge 1 commit into
masterfrom
fix/1236-sticker-set-api
Open

fix: update createNewStickerSet/addStickerToSet to current Bot API (#1236)#1314
yagop wants to merge 1 commit into
masterfrom
fix/1236-sticker-set-api

Conversation

@yagop

@yagop yagop commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Problem

createNewStickerSet and addStickerToSet were hand-ported from the pre-6.6 Bot API and still send the long-removed png_sticker / emojis fields. Telegram rejects that with 400 Bad Request: invalid sticker emojis, so both methods are unusable on the current API.

Refs #1236

Fix

Rewrite both to the current API, using the single options-object shape (matches the generated CreateNewStickerSetParams / AddStickerToSetParams):

bot.createNewStickerSet({
  user_id, name, title, sticker_type: 'regular',
  stickers: [{ sticker: './a.png', format: 'static', emoji_list: ['😀'] }],
});

bot.addStickerToSet({
  user_id, name,
  sticker: { sticker: './b.webp', format: 'static', emoji_list: ['🎈'] },
});
  • Each sticker's sticker accepts a file (Buffer / stream / local path) which is uploaded as an attach://sticker<i> multipart part, or a file_id / URL string which passes through unchanged.
  • New private helper _buildStickerItems() mirrors the existing _buildMediaItems() (sendMediaGroup / sendPaidMedia).
  • New internal input type InputStickerInput (the docs-faithful InputSticker with sticker widened to InputFile), following the same unexported pattern as SendMediaGroupMedia.

Breaking change

Both public method signatures change from the old positional form (createNewStickerSet(userId, name, title, pngSticker, emojis, ...)) to a single options object. Documented under Breaking in the CHANGELOG. Under semver this warrants a major bump.

Tests / verification

  • npm run typecheck clean; npm run build clean (declarations reference the new type correctly).
  • Unit (test/unit/telegram.test.ts): 45/45 pass, incl. 3 new (attach:// wiring, file_id passthrough -> urlencoded, single-object serialization).
  • Live API (the real proof, since the bug was a Telegram 400):
    • full sticker lifecycle create -> add -> title -> thumbnail -> position -> emoji -> keywords -> replace -> delete = 9/9 pass
    • mask-set create = 1/1; custom_emoji-set create = 1/1

Notes / follow-up (out of scope)

replaceStickerInSet still routes through _form and does not upload a file-bearing InputSticker.sticker via attach:// (only file_id / URL works there). Same root cause; could be fixed with the same _buildStickerItems helper in a follow-up.

🤖 Generated with Claude Code

Both methods still sent the pre-6.6 `png_sticker`/`emojis` fields, which
Telegram rejects with `400 Bad Request: invalid sticker emojis`. Rewrite them
to the current `stickers[]` / `InputSticker` API as a single options object:
each sticker's file (Buffer / stream / local path) is uploaded via an
`attach://` part, while a file_id / URL string passes through unchanged. Adds a
`_buildStickerItems` helper mirroring `_buildMediaItems`.

Breaking change to both public method signatures.

Refs #1236

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant