-
Notifications
You must be signed in to change notification settings - Fork 12
/
telegraf.js
52 lines (43 loc) · 1.23 KB
/
telegraf.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
const { Telegraf } = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => {
var defaultButton = {
text: 'default',
web_app: {
url: 'https://expented.github.io/tgdtp/'
}
}
var hideTimeButton = {
text: 'only date',
web_app: {
url: 'https://expented.github.io/tgdtp/?hide=time'
}
}
var betweenButton = {
text: 'May 1 to May 20',
web_app: {
url: 'https://expented.github.io/tgdtp/?min=2022-05-01&max=2022-05-20'
}
}
var print = 'choose date and time'
ctx.reply(print, {
reply_markup: JSON.stringify({
resize_keyboard: true,
keyboard: [
[ defaultButton, hideTimeButton ],
[ betweenButton ]
]
})
})
})
bot.on('web_app_data', (ctx) => {
var [ timespamp, timezoneOffset ] = ctx.message.web_app_data.data.split('_')
timespamp = parseInt(timespamp)
var clientOffset = parseInt(timezoneOffset) * 60 * 1000
var serverOffset = (new Date()).getTimezoneOffset() * 60 * 1000
var offset = serverOffset - clientOffset
var print = 'in user timezone: ' + (new Date(timespamp + offset)).toLocaleString() + '\n'
print += 'in server timezone: ' + (new Date(timespamp)).toLocaleString()
ctx.reply(print)
})
bot.launch()