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 React, { useState } from 'react';
|
||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
|||||||
@ -21,6 +21,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [nomeGrupo, setNomeGrupo] = useState('');
|
const [nomeGrupo, setNomeGrupo] = useState('');
|
||||||
const [carregando, setCarregando] = useState(false);
|
const [carregando, setCarregando] = useState(false);
|
||||||
|
const [webhookEnviado, setWebhookEnviado] = useState(false);
|
||||||
const [mensagemStatus, setMensagemStatus] = useState<{
|
const [mensagemStatus, setMensagemStatus] = useState<{
|
||||||
tipo: 'info' | 'success' | 'error';
|
tipo: 'info' | 'success' | 'error';
|
||||||
texto: string;
|
texto: string;
|
||||||
@ -40,6 +41,7 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
|||||||
|
|
||||||
setCarregando(true);
|
setCarregando(true);
|
||||||
setMensagemStatus(null);
|
setMensagemStatus(null);
|
||||||
|
setWebhookEnviado(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Verificar se o usuário tem instância WhatsApp
|
// Verificar se o usuário tem instância WhatsApp
|
||||||
@ -68,16 +70,19 @@ const CreateGroupFormSimple = ({ userEmail, onSuccess }: CreateGroupFormProps) =
|
|||||||
|
|
||||||
await createWorkflowInN8n(userEmail);
|
await createWorkflowInN8n(userEmail);
|
||||||
|
|
||||||
// Enviar webhook para N8N configurar webhook da Evolution API
|
// Enviar webhook para N8N configurar webhook da Evolution API APENAS UMA VEZ
|
||||||
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
|
if (!webhookEnviado) {
|
||||||
|
setMensagemStatus({ tipo: 'info', texto: 'Configurando webhook...' });
|
||||||
try {
|
|
||||||
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
try {
|
||||||
await createEvolutionWebhook(userEmail);
|
console.log(`🔔 Enviando email para N8N configurar webhook: ${userEmail}`);
|
||||||
console.log('✅ Email enviado com sucesso para N8N');
|
await createEvolutionWebhook(userEmail);
|
||||||
} catch (webhookError) {
|
setWebhookEnviado(true);
|
||||||
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
console.log('✅ Email enviado com sucesso para N8N');
|
||||||
// Continua mesmo se o webhook falhar
|
} catch (webhookError) {
|
||||||
|
console.error('❌ Erro ao enviar email para N8N:', webhookError);
|
||||||
|
// Continua mesmo se o webhook falhar
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMensagemStatus({
|
setMensagemStatus({
|
||||||
|
|||||||
@ -58,20 +58,8 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
if (groupResponse.id) {
|
if (groupResponse.id) {
|
||||||
await updateGroupRemoteJid(grupo.id, groupResponse.id);
|
await updateGroupRemoteJid(grupo.id, groupResponse.id);
|
||||||
|
|
||||||
// 4. Enviar webhook para N8N configurar webhook da Evolution API
|
// 4. Enviar webhook para N8N APENAS UMA VEZ - removido daqui para evitar loop
|
||||||
try {
|
// O webhook será enviado apenas no CreateGroupFormSimple.tsx
|
||||||
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',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Sucesso!',
|
title: 'Sucesso!',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user