forked from cloudflare/worker-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.ts
More file actions
23 lines (20 loc) · 664 Bytes
/
Copy pathhandler.ts
File metadata and controls
23 lines (20 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import Telegraf from 'telegraf'
export async function handleRequest(request: Request): Promise<Response> {
const bot = new Telegraf(TG_BOT_API_TOKEN)
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply('👍'))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
const result = { success: true }
try {
await bot.handleUpdate(await request.json())
} catch (error) {
result.success = false
} finally {
const init = {
headers: { 'content-type': 'application/json' },
}
const body = JSON.stringify(result)
return new Response(body, init)
}
}