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
+6 -1
View File
@@ -1238,7 +1238,12 @@ async function handleApi(req,res,pathname){
if(req.method==='GET'&&pathname==='/api/public/msg-inbox'){
const s=messages.authFromCookie(req);
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(pathname.slice('/api/tg-hook/'.length)!==tgbot.webhookSecret())return json(res,404,{error:'Not found'});