-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathwebhook.ts
More file actions
32 lines (26 loc) · 857 Bytes
/
webhook.ts
File metadata and controls
32 lines (26 loc) · 857 Bytes
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
import { Bot, webhookCallback } from 'grammy'
import { Agent } from 'https'
import express from 'express'
// 1. Create a bot
export const bot = new Bot(process.env.BOT_TOKEN as string, {
client: {
// 2. Set the local Bot API URL
apiRoot: 'https://bot-api',
baseFetchConfig: {
compress: true,
agent: new Agent({
keepAlive: true,
// 3. Disable Bot API server certificate verification
rejectUnauthorized: false,
}),
},
},
})
bot.on('message:text', ctx => ctx.reply(ctx.message.text))
const server = express()
server.use(express.json())
// 4. Register a handler for the bot
server.post('/webhook', webhookCallback(bot, 'express'))
server.listen(80)
// 5. Set webhook for handler in Bot API
bot.api.setWebhook('http://bot/webhook')