-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleBot.js
More file actions
130 lines (112 loc) · 3.33 KB
/
sampleBot.js
File metadata and controls
130 lines (112 loc) · 3.33 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* This is a sample Telegram bot.
*
* # RUN THIS BOT:
*
* 1. Run from command line:
*
* BOT_TOKEN=<YOUR_BOT_TOKEN> node sampleBot.js
*
*
* # This sample is modified from https://github.com/telegraf/telegraf/tree/develop/examples
*
*/
const Telegraf = require('telegraf')
const { Extra, Markup } = require('telegraf')
const app = new Telegraf(process.env.BOT_TOKEN)
app.command('start', (ctx) => {
console.log('start', ctx.from)
ctx.reply('Welcome!')
})
app.command('keyboard', (ctx) => {
return ctx.reply('Custom buttons keyboard', Markup
.keyboard([
['🔍 Search', '😎 Popular'], // Row1 with 2 button
['☸ Setting', '📞 Feedback'], // Row2 with 2 button
['📢 Ads', '⭐️ Rate us', '👥 Share'] // Row3 with 3 button
])
.oneTime()
.resize()
.extra()
)
})
app.command('photo', (ctx) => {
ctx.replyWithPhoto({url:'http://lorempixel.com/400/200/cats/',filename: 'kitten.jpg'})
})
app.command('location', (ctx) => {
ctx.replyWithLocation('25.0', '121.5')
})
app.command('contact', (ctx) => {
console.log(ctx)
ctx.replyWithContact('0900000000','Snoopy')
})
app.command('video', (ctx) => {
ctx.replyWithVideo({source : './video/sampleVideo.mp4'})
})
app.hears('hi', (ctx) => ctx.reply('Hey there!'))
app.on('text', (ctx) => {
ctx.reply(ctx.update.message.text)
})
app.on('sticker', (ctx) => {
ctx.replyWithSticker(ctx.update.message.sticker.file_id)
})
app.on('location', (ctx) => {
ctx.reply('I\'m just behind you!!')
ctx.replyWithLocation(ctx.update.message.location.latitude, ctx.update.message.location.longitude)
})
app.on('photo', (ctx) => {
ctx.reply('Nice photo!')
})
app.on('inline_query', (ctx) => {
const query = ctx.inlineQuery.query || ''
const results = countries
.filter((country) => country.name.toLowerCase().indexOf(query.toLowerCase()) !== -1)
.map((country) => {
return {
id: country.code,
title: country.name,
type: 'article',
input_message_content: {
message_text: `${country.name} code: *${country.code}*`,
parse_mode: 'Markdown'
}
}
})
return ctx.answerInlineQuery(results)
})
app.startPolling()
const countries = [
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
{name: 'Antigua and Barbuda', code: 'AG'},
{name: 'Argentina', code: 'AR'},
{name: 'Armenia', code: 'AM'},
{name: 'Aruba', code: 'AW'},
{name: 'Australia', code: 'AU'},
{name: 'Austria', code: 'AT'},
{name: 'Azerbaijan', code: 'AZ'},
{name: 'Bahamas', code: 'BS'},
{name: 'Bahrain', code: 'BH'},
{name: 'Bangladesh', code: 'BD'},
{name: 'Barbados', code: 'BB'},
{name: 'Belarus', code: 'BY'},
{name: 'Belgium', code: 'BE'},
{name: 'Belize', code: 'BZ'},
{name: 'Benin', code: 'BJ'},
{name: 'Bermuda', code: 'BM'},
{name: 'Bhutan', code: 'BT'},
{name: 'Bolivia', code: 'BO'},
{name: 'Bosnia and Herzegovina', code: 'BA'},
{name: 'Botswana', code: 'BW'},
{name: 'Bouvet Island', code: 'BV'},
{name: 'Brazil', code: 'BR'},
{name: 'British Indian Ocean Territory', code: 'IO'},
{name: 'Brunei Darussalam', code: 'BN'}
]