-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfly.ts
28 lines (25 loc) · 865 Bytes
/
fly.ts
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
// A special entrypoint for deploying the bot to Fly.io
// See also: https://grammy.dev/hosting/fly.html#setting-the-webhook-url
import * as log from "std/log/mod.ts";
import { serve } from "std/http/server.ts";
import { webhookCallback } from "grammy";
import { bot, setupLogger } from "./bot.ts";
const handleUpdate = webhookCallback(bot, "std/http");
const port = parseInt(Deno.env.get("PORT") ?? "8000");
const webhookPath = Deno.env.get("WEBHOOK_PATH") ?? "/";
if (!webhookPath.startsWith("/")) {
console.error("error: WEBHOOK_PATH must start with a slash");
Deno.exit(1);
}
await setupLogger();
serve(async (req) => {
const url = new URL(req.url);
if (req.method === "POST" && url.pathname === webhookPath) {
try {
return await handleUpdate(req);
} catch (err) {
log.error(err);
}
}
return new Response();
}, { port });