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
8a7adff80b
commit
376ba5e6f0
2 changed files with 9 additions and 32 deletions
|
|
@ -670,12 +670,3 @@ const rootRouteChildren: RootRouteChildren = {
|
||||||
export const routeTree = rootRouteImport
|
export const routeTree = rootRouteImport
|
||||||
._addFileChildren(rootRouteChildren)
|
._addFileChildren(rootRouteChildren)
|
||||||
._addFileTypes<FileRouteTypes>()
|
._addFileTypes<FileRouteTypes>()
|
||||||
|
|
||||||
import type { getRouter } from './router.tsx'
|
|
||||||
import type { createStart } from '@tanstack/react-start'
|
|
||||||
declare module '@tanstack/react-start' {
|
|
||||||
interface Register {
|
|
||||||
ssr: true
|
|
||||||
router: Awaited<ReturnType<typeof getRouter>>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// configure-telegram-webhook
|
// configure-telegram-webhook
|
||||||
// Gera secret aleatório, configura webhook no Telegram e marca telegram_webhook_configured=true.
|
// Mantém compatibilidade com o wizard: garante que o webhook do Telegram fique desligado,
|
||||||
|
// pois o Hermes responde via polling/runtime.
|
||||||
|
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||||
import { corsHeaders } from "../_shared/cors.ts";
|
import { corsHeaders } from "../_shared/cors.ts";
|
||||||
|
|
@ -12,14 +13,6 @@ function jsonResponse(body: unknown, status = 200): Response {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomHex(bytes: number): string {
|
|
||||||
const buf = new Uint8Array(bytes);
|
|
||||||
crypto.getRandomValues(buf);
|
|
||||||
return Array.from(buf)
|
|
||||||
.map((b) => b.toString(16).padStart(2, "0"))
|
|
||||||
.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
async function getDecryptedSecret(
|
async function getDecryptedSecret(
|
||||||
admin: any,
|
admin: any,
|
||||||
|
|
@ -81,21 +74,14 @@ Deno.serve(async (req) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const webhookSecret = randomHex(32);
|
const deleteRes = await telegramApi(token, "deleteWebhook", {
|
||||||
const webhookUrl =
|
drop_pending_updates: false,
|
||||||
`${supabaseUrl}/functions/v1/telegram-webhook?token=${agent.uuid_tenant}`;
|
|
||||||
|
|
||||||
const setRes = await telegramApi(token, "setWebhook", {
|
|
||||||
url: webhookUrl,
|
|
||||||
allowed_updates: ["message"],
|
|
||||||
drop_pending_updates: true,
|
|
||||||
secret_token: webhookSecret,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!setRes.ok) {
|
if (!deleteRes.ok) {
|
||||||
console.error("setWebhook failed", setRes);
|
console.error("deleteWebhook failed", deleteRes);
|
||||||
return jsonResponse(
|
return jsonResponse(
|
||||||
{ error: "Falha ao configurar webhook no Telegram." },
|
{ error: "Falha ao liberar o Telegram para o runtime do agente." },
|
||||||
500,
|
500,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -103,8 +89,8 @@ Deno.serve(async (req) => {
|
||||||
const { error: updErr } = await admin
|
const { error: updErr } = await admin
|
||||||
.from("agent_instances")
|
.from("agent_instances")
|
||||||
.update({
|
.update({
|
||||||
telegram_webhook_secret: webhookSecret,
|
telegram_webhook_secret: null,
|
||||||
telegram_webhook_configured: true,
|
telegram_webhook_configured: false,
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
})
|
})
|
||||||
.eq("id", agent.id);
|
.eq("id", agent.id);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue