Fix: Webhook issues and improve group creation
- Investigate and correct the timing and data sent to the `/ativarworkflow` webhook. - Address the looping issue with the `/hook` webhook, ensuring it's only triggered once during group creation.
This commit is contained in:
parent
0f9549556c
commit
8400de1baa
@ -1,4 +1,3 @@
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
|
||||
@ -21,6 +21,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
||||
const { toast } = useToast();
|
||||
const [nomeGrupo, setNomeGrupo] = useState('');
|
||||
const [carregando, setCarregando] = useState(false);
|
||||
const [webhookEnviado, setWebhookEnviado] = useState(false);
|
||||
const [mensagemStatus, setMensagemStatus] = useState<{
|
||||
tipo: 'info' | 'success' | 'error';
|
||||
texto: string;
|
||||
@ -40,6 +41,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
||||
|
||||
setCarregando(true);
|
||||
setMensagemStatus(null);
|
||||
setWebhookEnviado(false);
|
||||
|
||||
try {
|
||||
// Verificar se o usuário tem instância WhatsApp
|
||||
@ -68,16 +70,19 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
||||
|
||||
await createWorkflowInN8n(userEmail);
|
||||
|
||||
// Enviar webhook para N8N configurar webhook da Evolution API
|
||||
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
|
||||
|
||||
try {
|
||||
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
||||
await createEvolutionWebhook(userEmail);
|
||||
console.log('✅ Email enviado com sucesso para N8N');
|
||||
} catch (webhookError) {
|
||||
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
||||
// Continua mesmo se o webhook falhar
|
||||
// Enviar webhook para N8N configurar webhook da Evolution API APENAS UMA VEZ
|
||||
if (!webhookEnviado) {
|
||||
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
|
||||
|
||||
try {
|
||||
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
||||
await createEvolutionWebhook(userEmail);
|
||||
setWebhookEnviado(true);
|
||||
console.log('✅ Email enviado com sucesso para N8N');
|
||||
} catch (webhookError) {
|
||||
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
||||
// Continua mesmo se o webhook falhar
|
||||
}
|
||||
}
|
||||
|
||||
setMensagemStatus({
|
||||
|
||||
@ -58,20 +58,8 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
||||
if (groupResponse.id) {
|
||||
await updateGroupRemoteJid(grupo.id, groupResponse.id);
|
||||
|
||||
// 4. Enviar webhook para N8N configurar webhook da Evolution API
|
||||
try {
|
||||
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
||||
await createEvolutionWebhook(userEmail);
|
||||
console.log('✅ Email enviado com sucesso para N8N');
|
||||
} catch (webhookError) {
|
||||
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
||||
// Não falha o processo todo se o webhook falhar
|
||||
toast({
|
||||
title: 'Atenção',
|
||||
description: 'Grupo criado com sucesso, mas houve um problema ao configurar a automação. Entre em contato com o suporte.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
}
|
||||
// 4. Enviar webhook para N8N APENAS UMA VEZ - removido daqui para evitar loop
|
||||
// O webhook será enviado apenas no CreateGroupFormSimple.tsx
|
||||
|
||||
toast({
|
||||
title: 'Sucesso!',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user