@grammyjs/files
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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').

Package Sidebar

Install

npm i @grammyjs/files

Weekly Downloads

623

Version

1.1.0

License

MIT

Unpacked Size

14.5 kB

Total Files

11

Last publish

Collaborators

  • knorpelsenf