
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
grammy-media-group
Advanced tools
Middleware and utilities for handling and grouping media messages (photos, videos) in grammY bots, enabling easy processing of media groups.
A lightweight middleware for grammY Telegram bots that collects and groups media messages (like photos and videos) into a single media_group
context property. This makes it easier to handle albums using a simple timeout-based strategy.
mediaGroup
filter for a clean handler with bot.filter()
copyMediaGroup
function to copy media groupsnpm install grammy-media-group
import { Bot } from "grammy";
import { MediaGroupHandler, mediaGroup } from "grammy-media-group";
const bot = new Bot("<BOT_TOKEN>");
const mediaGroupHandler = new MediaGroupHandler(4000); // optional timeout in ms
bot.use(mediaGroupHandler.middleware());
const { Bot } = require("grammy");
const { MediaGroupHandler, mediaGroup } = require("grammy-media-group");
const bot = new Bot("<BOT_TOKEN>");
const mediaGroupHandler = new MediaGroupHandler(4000); // optional timeout in ms
bot.use(mediaGroupHandler.middleware());
This example shows how to use the mediaGroup
filter to detect incoming media groups. When a media group is detected, the handler/middleware processes the grouped media files.
bot.filter(mediaGroup, async (ctx) => {
const media = ctx.media_group;
console.log(media.length); // outputs the media group (album) length
// handle the media group...
});
You can use the copyMediaGroup
utility function to copy a received media group, or copy it directly from the context into a format ready to be sent. This is useful if you want to resend an album with a custom caption or formatting.
// Import if you don't want to copy it directly from the context
import { copyMediaGroup } from "grammy-media-group";
// Or require if you are using CommonJS
const { copyMediaGroup } = require("grammy-media-group");
bot.filter(mediaGroup, async (ctx) => {
// You can pass an optional options object to customize caption
// and formatting
const copiedMediaGroup = copyMediaGroup(ctx.media_group, {
caption: "<b>Here's the album!</b>",
parse_mode: "HTML"
});
// Or you can also copy the media group directly from the context
// and pass the optional options object there as well
const copiedMediaGroup = ctx.copyMediaGroup({
caption: "<b>Here's the album!</b>",
parse_mode: "HTML"
});
// Then you are ready to send the copied media group
await ctx.api.sendMediaGroup(ctx.chat.id, copiedMediaGroup);
});
FAQs
Middleware and utilities for handling and grouping media messages (photos, videos) in grammY bots, enabling easy processing of media groups.
We found that grammy-media-group demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.