Personal Telegram developer console for GitHub

cleanup: remove temporary /diag command

* test: ensure temporary diag command is removed * cleanup: remove temporary Telegram diagnostics command * test: remove obsolete diagnostics test

davoodmehraban89 committed Oct 2, 2026 at 19:07 UTC e519409667b184ddd69e4151b1d9ecab9f2d04f3
3 files changed +27 -43
src/index.js
-7
@@ -78,13 +78,6 @@ async function handleCommand(env, message) {
78 const chatId = message.chat?.id;
79 const command = (message.text || "").trim().split(/\s+/)[0].split("@")[0].toLowerCase();
80
81 - if (command === "/diag") {
82 - const senderId = message.from?.id;
83 - const authState = isOwner(env, message.from) ? "authorized" : "unauthorized";
84 - await sendMessage(env, chatId, `Telegram ID: <code>${senderId}</code>\nAuthorization: <b>${authState}</b>`);
85 - return;
86 - }
87 -
81 // Personal bot: fail silently for every Telegram user except the owner.
82 if (!isOwner(env, message.from)) return;
83
test/diag.test.js deleted
-36
@@ -1,36 +0,0 @@
1 -import test from "node:test";
2 -import assert from "node:assert/strict";
3 -import worker from "../src/index.js";
4 -
5 -test("/diag replies with sender id and authorization state before owner gate", async () => {
6 - const req = new Request("https://example.com/telegram/webhook", {
7 - method: "POST",
8 - headers: {
9 - "content-type": "application/json",
10 - "X-Telegram-Bot-Api-Secret-Token": "right",
11 - },
12 - body: JSON.stringify({
13 - message: { text: "/diag", from: { id: 999 }, chat: { id: 999 } },
14 - }),
15 - });
16 -
17 - let sent;
18 - globalThis.fetch = async (url, init) => {
19 - sent = { url: String(url), body: JSON.parse(init.body) };
20 - return new Response(JSON.stringify({ ok: true }), {
21 - status: 200,
22 - headers: { "content-type": "application/json" },
23 - });
24 - };
25 -
26 - const res = await worker.fetch(req, {
27 - TELEGRAM_WEBHOOK_SECRET: "right",
28 - OWNER_TELEGRAM_ID: "123",
29 - TELEGRAM_BOT_TOKEN: "token",
30 - });
31 -
32 - assert.equal(res.status, 200);
33 - assert.equal(sent.url, "https://api.telegram.org/bottoken/sendMessage");
34 - assert.match(sent.body.text, /999/);
35 - assert.match(sent.body.text, /unauthorized/i);
36 -});
test/security.test.js
+27
@@ -100,3 +100,30 @@ test("temporary setup endpoint is disabled after webhook registration", async ()
100 assert.equal(res.status, 404);
101 assert.equal(calls, 0);
102 });
103 +
104 +test("temporary diagnostic command no longer exposes Telegram ID", async () => {
105 + const req = telegramRequest("right", {
106 + message: { text: "/diag", from: { id: 123 }, chat: { id: 123 } },
107 + });
108 +
109 + const messages = [];
110 + globalThis.fetch = async (_url, options) => {
111 + const payload = JSON.parse(options.body);
112 + messages.push(payload.text);
113 + return new Response(JSON.stringify({ ok: true }), {
114 + status: 200,
115 + headers: { "content-type": "application/json" },
116 + });
117 + };
118 +
119 + const res = await worker.fetch(req, {
120 + TELEGRAM_WEBHOOK_SECRET: "right",
121 + OWNER_TELEGRAM_ID: "123",
122 + TELEGRAM_BOT_TOKEN: "token",
123 + });
124 +
125 + assert.equal(res.status, 200);
126 + assert.equal(messages.length, 1);
127 + assert.match(messages[0], /فرمان شناخته نشد/);
128 + assert.doesNotMatch(messages[0], /Telegram ID|123/);
129 +});