Reverted to commit 09ffd66b47

This commit is contained in:
gpt-engineer-app[bot] 2025-07-01 22:37:49 +00:00
parent 3c9cf4de12
commit 7420bec9cc

View File

@ -29,87 +29,6 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
texto: string; texto: string;
} | null>(null); } | null>(null);
const enviarWebhookAtivarWorkflow = async (email: string) => {
try {
console.log(`🔔 [WEBHOOK] Enviando webhook ativarworkflow para: ${email}`);
const webhookUrl = 'https://webhookn8n.innova1001.com.br/webhook/ativarworkflow';
const webhookBody = {
email: email,
timestamp: new Date().toISOString(),
action: 'activate_workflow',
source: 'group_creation'
};
console.log('📦 [WEBHOOK] Dados do webhook ativarworkflow:', JSON.stringify(webhookBody, null, 2));
const response = await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(webhookBody)
});
console.log(`📡 [WEBHOOK] Status da resposta ativarworkflow: ${response.status}`);
if (!response.ok) {
const errorText = await response.text();
console.error(`❌ [WEBHOOK] Erro ativarworkflow: ${response.status} - ${errorText}`);
throw new Error(`Erro webhook ativarworkflow: ${response.status}`);
}
const responseData = await response.text();
console.log('✅ [WEBHOOK] Webhook ativarworkflow enviado com sucesso:', responseData);
setWorkflowAtivado(true);
} catch (error) {
console.error('💥 [WEBHOOK] Erro crítico webhook ativarworkflow:', error);
throw error;
}
};
const enviarWebhookHook = async (email: string) => {
try {
console.log(`🔔 [WEBHOOK] Enviando webhook hook para: ${email}`);
const webhookUrl = 'https://webhookn8n.innova1001.com.br/webhook/hook';
const webhookBody = {
email: email,
timestamp: new Date().toISOString(),
source: 'group_creation'
};
console.log('📦 [WEBHOOK] Dados do webhook hook:', JSON.stringify(webhookBody, null, 2));
const response = await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(webhookBody)
});
console.log(`📡 [WEBHOOK] Status da resposta hook: ${response.status}`);
if (!response.ok) {
const errorText = await response.text();
console.error(`❌ [WEBHOOK] Erro hook: ${response.status} - ${errorText}`);
throw new Error(`Erro webhook hook: ${response.status}`);
}
const responseData = await response.text();
console.log('✅ [WEBHOOK] Webhook hook enviado com sucesso:', responseData);
setWebhookEnviado(true);
} catch (error) {
console.error('💥 [WEBHOOK] Erro crítico webhook hook:', error);
throw error;
}
};
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
@ -128,7 +47,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
setWorkflowAtivado(false); setWorkflowAtivado(false);
try { try {
// 1. Verificar se o usuário tem instância WhatsApp // Verificar se o usuário tem instância WhatsApp
setMensagemStatus({ tipo: 'info', texto: 'Verificando sua instância do WhatsApp...' }); setMensagemStatus({ tipo: 'info', texto: 'Verificando sua instância do WhatsApp...' });
const instanciaInfo = await verificarInstanciaWhatsApp(); const instanciaInfo = await verificarInstanciaWhatsApp();
@ -141,7 +60,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
return; return;
} }
// 2. Criar ou encontrar grupo // Criar ou encontrar grupo
setMensagemStatus({ tipo: 'info', texto: 'Cadastrando grupo...' }); setMensagemStatus({ tipo: 'info', texto: 'Cadastrando grupo...' });
const grupo = await findOrCreateWhatsAppGroup(nomeGrupo.trim()); const grupo = await findOrCreateWhatsAppGroup(nomeGrupo.trim());
@ -149,43 +68,37 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
throw new Error('Falha ao criar o grupo'); throw new Error('Falha ao criar o grupo');
} }
// 3. Criar workflow no n8n // Criar workflow no n8n
setMensagemStatus({ tipo: 'info', texto: 'Configurando automação...' }); setMensagemStatus({ tipo: 'info', texto: 'Configurando automação...' });
await createWorkflowInN8n(userEmail); await createWorkflowInN8n(userEmail);
// 4. ENVIAR WEBHOOK ATIVARWORKFLOW // AGORA SIM: Ativar workflow (webhook ativarworkflow) APENAS NO MOMENTO DE CADASTRAR GRUPO
console.log('🚀 [GRUPO] Enviando webhook ativarworkflow no cadastro do grupo'); console.log('🔔 [GRUPO] Enviando webhook ativarworkflow no momento do cadastro do grupo');
setMensagemStatus({ tipo: 'info', texto: 'Ativando workflow...' }); setMensagemStatus({ tipo: 'info', texto: 'Ativando workflow...' });
try { try {
await enviarWebhookAtivarWorkflow(userEmail); console.log(`🔔 Enviando webhook ativarworkflow para usuário: ${userEmail}`);
console.log('✅ [GRUPO] Webhook ativarworkflow enviado com sucesso'); await activateUserWorkflow(userEmail);
setWorkflowAtivado(true);
console.log('✅ [GRUPO] Webhook ativarworkflow enviado com sucesso no cadastro do grupo');
} catch (workflowError) { } catch (workflowError) {
console.error('❌ [GRUPO] Erro ao enviar webhook ativarworkflow:', workflowError); console.error('❌ Erro ao enviar webhook ativarworkflow:', workflowError);
// Continua mesmo se o webhook falhar // Continua mesmo se o webhook falhar
toast({
title: 'Aviso',
description: 'Grupo criado, mas houve erro ao ativar workflow',
variant: 'destructive',
});
} }
// 5. ENVIAR WEBHOOK HOOK // AGORA SIM: Enviar webhook para N8N configurar webhook da Evolution API APENAS NO MOMENTO DE CADASTRAR GRUPO
console.log('🚀 [GRUPO] Enviando webhook hook no cadastro do grupo'); console.log('🔔 [GRUPO] Enviando webhook de configuração no momento do cadastro do grupo');
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' }); setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
try { try {
await enviarWebhookHook(userEmail); console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
console.log('✅ [GRUPO] Webhook hook enviado com sucesso'); await createEvolutionWebhook(userEmail);
setWebhookEnviado(true);
console.log('✅ [GRUPO] Email enviado com sucesso para N8N no cadastro do grupo');
} catch (webhookError) { } catch (webhookError) {
console.error('❌ [GRUPO] Erro ao enviar webhook hook:', webhookError); console.error('❌ Erro ao enviar email para N8N:', webhookError);
// Continua mesmo se o webhook falhar // Continua mesmo se o webhook falhar
toast({
title: 'Aviso',
description: 'Grupo criado, mas houve erro na configuração do webhook',
variant: 'destructive',
});
} }
setMensagemStatus({ setMensagemStatus({
@ -205,7 +118,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
onSuccess(); onSuccess();
} catch (error) { } catch (error) {
console.error('❌ [GRUPO] Erro ao cadastrar grupo:', error); console.error('Erro ao cadastrar grupo:', error);
setMensagemStatus({ setMensagemStatus({
tipo: 'error', tipo: 'error',
texto: 'Erro ao cadastrar grupo. Tente novamente.' texto: 'Erro ao cadastrar grupo. Tente novamente.'
@ -252,24 +165,6 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
</Alert> </Alert>
)} )}
{/* Status dos webhooks */}
{(workflowAtivado || webhookEnviado) && (
<div className="space-y-2">
{workflowAtivado && (
<div className="flex items-center text-sm text-green-600">
<CheckCircle2 className="h-4 w-4 mr-2" />
Webhook ativarworkflow enviado
</div>
)}
{webhookEnviado && (
<div className="flex items-center text-sm text-green-600">
<CheckCircle2 className="h-4 w-4 mr-2" />
Webhook hook enviado
</div>
)}
</div>
)}
<Button type="submit" disabled={carregando || !nomeGrupo.trim()}> <Button type="submit" disabled={carregando || !nomeGrupo.trim()}>
{carregando ? ( {carregando ? (
<> <>