forked from angelancajas34-beep/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset-webhook.mjs
More file actions
27 lines (22 loc) · 835 Bytes
/
Copy pathset-webhook.mjs
File metadata and controls
27 lines (22 loc) · 835 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
// Usage: node scripts/set-webhook.mjs <worker-url> <bot-token> <webhook-secret>
// Example:
// node scripts/set-webhook.mjs https://teammarysy-bot.myaccount.workers.dev 123456:ABC... mySecret123
const [, , workerUrl, botToken, webhookSecret] = process.argv;
if (!workerUrl || !botToken || !webhookSecret) {
console.error("Usage: node scripts/set-webhook.mjs <worker-url> <bot-token> <webhook-secret>");
process.exit(1);
}
const res = await fetch(`https://api.telegram.org/bot${botToken}/setWebhook`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
url: workerUrl,
secret_token: webhookSecret,
allowed_updates: ["message", "callback_query"],
}),
});
const data = await res.json();
console.log(JSON.stringify(data, null, 2));
if (!data.ok) {
process.exit(1);
}