mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 10:16:43 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
6b069037ff
commit
7218ed9885
1 changed files with 37 additions and 1 deletions
|
|
@ -81,7 +81,7 @@ Deno.serve(async (req) => {
|
||||||
|
|
||||||
const { data: agent } = await supabase
|
const { data: agent } = await supabase
|
||||||
.from("agent_instances")
|
.from("agent_instances")
|
||||||
.select("id, status")
|
.select("id, status, user_id, telegram_bot_username, railway_service_id")
|
||||||
.eq("railway_service_id", serviceId)
|
.eq("railway_service_id", serviceId)
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
|
|
||||||
|
|
@ -92,6 +92,17 @@ Deno.serve(async (req) => {
|
||||||
|
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
const upper = status.toUpperCase();
|
const upper = status.toUpperCase();
|
||||||
|
const wasProvisioning = agent.status === "provisioning";
|
||||||
|
|
||||||
|
// Carrega nome do cliente para a notificação (best-effort)
|
||||||
|
async function loadFullName(): Promise<string> {
|
||||||
|
const { data } = await supabase
|
||||||
|
.from("profiles")
|
||||||
|
.select("full_name")
|
||||||
|
.eq("id", agent.user_id)
|
||||||
|
.maybeSingle();
|
||||||
|
return (data?.full_name as string | undefined) || "—";
|
||||||
|
}
|
||||||
|
|
||||||
if (upper === "SUCCESS" || upper === "ACTIVE" || upper === "DEPLOYED") {
|
if (upper === "SUCCESS" || upper === "ACTIVE" || upper === "DEPLOYED") {
|
||||||
await supabase
|
await supabase
|
||||||
|
|
@ -110,6 +121,19 @@ Deno.serve(async (req) => {
|
||||||
.in("status", ["running", "retrying", "pending"]);
|
.in("status", ["running", "retrying", "pending"]);
|
||||||
|
|
||||||
console.log(`railway-webhook: agent ${agent.id} marcado como active (status=${upper})`);
|
console.log(`railway-webhook: agent ${agent.id} marcado como active (status=${upper})`);
|
||||||
|
|
||||||
|
// Notifica admin somente se era um auto-provisionamento (status anterior=provisioning)
|
||||||
|
if (wasProvisioning) {
|
||||||
|
const fullName = await loadFullName();
|
||||||
|
await notifyAdmin(
|
||||||
|
`✅ <b>Agente provisionado automaticamente!</b>\n\n` +
|
||||||
|
`👤 <b>Cliente:</b> ${fullName}\n` +
|
||||||
|
`🤖 <b>Bot:</b> @${agent.telegram_bot_username || "—"}\n` +
|
||||||
|
`🚀 <b>Railway:</b> <code>${agent.railway_service_id}</code>\n\n` +
|
||||||
|
`O cliente já pode conversar com a Mika no Telegram.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return jsonResponse(200, { ok: true, agent_id: agent.id, new_status: "active" });
|
return jsonResponse(200, { ok: true, agent_id: agent.id, new_status: "active" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,6 +154,18 @@ Deno.serve(async (req) => {
|
||||||
.in("status", ["running", "retrying", "pending"]);
|
.in("status", ["running", "retrying", "pending"]);
|
||||||
|
|
||||||
console.log(`railway-webhook: agent ${agent.id} marcado como error (status=${upper})`);
|
console.log(`railway-webhook: agent ${agent.id} marcado como error (status=${upper})`);
|
||||||
|
|
||||||
|
if (wasProvisioning) {
|
||||||
|
const fullName = await loadFullName();
|
||||||
|
await notifyAdmin(
|
||||||
|
`❌ <b>Falha no deploy do agente</b>\n\n` +
|
||||||
|
`👤 <b>Cliente:</b> ${fullName}\n` +
|
||||||
|
`🚀 <b>Railway:</b> <code>${agent.railway_service_id}</code>\n` +
|
||||||
|
`❗ <b>Status:</b> ${upper}\n\n` +
|
||||||
|
`➡️ <a href="https://mika.domco.ai/admin">Investigar</a>`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return jsonResponse(200, { ok: true, agent_id: agent.id, new_status: "error" });
|
return jsonResponse(200, { ok: true, agent_id: agent.id, new_status: "error" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue