1.1.0 • Published 2 months ago

@grammyjs/files v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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";

// Transformative API flavor
type MyContext = FileFlavor<Context>;

// Create bot
const bot = new Bot<MyContext>("");

// Install plugin
bot.api.config.use(hydrateFiles(bot.token));

// Download videos and GIFs to temporary files
bot.on([":video", ":animation"], async (ctx) => {
    // Prepare file for download
    const file = await ctx.getFile();
    // Download file to temporary location on your disk
    const path = await file.download();
    // Print file path
    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').