Socket
Socket
Sign inDemoInstall

@grammyjs/files

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grammyjs/files


Version published
Maintainers
1
Created

Readme

Source

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, Context } from "grammy";
import { 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').

Keywords

FAQs

Last updated on 16 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc