forked from Txio-labs/txio-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
27 lines (23 loc) · 945 Bytes
/
Copy pathindex.ts
File metadata and controls
27 lines (23 loc) · 945 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
import express from "express";
import { createNodeMiddleware } from "@octokit/webhooks";
import { webhookCallback } from "grammy";
import { config } from "./config.js";
import { webhooks } from "./github/webhooks.js";
import { bot } from "./telegram/client.js";
const app = express();
app.get("/healthz", (_req, res) => {
res.status(200).send("ok");
});
app.use(createNodeMiddleware(webhooks, { path: config.githubWebhookPath }));
app.use(config.telegramWebhookPath, express.json());
app.use(config.telegramWebhookPath, webhookCallback(bot, "express"));
app.listen(config.port, async () => {
console.log(`txio-telegram-bot listening on :${config.port}`);
const webhookUrl = `${config.publicUrl}${config.telegramWebhookPath}`;
try {
await bot.api.setWebhook(webhookUrl);
console.log(`Telegram webhook registered at ${webhookUrl}`);
} catch (error) {
console.error("Failed to register Telegram webhook:", error);
}
});