1.0.3 • Published 3 months ago

@opengram/media-group v1.0.3

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

The media-group plugin lets you handle & copy media-groups (albums) with ease.

CI codecov npm downloads javascript style guide Codacy Badge License: MIT FOSSA Status

Features

  • video, audio, photo, document support
  • Supports sends copy of a media group

Docs

You can find documentation here and examples here and try now here

Installation

NPM

npm i @opengram/media-group

Yarn

yarn add @opengram/media-group

PNPM

pnpm add @opengram/media-group

Quick start

const { Opengram } = require('opengram')
const { MediaGroup } = require('@opengram/media-group')
const bot = new Opengram(process.env.BOT_TOKEN) // <-- put your bot token here (https://t.me/BotFather)
const mediaGroup = new MediaGroup()
bot.use(mediaGroup)

bot.on('media_group', async ctx => {
  // ctx.mediaGroup - array of messages
  for (const message of ctx.mediaGroup) {
    console.log(JSON.stringify(message, null, 2)) // Pretty-print media group messages to console
  }

  await ctx.copyMediaGroup(ctx.chat.id) // Copy media-group to current chat
})

bot.launch()

// Enable graceful stop
process.once('SIGINT', () => bot.stop())
process.once('SIGTERM', () => bot.stop())

Flowchart

flowchart TB
  U("Incoming update") --> M("Upstream middlewares")
  M --> F("Filter by given update types")
  F --> E("Has media group?")
  E -- No --> N("Nothing to do, run next")
  E -- Yes --> STSAV
  MGLEN --> TO("Wait for <code>timeout</code>")
  TO --> TOE("Timeout expired") --> ACTX
  HV --> U

  ACTX("Add media-group messages\nto <code>ctx.mediaGroup</code> and mark as <code>media_group</code>, run next") --> DM("Downstream middlewares")

  HV("Wait for new media")

  STSAV("Save to store") --> MGLEN("Saved messages count = 10?")

  MGLEN -- No --> HV
  MGLEN -- Yes --> ACTX

License

FOSSA Status

1.0.3

3 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago