forked from telegraf/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media-bot.js
69 lines (61 loc) · 2.13 KB
/
media-bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const Telegraf = require('telegraf')
const Extra = require('telegraf/extra')
const fs = require('fs')
const AnimationUrl1 = 'https://media.giphy.com/media/ya4eevXU490Iw/giphy.gif'
const AnimationUrl2 = 'https://media.giphy.com/media/LrmU6jXIjwziE/giphy.gif'
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.command('local', (ctx) => ctx.replyWithPhoto({ source: '/cats/cat1.jpeg' }))
bot.command('stream', (ctx) => ctx.replyWithPhoto({ source: fs.createReadStream('/cats/cat2.jpeg') }))
bot.command('buffer', (ctx) => ctx.replyWithPhoto({ source: fs.readFileSync('/cats/cat3.jpeg') }))
bot.command('pipe', (ctx) => ctx.replyWithPhoto({ url: 'https://picsum.photos/200/300/?random' }))
bot.command('url', (ctx) => ctx.replyWithPhoto('https://picsum.photos/200/300/?random'))
bot.command('animation', (ctx) => ctx.replyWithAnimation(AnimationUrl1))
bot.command('pipe_animation', (ctx) => ctx.replyWithAnimation({ url: AnimationUrl1 }))
bot.command('caption', (ctx) => ctx.replyWithPhoto(
'https://picsum.photos/200/300/?random',
Extra.caption('Caption *text*').markdown()
))
bot.command('album', (ctx) => {
ctx.replyWithMediaGroup([
{
media: 'AgADBAADXME4GxQXZAc6zcjjVhXkE9FAuxkABAIQ3xv265UJKGYEAAEC',
caption: 'From file_id',
type: 'photo'
},
{
media: 'https://picsum.photos/200/500/',
caption: 'From URL',
type: 'photo'
},
{
media: { url: 'https://picsum.photos/200/300/?random' },
caption: 'Piped from URL',
type: 'photo'
},
{
media: { source: '/cats/cat1.jpeg' },
caption: 'From file',
type: 'photo'
},
{
media: { source: fs.createReadStream('/cats/cat2.jpeg') },
caption: 'From stream',
type: 'photo'
},
{
media: { source: fs.readFileSync('/cats/cat3.jpeg') },
caption: 'From buffer',
type: 'photo'
}
])
})
bot.command('edit_media', (ctx) => ctx.replyWithAnimation(AnimationUrl1, Extra.markup((m) =>
m.inlineKeyboard([
m.callbackButton('Change media', 'swap_media')
])
)))
bot.action('swap_media', (ctx) => ctx.editMessageMedia({
type: 'animation',
media: AnimationUrl2
}))
bot.launch()