yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.45k stars 1.53k forks source link

[Error] 400 Bad Request: invalid sticker emojis #1236

Open longlin10086 opened 3 days ago

longlin10086 commented 3 days ago

Bug Report

"node-telegram-bot-api": "^0.66.0",

Expected Behavior

When I used createNewStickerSet I got an error.(The error message is at the buttom)

await bot.createNewStickerSet(
  userId,
  stickerSetName,
  `User ${userId}'s stickers`,
  uploadedPhoto.file_id,
  "😊"
);

This is the API right now:

  /**
   * Use this method to create new sticker set owned by a user.
   *
   * The bot will be able to edit the created sticker set.
   *
   * You must use exactly one of the fields *png_sticker*, *tgs_sticker*, or *webm_sticker*
   *
   * @param  {Number} userId User identifier of created sticker set owner
   * @param  {String} name Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g.,   *"animals"*). Can contain only english letters, digits and underscores.
   *  Must begin with a letter, can't contain consecutive underscores and must end in `"_by_<bot_username>"`. `<bot_username>` is case insensitive. 1-64 characters.
   * @param  {String} title Sticker set title, 1-64 characters
   * @param  {String|stream.Stream|Buffer} pngSticker Png image with the sticker, must be up to 512 kilobytes in size,
   *  dimensions must not exceed 512px, and either width or height must be exactly 512px.
   * @param  {String} emojis One or more emoji corresponding to the sticker
   * @param  {Object} [options] Additional Telegram query options
   * @param  {Object} [fileOptions] Optional file related meta-data
   * @return {Promise}  True on success
   * @see https://core.telegram.org/bots/api#createnewstickerset
   */
  createNewStickerSet(userId, name, title, pngSticker, emojis, options = {}, fileOptions = {}) {
    const opts = {
      qs: options,
    };
    opts.qs.user_id = userId;
    opts.qs.name = name;
    opts.qs.title = title;
    opts.qs.emojis = emojis;
    opts.qs.mask_position = stringify(options.mask_position);
    try {
      const sendData = this._formatSendData('png_sticker', pngSticker, fileOptions);
      opts.formData = sendData[0];
      opts.qs.png_sticker = sendData[1];
    } catch (ex) {
      return Promise.reject(ex);
    }
    return this._request('createNewStickerSet', opts);
  }

But I found that in the newest telegram API it seems like we don't need to send the key emoji : https://core.telegram.org/bots/api#createnewstickerset

2024-11-11 21 06 45

The cURL command can be like:

curl --location 'https://api.telegram.org/botxxxx:XXXXXXXXX/createNewStickerSet' \
--form 'user_id=""' \
--form 'name=""' \
--form 'title=""' \
--form 'stickers=""' \
--form 'sticker_format=""'

Maybe the api needs to be updated, or there is other way to get rid of this error.

Actual Behavior

Error processing sticker 1:  5 |    * @private
 6 |    * @param  {String} code Error code
 7 |    * @param  {String} message Error message
 8 |    */
 9 |   constructor(code, message) {
10 |     super(`${code}: ${message}`);
         ^
error: ETELEGRAM: 400 Bad Request: invalid sticker emojis
 code: "ETELEGRAM"
longlin10086 commented 1 day ago

Well, I have solved this problem. It doesn't happen on this function, but the other in my code. However, I will keep this issue open for the confused API difference.