-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
43 lines (36 loc) · 1.17 KB
/
app.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
const { Telegraf } = require('telegraf')
// const fs = require('fs')
const port = process.env.PORT || 8000
require('dotenv')
const func = require('./func')
const bot = new Telegraf(process.env.BOT_TOKEN )
bot.command('today', async (ctx) => {
if (ctx.update.message.chat.type !== 'private') return ctx.reply('请在私聊中使用该 bot。')
try {
ctx.reply(await func.get(ctx.update.message.chat.id, '您'))
} catch (e) {
ctx.reply('出现了一些错误……')
}
})
bot.on('inline_query', async (ctx) => {
console.log('new inline query...')
console.log(ctx.update.inline_query)
try {
let hl = await func.get(ctx.update.inline_query.from.id, `@${ctx.update.inline_query.from.username}`)
ctx.telegram.answerInlineQuery(ctx.inlineQuery.id, [{
type: 'article',
id: 0,
title: '在此聊天分享我的今日黄历',
input_message_content: {
message_text: hl
}
}], {
cache_time: 1
})
} catch (e) {
}
})
bot.launch()
bot.telegram.setWebhook(`https://${process.env.BOT_DOMAIN}/${process.env.BOT_PATH}`, {})
// Http webhook, for nginx/heroku users.
bot.startWebhook(`/${process.env.BOT_PATH}`, null, port)