File handling simplified in grammY
This plugin allows you to easily download files from Telegram servers.
Check out the official plugin page for further documentation.
Example
import { Bot, type Context } from "grammy";
import { type FileFlavor, hydrateFiles } from "@grammyjs/files";
type MyContext = FileFlavor<Context>;
const bot = new Bot<MyContext>("");
bot.api.config.use(hydrateFiles(bot.token));
bot.on([":video", ":animation"], async (ctx) => {
const file = await ctx.getFile();
const path = await file.download();
console.log("File saved at", path);
});
You can pass a string with a file path to download
if you don't want to create a temporary file.
Just do await file.download('/path/to/file')
.