From 403dc47c166ac102947a4e2ba7292d57d9a27cfa Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 21:20:04 +0000 Subject: [PATCH 1/3] Work in progress --- bun.lockb | Bin 354676 -> 354676 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/bun.lockb b/bun.lockb index 5733bffcb5b3393df27937be25c9c3ac4d005ecb..0c6fdca2318122dd03d13d4ae2b85aeed0532242 100755 GIT binary patch delta 1716 zcmY*ZS4>n<5Y6g&t5Oz3iHR{H#uiJI6)PA}>^PF|mD!=u%ctR#7A{NYM{J zOt4T~T`;jMC}8|B8smqt2V-LWQ9q1r-Ym1_=iT$poSA!P?%etQB=-B0*j%T@*~8h> zjrfC>MCyA436yydd5W#sn5Wp0jVVFcpfA~2uEd{92&bGwNM|CU2~%lcGi(%-gF&ju z%E4I1mK#VUZw@9YKkBgXvUOn)?(*X`Dy=z!RgB{=A%zw@(3_GRXjbF!+&~;TO-U}+ zs!@o}Ttt#R4^uN=tN64VF=Q=-U4^xUOt=a$lL<*Aq6pI&OVJ!f813Ve>30z)__YWVneg4qF(fPY z9+P8mfMiNPjy=qC0_0n!Uo0zz#fMYrsS9%yuRVboe(XX7b)5+0mvu6LQ(b(WA5O~2 zq%vVHKKA|+Id(=V(&$Yw4EkFlEy0Q;+H(pIHTL1tSio3>VWpVs!wy~^m%>~!&cMZs zBpq9ZM8)}K7{*uv##JKH^Q{cMyHiObW^A;hoImO15>$0IdR>l%L5?=sSAkg}#J>vZ z)_}`x;sReFqz1{hFqWdWR>G|~r3zMRIV&lNk%>hg*L%iYMTA*Uao$<)HxT1K^toQLF&lZ2xzKT4UJ>KXN>$&G9mG7?Bc+fN zakwxlKFXi-9=U1Bny1bf_LPIi^QCoLnwf_unUUW94) zWpt@$1YNz4kwJstZHqR{=NnLbiZ;53f}Ko-XH#DzX7ztuw=Aas delta 1716 zcmY*ZS4>n<5Y6g&D^eCjiHR{H#uiJI#SR7(dqXsKqr?PzOl%(_x|9`^RTK$~QuKol z6Rha!f{A58De=Qdj334xjEVI}{V=w9v&@#Cch5U>X6~K2bLV?!-1pA7Jg3Fk!`ah~ zgaejD>T?*0wEO__6b1_l*k%xqrt&4(immjZDY0Y7*Vw`XhskF#}FiLiyQH{g$0&(OtrFmGZ zMj_hs5JmQUObKBxn8iTFY!D`w*mx>JZuB{G~?q4>QMQyEJZ zOOIfW;!|$KlC=nS71kCp;VQxmCM1!_VoYN!MROEml#frL-^HBZ*J30w;k%ckNKx!P zD#zdeDU@*xyP4+%$hSyIv&U`>qG#jx%fIioRE`A zWx`#2?0uzj?94Kx)0+|)^tV)6f)&ZM`y?J|>_ew8pRowT%P_}>9lSg#gSlj$hKmR`vC;Ml{$x~0P}SM!bp;j#IofD%C1!>Y|0<~yC}swVuzYAjZ#d(}u+oLYlj zia*w1BV)PIgSD8~jXghV@hd_N3H3Ow_8`!UV@k{7S@ouCB5lb0!%m!X$F0|d0SHw75sp?y@gO~?-q!e-@ z4i`=(NBDEzBR4Hs^VAv5o^p_a#=z|2tix$w6Mv$cq+Y(-HDNugP3-A;8?UVV!(r^y z&xFQbeI`s|g5BVOy8F{#^&TAJl$3qPVo9|GB1jQU{adkIiL5qm$GTPw3n46Rff%eXXPm~1pl5AJ3?XK>OQA*4(2gx3 z#+4m1XxNzKY3)Fl*~c1dn_@YI!)A Date: Thu, 23 Apr 2026 21:20:26 +0000 Subject: [PATCH 2/3] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- src/routes/admin.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/routes/admin.tsx b/src/routes/admin.tsx index df5a5d0..964720b 100644 --- a/src/routes/admin.tsx +++ b/src/routes/admin.tsx @@ -74,10 +74,9 @@ function AdminPage() { const { data, error } = await supabase .from("agent_instances") .select( - `id, user_id, status, uuid_tenant, telegram_bot_username, telegram_bot_token_vault_id, - railway_service_id, vps_pool_id, created_at, provisioned_at, - profile:profiles!agent_instances_user_id_fkey(full_name), - subscription:subscriptions!subscriptions_user_id_fkey(plans(slug, name))`, + `*, + profile:profiles!agent_instances_user_id_fkey(full_name, phone), + subscription:subscriptions!subscriptions_user_id_fkey(status, plans(slug, name))`, ) .order("created_at", { ascending: false }) .limit(100); From ec253ae5e8e1a4f0db981b4d99d586f795715796 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 21:20:38 +0000 Subject: [PATCH 3/3] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- src/routes/admin.agente.$id.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/routes/admin.agente.$id.tsx b/src/routes/admin.agente.$id.tsx index 7bab235..5adac85 100644 --- a/src/routes/admin.agente.$id.tsx +++ b/src/routes/admin.agente.$id.tsx @@ -140,6 +140,35 @@ function AgentDetailPage() { }, }); + // Backfill: se o agente não tem telegram_user_chat_id mas já recebeu mensagens, + // pega a primeira mensagem incoming e popula automaticamente. + useEffect(() => { + if (!agent || !isAdmin) return; + if (agent.telegram_user_chat_id) return; + let cancelled = false; + (async () => { + const { data: msg } = await supabase + .from("telegram_messages_log") + .select("telegram_chat_id") + .eq("agent_instance_id", id) + .eq("direction", "incoming") + .order("created_at", { ascending: true }) + .limit(1) + .maybeSingle(); + if (cancelled || !msg?.telegram_chat_id) return; + const { error: updErr } = await supabase + .from("agent_instances") + .update({ telegram_user_chat_id: msg.telegram_chat_id }) + .eq("id", id); + if (!updErr) { + queryClient.invalidateQueries({ queryKey: ["agent-detail", id] }); + } + })(); + return () => { + cancelled = true; + }; + }, [agent, isAdmin, id, queryClient]); + // ===== Estado do formulário ===== const fullName = agent?.profile?.full_name?.trim() || "Usuário"; const firstName = fullName.split(" ")[0] || "Usuário";