Personal Telegram developer console for GitHub
test: require callback_query webhook registration
davoodmehraban89 committed
Oct 2, 2026 at 19:26 UTC
a5dbad405289df9294628a76be78f184fcdf7efd
1 file changed
+34
test/webhook-callback-setup.test.js
new
+34
@@ -0,0 +1,34 @@
1
+import test from "node:test";
2
+import assert from "node:assert/strict";
3
+import worker from "../src/index.js";
4
+
5
+test("temporary setup registers callback_query updates with Telegram", async () => {
6
+ const req = new Request("https://nexa-dev-bot.example.workers.dev/telegram/setup", {
7
+ method: "GET",
8
+ });
9
+
10
+ let captured;
11
+ globalThis.fetch = async (url, init) => {
12
+ captured = {
13
+ url: String(url),
14
+ body: JSON.parse(init.body),
15
+ };
16
+ return new Response(JSON.stringify({ ok: true, result: true }), {
17
+ status: 200,
18
+ headers: { "content-type": "application/json" },
19
+ });
20
+ };
21
+
22
+ const res = await worker.fetch(req, {
23
+ TELEGRAM_WEBHOOK_SECRET: "secret",
24
+ TELEGRAM_BOT_TOKEN: "token",
25
+ });
26
+
27
+ assert.equal(res.status, 200);
28
+ assert.equal(captured.url, "https://api.telegram.org/bottoken/setWebhook");
29
+ assert.deepEqual(captured.body, {
30
+ url: "https://nexa-dev-bot.example.workers.dev/telegram/webhook",
31
+ secret_token: "secret",
32
+ allowed_updates: ["message", "callback_query"],
33
+ });
34
+});