-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
48 lines (36 loc) · 1.25 KB
/
handler.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
const Telegraf = require('telegraf')
const khayyam = require('./khayyam.js')
const messages = require('./messages.js')
exports.saaghia = (event, context, callback) => {
console.log(JSON.stringify(event))
if (event.source == 'aws.events') {
console.log('I feel warm.')
callback(null, 'I feel warm.')
}
if (!process.env.SAAGHIBOT_TOKEN) {
console.error('SAAGHIBOT_TOKEN environment variable not defined.')
callback(null, {
statusCode: 500,
body: JSON.stringify({
message: 'SAAGHIBOT_TOKEN environment variable not defined.',
})
})
}
const bot = new Telegraf(process.env.SAAGHIBOT_TOKEN)
bot.start((ctx) => ctx.replyWithMarkdown(messages.help))
bot.help((ctx) => ctx.replyWithMarkdown(messages.help))
bot.on('sticker', (ctx) => ctx.reply('👍'))
bot.on('message', (ctx) => {
ctx.replyWithMarkdown(khayyam.findOne(ctx.message.text) || messages.nihility)
})
bot.on('inline_query', (ctx) => {
ctx.answerInlineQuery(khayyam.process_query(ctx.inlineQuery.query).slice(0, 50))
})
bot.handleUpdate(JSON.parse(event.body))
callback(null, {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
})
})
}