mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 09:16:46 +00:00
Corrigiu query e chat_id
X-Lovable-Edit-ID: edt-2baa544b-0bcb-4815-abcd-5af5236eabd3 Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
commit
53d76261ec
3 changed files with 32 additions and 4 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue