mirror of
https://github.com/tiennm99/claude-status-webhook.git
synced 2026-04-17 13:21:01 +00:00
refactor: make setup script interactive instead of using env vars
This commit is contained in:
@@ -11,7 +11,7 @@ Telegram bot that forwards [status.claude.com](https://status.claude.com/) (Atla
|
|||||||
- `npm run dev` — Start local dev server (wrangler dev, emulates KV + Queues locally)
|
- `npm run dev` — Start local dev server (wrangler dev, emulates KV + Queues locally)
|
||||||
- `npm run deploy` — Deploy to Cloudflare Workers
|
- `npm run deploy` — Deploy to Cloudflare Workers
|
||||||
- `npx wrangler deploy --dry-run` — Verify build without deploying
|
- `npx wrangler deploy --dry-run` — Verify build without deploying
|
||||||
- `node scripts/setup-bot.js` — One-time: register bot commands + set Telegram webhook (requires BOT_TOKEN and WORKER_URL env vars)
|
- `node scripts/setup-bot.js` — One-time: register bot commands + set Telegram webhook (interactive prompts)
|
||||||
|
|
||||||
No test framework configured yet. No linter configured.
|
No test framework configured yet. No linter configured.
|
||||||
|
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ Note the worker URL from the output (e.g., `https://claude-status-webhook.<your-
|
|||||||
Run the setup script to register bot commands and set the Telegram webhook:
|
Run the setup script to register bot commands and set the Telegram webhook:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
BOT_TOKEN=your-token WORKER_URL=https://your-worker.workers.dev node scripts/setup-bot.js
|
node scripts/setup-bot.js
|
||||||
```
|
```
|
||||||
|
|
||||||
You should see `{"ok":true}` for both webhook and commands.
|
It will prompt for your bot token and worker URL. You should see `{"ok":true}` for both webhook and commands.
|
||||||
|
|
||||||
### 7. Configure Statuspage webhook
|
### 7. Configure Statuspage webhook
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { createInterface } from "node:readline/promises";
|
||||||
|
|
||||||
const TELEGRAM_API = "https://api.telegram.org/bot";
|
const TELEGRAM_API = "https://api.telegram.org/bot";
|
||||||
|
|
||||||
const BOT_COMMANDS = [
|
const BOT_COMMANDS = [
|
||||||
@@ -12,31 +14,40 @@ const BOT_COMMANDS = [
|
|||||||
{ command: "uptime", description: "Component health overview" },
|
{ command: "uptime", description: "Component health overview" },
|
||||||
];
|
];
|
||||||
|
|
||||||
async function main() {
|
async function prompt(rl, question) {
|
||||||
const token = process.env.BOT_TOKEN;
|
const answer = (await rl.question(question)).trim();
|
||||||
const workerUrl = process.env.WORKER_URL;
|
if (!answer) {
|
||||||
|
console.error("Input required. Aborting.");
|
||||||
if (!token || !workerUrl) {
|
|
||||||
console.error("Required env vars: BOT_TOKEN, WORKER_URL");
|
|
||||||
console.error("Usage: BOT_TOKEN=xxx WORKER_URL=https://your-worker.workers.dev node scripts/setup-bot.js");
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
// Set webhook
|
async function main() {
|
||||||
const webhookRes = await fetch(`${TELEGRAM_API}${token}/setWebhook`, {
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ url: `${workerUrl}/webhook/telegram` }),
|
|
||||||
});
|
|
||||||
console.log("Webhook:", await webhookRes.json());
|
|
||||||
|
|
||||||
// Register commands
|
try {
|
||||||
const commandsRes = await fetch(`${TELEGRAM_API}${token}/setMyCommands`, {
|
const token = await prompt(rl, "Bot token: ");
|
||||||
method: "POST",
|
const workerUrl = await prompt(rl, "Worker URL (e.g. https://your-worker.workers.dev): ");
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ commands: BOT_COMMANDS }),
|
// Set webhook
|
||||||
});
|
const webhookRes = await fetch(`${TELEGRAM_API}${token}/setWebhook`, {
|
||||||
console.log("Commands:", await commandsRes.json());
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ url: `${workerUrl}/webhook/telegram` }),
|
||||||
|
});
|
||||||
|
console.log("Webhook:", await webhookRes.json());
|
||||||
|
|
||||||
|
// Register commands
|
||||||
|
const commandsRes = await fetch(`${TELEGRAM_API}${token}/setMyCommands`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ commands: BOT_COMMANDS }),
|
||||||
|
});
|
||||||
|
console.log("Commands:", await commandsRes.json());
|
||||||
|
} finally {
|
||||||
|
rl.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(console.error);
|
main().catch(console.error);
|
||||||
|
|||||||
Reference in New Issue
Block a user