Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,21 @@
store.set("waNum", wa);
$("setupMsg").textContent = problems.length ? "Saved, but check: " + problems.join("; ") + "." : "Saved in this browser.";
};
// Reads the chat id from the newest message sent to the bot, so nobody has to dig through getUpdates JSON.
$("findChat").onclick = async () => {
const tok = $("tgToken").value.trim();
if (!tok) { $("setupMsg").textContent = "Paste the bot token first."; return; }
$("setupMsg").textContent = "Looking for your message to the bot…";
try {
const j = await (await fetch("https://api.telegram.org/bot" + encodeURIComponent(tok) + "/getUpdates")).json();
if (!j.ok) { $("setupMsg").textContent = j.error_code === 401 ? "Telegram did not accept this token. Copy it again from @BotFather." : "Telegram said: " + (j.description || "error"); return; }
const msgs = j.result.map((u) => u.message || u.edited_message || u.channel_post).filter(Boolean);
if (!msgs.length) { $("setupMsg").textContent = "No message found. In Telegram, open your bot, press Start, send \"hi\", then press this button again."; return; }
const chat = msgs[msgs.length - 1].chat;
$("tgChat").value = chat.id;
$("setupMsg").textContent = "Found " + (chat.first_name || chat.title || "your chat") + " (" + chat.id + "). Press Save.";
} catch (e) { $("setupMsg").textContent = "Could not reach Telegram. Check the internet connection."; }
};
$("testTg").onclick = () => {
$("saveSetup").click();
sendTelegram("Nazar test message: family alerts are working. You will get a message like this if a scam call is detected.", $("setupMsg"));
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h3>Family alert</h3>
<label>Telegram bot token <input id="tgToken" placeholder="123456:ABC..." autocomplete="off"></label>
<label>Telegram chat id <input id="tgChat" placeholder="e.g. 987654321"></label>
<label>WhatsApp number with country code <input id="waNum" placeholder="e.g. 919876543210"></label>
<div class="btns"><button class="primary" id="saveSetup">Save</button><button id="testTg">Send a test message</button><span id="setupMsg" class="state"></span></div>
<div class="btns"><button class="primary" id="saveSetup">Save</button><button id="findChat">Find my chat ID</button><button id="testTg">Send a test message</button><span id="setupMsg" class="state"></span></div>
</div>
</details>
</section>
Expand Down
Loading