{"id":26655623,"url":"https://github.com/gramiojs/media-group","last_synced_at":"2025-04-11T09:38:00.309Z","repository":{"id":239973269,"uuid":"801176238","full_name":"gramiojs/media-group","owner":"gramiojs","description":"Media group collector plugin for GramIO","archived":false,"fork":false,"pushed_at":"2024-11-24T18:47:54.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T06:36:35.065Z","etag":null,"topics":["attachments","gramio-plugin","media-group","telegram-bot","telegram-bot-api"],"latest_commit_sha":null,"homepage":"https://gramio.dev/plugins/official/media-group","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gramiojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-15T18:31:58.000Z","updated_at":"2024-12-02T10:39:57.000Z","dependencies_parsed_at":"2024-11-24T23:45:07.686Z","dependency_job_id":"f4c5e63e-abba-4ce5-b84d-4736c7da35d7","html_url":"https://github.com/gramiojs/media-group","commit_stats":null,"previous_names":["gramiojs/media-group"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fmedia-group","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fmedia-group/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fmedia-group/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fmedia-group/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gramiojs","download_url":"https://codeload.github.com/gramiojs/media-group/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248368745,"owners_count":21092446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attachments","gramio-plugin","media-group","telegram-bot","telegram-bot-api"],"created_at":"2025-03-25T06:36:43.745Z","updated_at":"2025-04-11T09:38:00.282Z","avatar_url":"https://github.com/gramiojs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Media group plugin\n\n[![npm](https://img.shields.io/npm/v/@gramio/media-group?logo=npm\u0026style=flat\u0026labelColor=000\u0026color=3b82f6)](https://www.npmjs.org/package/@gramio/media-group)\n[![JSR](https://jsr.io/badges/@gramio/media-group)](https://jsr.io/@gramio/media-group)\n[![JSR Score](https://jsr.io/badges/@gramio/media-group/score)](https://jsr.io/@gramio/media-group)\n\nThis plugin collects `mediaGroup` from messages (**1** attachment = **1** message) using a **delay** if `mediaGroupId` is in the **MessageContext**, pass only **first** message further down the middleware chain with the `mediaGroup` key, which contains an **array** of messages of this **mediaGroup** (it also contains the **first** message). The delay after 10 attachments (max messages in 1 mediaGroup) is automatically skipped.\n\n```ts\nimport { Bot } from \"gramio\";\nimport { mediaGroup } from \"@gramio/media-group\";\n\nconst bot = new Bot(process.env.TOKEN as string)\n    .extend(mediaGroup())\n    .on(\"message\", async (context) =\u003e {\n        if (!context.mediaGroup) return;\n\n        return context.send(\n            `Caption from the first message - ${context.caption}. MediaGroup contains ${context.mediaGroup.length} attachments`\n        );\n    })\n    .onStart(({ info }) =\u003e console.log(`✨ Bot ${info.username} was started!`));\n\nbot.start();\n```\n\n### Setup\n\nYou can change the duration of the delay in milliseconds by simply passing it like this:\n\n```typescript\nconst bot = new Bot(process.env.TOKEN!)\n    .extend(mediaGroup(1000)) // wait 1 second for message with mediaGroupId (refreshed after new message with it)\n    .on(\"message\", async (context) =\u003e {\n        if (!context.mediaGroup) return;\n\n        return context.send(\n            `Caption from the first message - ${context.caption}. MediaGroup contains ${context.mediaGroup.length} attachments`\n        );\n    })\n    .onStart(({ info }) =\u003e console.log(`✨ Bot ${info.username} was started!`));\n\nbot.start();\n```\n\nBy default it `150 ms`.\n\n## TODO\n\n-   Currently, it stateful, so it does not work with horizontal scaling. Fixes would be hard (for example serialize/deserialize context in redis and etc) and maybe slow in perfomance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgramiojs%2Fmedia-group","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgramiojs%2Fmedia-group","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgramiojs%2Fmedia-group/lists"}