grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.04k stars 106 forks source link

Problem with editing files (editMessageMedia and editMessageMediaInline) #591

Closed pepethelis closed 1 month ago

pepethelis commented 1 month ago

Files attached via a link are sent normally, unlike locally uploaded files. The code for uploading files is recreated step by step using grammy classes grammy version: 1.24.0

bot.on("inline_query", async (ctx) => {
  const keyboard = new InlineKeyboard().text("Aw yis", "aab");

  const result = InlineQueryResultBuilder.audio(
    "id",
    "title",
    "https://samplelib.com/lib/preview/mp3/sample-3s.mp3",
    { reply_markup: keyboard }
  );

  await ctx.answerInlineQuery(
    [result], // answer with result list
    { cache_time: 30 * 24 * 3600 } // 30 days in seconds
  );
});

bot.on("chosen_inline_result", (ctx) => {
  const inline_message_id = ctx.chosenInlineResult.inline_message_id;

  const audioPath = path.resolve(__dirname, "./sample.mp3");
  fs.stat(audioPath, (err, stats) => {
    if (err) {
      console.log("File not found", err);
      return;
    }
    console.log("File size", stats.size);
  });

  const streamAudio = fs.createReadStream(audioPath);
  const file = new InputFile(streamAudio);
  const newMedia = InputMediaBuilder.audio(file);

  if (inline_message_id) {
    bot.api
      .editMessageMediaInline(inline_message_id, newMedia)
      .then(() => {
        console.log("Message media edited successfully.");
      })
      .catch((error) => {
        console.log("editMessageMediaInline", error);
      });
  }
});

image

KnorpelSenf commented 1 month ago

Looking into this

KnorpelSenf commented 1 month ago

I currently believe this to be an issue with the Bot API server. I know for a fact that it isn't a problem with grammY. The other possibility is that something is wrong with the way the API is used in this example. I'll get back to you once I know more.

KnorpelSenf commented 1 month ago

We didn't read the specs.

https://core.telegram.org/bots/api#editmessagemedia

When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL.