GIFs are Sent as Videos in Telegram Using grammy Library

122 Views Asked by At

We are developing a Telegram bot using the grammy library and have encountered an issue: when attempting to send GIF files using the sendAnimation method from the grammy documentation, they are being sent and displayed as videos in Telegram, instead of animations.

We have verified that the files are indeed in GIF format. Could anyone suggest a solution or explain why this is happening? Perhaps someone has faced a similar issue.

Link to grammy documentation: Grammy Documentation

async function sendChallengeAnimation(
    ctx: CommandContext<Context>
): Promise<void> {
    const randomAnimationNumber =
        Math.floor(Math.random() * challengeAnimationsCount) + 1
    const video = InputMediaBuilder.video(
        new InputFile(`media/challenge/${randomAnimationNumber}.gif`)
    )
    await ctx.replyWithMediaGroup([video])
}
1

There are 1 best solutions below

0
Noah On

This question gets at functions relying on more of the Telegram rather than the Grammy side and docs can be found here.

In addition to the Photo, Video, MediaGroup and other media types in Telegram, there is also the Animation type. Try substituting MediaGroup for Animation.

If that doesn't work or you need the MediaGroup type, try substituting the video in InputMediaBuilder.video for animation.

Here's some more relevant docs for that last bit.