Skip to content

Commit 80061da

Browse files
committed
Add readme
1 parent b533111 commit 80061da

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

service/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Webhook for Upptime
2+
3+
This is a webhook for Upptime to notify the Telegram chat.
4+
5+
## Test the webhook
6+
7+
Assuming the [.upptimerc.yml](../.upptimerc.yml) is configured with a site whose name starts with "TEST - Intentional Failure", you can test the webhook with the following command:
8+
9+
```bash
10+
curl -X POST "https://uptime-periphery.vercel.app/api/notifyRouter?key=<ROUTER_SECRET>" \
11+
-H "content-type: application/json" \
12+
-d '{"site":"TEST - Intentional Failure","status":"down"}'
13+
```
14+
15+
### How to add a new notification channel
16+
If there's a site whose status needs to be reported to a new channel.
17+
18+
1. Create a new Telegram channel for the notifications. Add anyone who needs to be notified to the channel.
19+
2. Add the Telegram Bot to that channel. Write anything in that channel (relevant for next step).
20+
3. Get the Telegram Chat ID of the channel by checking the result of this https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/getUpdates. Make sure you add the telegram bot token to the URL.
21+
4. Create a new site. Make sure the name starts with the a given text (let's call this the `prefix`).
22+
5. Add the `prefix` to the `sitePrefixToTelegramId` record in the [notifyRouter.ts](api/notifyRouter.ts) file, and map it to the Telegram Chat ID you got in step 2.
23+
6. Deploy the changes to the Vercel app.

service/api/notifyRouter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default {
6666
}
6767

6868
// Map by endpoint name prefix to Telegram chat ID
69-
const NAME_PREFIX_TO_TELEGRAM_CHAT_ID: Record<
69+
const sitePrefixToTelegramId: Record<
7070
string,
7171
string | string[] | undefined
7272
> = {
@@ -76,7 +76,7 @@ export default {
7676

7777
const url = new URL(request.url);
7878
if (url.searchParams.get("key") !== routerSecret)
79-
return new Response("unauthorized", { status: 401 });
79+
return new Response("Not Authorized", { status: 401 });
8080

8181
const payload = await request.json().catch(() => ({} as any));
8282
const textPayload =
@@ -89,8 +89,8 @@ export default {
8989
/(^|>)\s*(?<name>[^<(]+)\s*\(/.exec(textPayload)?.groups?.name ||
9090
"Unknown Site";
9191

92-
const match = Object.entries(NAME_PREFIX_TO_TELEGRAM_CHAT_ID).find(
93-
([k]) => siteName.startsWith(k)
92+
const match = Object.entries(sitePrefixToTelegramId).find(([k]) =>
93+
siteName.startsWith(k)
9494
)?.[1];
9595

9696
// If no matching route found, skip notification silently

0 commit comments

Comments
 (0)