Reverted to commit 3800e5818b
This commit is contained in:
parent
259ac13e6d
commit
c8075b9f34
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import { createWhatsAppGroup } from '@/services/whatsAppGroupCreationService';
|
|
||||||
|
|
||||||
export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@ -29,14 +28,8 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
setCadastrando(true);
|
setCadastrando(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. Primeiro criar o grupo via Evolution API para obter o remote_jid e dados completos
|
// 1. Webhook para criar grupo via N8N
|
||||||
console.log("🔔 [GRUPO] Criando grupo via Evolution API");
|
console.log("🔔 [GRUPO] Enviando webhook para criar grupo via N8N");
|
||||||
|
|
||||||
const grupoEvolutionData = await createWhatsAppGroup(userEmail, nomeGrupo.trim());
|
|
||||||
console.log('✅ [GRUPO] Grupo criado via Evolution API:', grupoEvolutionData);
|
|
||||||
|
|
||||||
// 2. Webhook para enviar dados completos do grupo criado para N8N
|
|
||||||
console.log("🔔 [GRUPO] Enviando webhook para N8N com dados completos do grupo");
|
|
||||||
|
|
||||||
const webhookCriarGrupo = 'https://webhookn8n.innova1001.com.br/webhook/criargrupofinance';
|
const webhookCriarGrupo = 'https://webhookn8n.innova1001.com.br/webhook/criargrupofinance';
|
||||||
const webhookData = {
|
const webhookData = {
|
||||||
@ -44,17 +37,10 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
whatsapp: userInstance?.whatsapp || '',
|
whatsapp: userInstance?.whatsapp || '',
|
||||||
nomeGrupo: nomeGrupo.trim(),
|
nomeGrupo: nomeGrupo.trim(),
|
||||||
instancia: userInstance?.instancia_zap || '',
|
instancia: userInstance?.instancia_zap || '',
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString()
|
||||||
// Dados completos do grupo criado via Evolution API
|
|
||||||
grupoEvolution: grupoEvolutionData,
|
|
||||||
remote_jid: grupoEvolutionData.id || null,
|
|
||||||
group_id: grupoEvolutionData.id || null,
|
|
||||||
subject: grupoEvolutionData.subject || nomeGrupo.trim(),
|
|
||||||
description: grupoEvolutionData.description || null,
|
|
||||||
participants: grupoEvolutionData.participants || []
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('🔔 Enviando dados completos para webhook criar grupo:', webhookData);
|
console.log('🔔 Enviando dados para webhook criar grupo:', webhookData);
|
||||||
|
|
||||||
const responseCriar = await fetch(webhookCriarGrupo, {
|
const responseCriar = await fetch(webhookCriarGrupo, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -67,12 +53,12 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
if (!responseCriar.ok) {
|
if (!responseCriar.ok) {
|
||||||
const errorText = await responseCriar.text();
|
const errorText = await responseCriar.text();
|
||||||
console.error(`❌ Erro ao enviar webhook criar grupo: ${responseCriar.status} - ${errorText}`);
|
console.error(`❌ Erro ao enviar webhook criar grupo: ${responseCriar.status} - ${errorText}`);
|
||||||
throw new Error(`Erro ao enviar dados do grupo para N8N: ${responseCriar.status}`);
|
throw new Error(`Erro ao criar grupo via N8N: ${responseCriar.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('✅ [GRUPO] Webhook criar grupo enviado com sucesso');
|
console.log('✅ [GRUPO] Webhook criar grupo enviado com sucesso');
|
||||||
|
|
||||||
// 3. Webhook para ativar workflow
|
// 2. Webhook para ativar workflow
|
||||||
console.log("🔔 [GRUPO] Enviando webhook ativar workflow");
|
console.log("🔔 [GRUPO] Enviando webhook ativar workflow");
|
||||||
|
|
||||||
const webhookAtivarWorkflow = 'https://webhookn8n.innova1001.com.br/webhook/ativarworkflow';
|
const webhookAtivarWorkflow = 'https://webhookn8n.innova1001.com.br/webhook/ativarworkflow';
|
||||||
@ -103,7 +89,7 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
console.error('❌ Erro ao enviar webhook ativar workflow:', error);
|
console.error('❌ Erro ao enviar webhook ativar workflow:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Webhook para configurar hook da Evolution API
|
// 3. Webhook para configurar hook da Evolution API
|
||||||
console.log("🔔 [GRUPO] Enviando webhook configurar hook");
|
console.log("🔔 [GRUPO] Enviando webhook configurar hook");
|
||||||
|
|
||||||
const webhookHook = 'https://webhookn8n.innova1001.com.br/webhook/hook';
|
const webhookHook = 'https://webhookn8n.innova1001.com.br/webhook/hook';
|
||||||
@ -135,7 +121,7 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Sucesso!',
|
title: 'Sucesso!',
|
||||||
description: `Grupo "${nomeGrupo}" criado e configurado com sucesso!`,
|
description: `Solicitação para criar grupo "${nomeGrupo}" enviada com sucesso!`,
|
||||||
variant: 'default',
|
variant: 'default',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -151,7 +137,7 @@ export const useGroupCreation = (userEmail: string, onSuccess: () => void) => {
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Erro',
|
title: 'Erro',
|
||||||
description: `Não foi possível criar o grupo: ${errorMsg}`,
|
description: `Não foi possível solicitar criação do grupo: ${errorMsg}`,
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user