Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@dietime/telegraf-media-group
Advanced tools
All that you want to easily process media groups in telegraf.js
All that you want to easily process media groups in telegraf.js
When writing a telegram bot using telegraf.js, you may want to process a group of media sent by a user.
This package provides all that you want to solve this problem:
$ npm i @dietime/telegraf-media-group
MediaGroup
middlewareYou need to attach MediaGroup
middleware to your bot so that when you receive media group messages, these messages will be accumulated.
import { MediaGroup } from '@dietime/telegraf-media-group'
bot.use(new MediaGroup({ timeout: 1000 }).middleware())
The timeout
option controls the time the middleware will wait for the next media group message. If no message is received within this timeout, middleware sends a message with accumulated media group messages for processing.
To process a media group that contains both photos and videos, use the media_group()
filter and wrap the context in the MediaGroupContext<T>
type for better typing.
import { media_group, type MediaGroupContext } from '@dietime/telegraf-media-group'
bot.on(media_group(), (ctx: MediaGroupContext<Context>) => {
for (const media of ctx.update.media_group) {
if ('photo' in media) {
console.log('Photo:', media.photo)
}
if ('video' in media) {
console.log('Video:', media.video)
}
}
})
To process a media group that contains only photos, use photo_media_group()
filter and wrap the context in PhotoMediaGroupContext<T>
type for better typing.
import { photo_media_group, type PhotoMediaGroupContext } from '@dietime/telegraf-media-group'
bot.on(photo_media_group(), (ctx: PhotoMediaGroupContext<Context>) => {
for (const media of ctx.update.media_group) {
console.log('Photo:', media.photo)
}
})
To process a media group that contains only videos, use video_media_group()
filter and wrap the context in VideoMediaGroupContext<T>
type for better typing.
import { video_media_group, type VideoMediaGroupContext } from '@dietime/telegraf-media-group'
bot.on(video_media_group(), (ctx: VideoMediaGroupContext<Context>) => {
for (const media of ctx.update.media_group) {
console.log('Video:', media.video)
}
})
FAQs
All that you want to easily process media groups in telegraf.js
We found that @dietime/telegraf-media-group demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.