npm.io
1.2.1 • Published 4 years ago

telegraf-media-group

Licence
MIT
Version
1.2.1
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
9

telegraf-media-group

Handle media groups (aka albums) easily with telegraf!

Usage

Telegraf v3

const Telegraf = require('telegraf')
const mediaGroup = require('telegraf-media-group')

const bot = new Telegraf(process.env.BOT_TOKEN)

bot.use(mediaGroup())

bot.on('media_group', (ctx) => {
  // ctx.mediaGroup — an array of album messages (including the last one)
  for (const message of ctx.mediaGroup) {
    console.log(message)
  }
  return ctx.reply(`total: ${ctx.mediaGroup.length}`)
})
Telegraf v4
const { Telegraf } = require('telegraf')
const mediaGroup = require('telegraf-media-group')

const bot = new Telegraf(process.env.BOT_TOKEN)

bot.use(mediaGroup())

bot.on('media_group', (ctx) => {
  // ctx.mediaGroup — an array of album messages (including the last one)
  for (const message of ctx.mediaGroup) {
    console.log(message)
  }
  return ctx.reply(`total: ${ctx.mediaGroup.length}`)
})