Stop offering "Connect Telegram" to members who are already connected

Janie linked successfully and the dashboard kept showing the Connect button,
so a working link looked like a failed one — and she had no way to tell which.

The Messages panel had no idea about link state: msg-inbox never reported it.
It now returns tgLinked (from tgbot.memberChat) on the response the panel
already fetches, so this costs no extra request. Linked members get a
confirmation telling them where their pings arrive and how to open the Mini
App, instead of a button asking them to do something already done.

Third variant today of the same failure: the interface not knowing a state it
could easily have known, and the member left guessing. The bot had it too —
telling an already-linked member their code had expired.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-08-29 07:05:26 -05:00
parent 8e7660a9a1
commit 962f0c8892
2 changed files with 15 additions and 1 deletions
+9
View File
@@ -307,6 +307,15 @@
try{ try{
const foot=document.createElement('div'); const foot=document.createElement('div');
foot.style.cssText='margin-top:12px;padding-top:10px;border-top:1px solid var(--line, #24425d)'; foot.style.cssText='margin-top:12px;padding-top:10px;border-top:1px solid var(--line, #24425d)';
// Already connected? Say so and stop asking. Offering to connect someone
// who IS connected is how a working link looks broken.
if(data&&data.tgLinked){
foot.innerHTML='<div class="micro" style="color:var(--teal)">✈️ <b>Telegram connected.</b> '
+'Payout pings, team messages and join alerts arrive in your chat with the bot. '
+'Open the bot and tap ☰ for your dashboard inside Telegram.</div>';
el.appendChild(foot);
return;
}
foot.innerHTML='<button id="tgLinkBtn" class="btn btn-secondary btn-sm">✈️ Connect Telegram — payout pings + team chat</button><span class="micro" id="tgLinkNote" style="margin-left:8px"></span>'; foot.innerHTML='<button id="tgLinkBtn" class="btn btn-secondary btn-sm">✈️ Connect Telegram — payout pings + team chat</button><span class="micro" id="tgLinkNote" style="margin-left:8px"></span>';
el.appendChild(foot); el.appendChild(foot);
const tb=document.getElementById('tgLinkBtn'); const tb=document.getElementById('tgLinkBtn');
+6 -1
View File
@@ -1238,7 +1238,12 @@ async function handleApi(req,res,pathname){
if(req.method==='GET'&&pathname==='/api/public/msg-inbox'){ if(req.method==='GET'&&pathname==='/api/public/msg-inbox'){
const s=messages.authFromCookie(req); const s=messages.authFromCookie(req);
if(!s)return json(res,401,{error:'Not signed in.'}); if(!s)return json(res,401,{error:'Not signed in.'});
return json(res,200,messages.inbox(s)); // Whether this position already has a Telegram chat attached. Without it
// the panel keeps offering "Connect Telegram" to people who are already
// connected, which reads as the link having silently failed.
let tgLinked=false;
try{ tgLinked=!!tgbot.memberChat(s.id); }catch(err){}
return json(res,200,Object.assign({},messages.inbox(s),{tgLinked:tgLinked}));
} }
if(req.method==='POST'&&pathname.startsWith('/api/tg-hook/')){ if(req.method==='POST'&&pathname.startsWith('/api/tg-hook/')){
if(pathname.slice('/api/tg-hook/'.length)!==tgbot.webhookSecret())return json(res,404,{error:'Not found'}); if(pathname.slice('/api/tg-hook/'.length)!==tgbot.webhookSecret())return json(res,404,{error:'Not found'});