mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-15 11:42:53 -06:00
Added Typebot integration
This commit is contained in:
parent
201e6f7e7b
commit
6f99784224
@ -27,7 +27,9 @@ function bootstrap() {
|
|||||||
cors({
|
cors({
|
||||||
origin(requestOrigin, callback) {
|
origin(requestOrigin, callback) {
|
||||||
const { ORIGIN } = configService.get<Cors>('CORS');
|
const { ORIGIN } = configService.get<Cors>('CORS');
|
||||||
!requestOrigin ? (requestOrigin = '*') : undefined;
|
if (ORIGIN.includes('*')) {
|
||||||
|
return callback(null, true);
|
||||||
|
}
|
||||||
if (ORIGIN.indexOf(requestOrigin) !== -1) {
|
if (ORIGIN.indexOf(requestOrigin) !== -1) {
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { delay } from '@whiskeysockets/baileys';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
@ -162,13 +163,34 @@ export class TypebotService {
|
|||||||
return request.data;
|
return request.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendWAMessage(instance: InstanceDto, remoteJid: string, messages: any[], input: any[]) {
|
public async sendWAMessage(
|
||||||
processMessages(this.waMonitor.waInstances[instance.instanceName], messages, input).catch((err) => {
|
instance: InstanceDto,
|
||||||
console.error('Erro ao processar mensagens:', err);
|
remoteJid: string,
|
||||||
});
|
messages: any[],
|
||||||
|
input: any[],
|
||||||
|
clientSideActions: any[],
|
||||||
|
) {
|
||||||
|
processMessages(this.waMonitor.waInstances[instance.instanceName], messages, input, clientSideActions).catch(
|
||||||
|
(err) => {
|
||||||
|
console.error('Erro ao processar mensagens:', err);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
async function processMessages(instance, messages, input) {
|
function findItemAndGetSecondsToWait(array, targetId) {
|
||||||
|
if (!array) return null;
|
||||||
|
|
||||||
|
for (const item of array) {
|
||||||
|
if (item.lastBubbleBlockId === targetId) {
|
||||||
|
return item.wait?.secondsToWaitFor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processMessages(instance, messages, input, clientSideActions) {
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
|
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
||||||
|
|
||||||
if (message.type === 'text') {
|
if (message.type === 'text') {
|
||||||
let formattedText = '';
|
let formattedText = '';
|
||||||
|
|
||||||
@ -260,6 +282,10 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wait) {
|
||||||
|
await delay(wait * 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
@ -323,7 +349,7 @@ export class TypebotService {
|
|||||||
pushName: msg.pushName,
|
pushName: msg.pushName,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.sendWAMessage(instance, remoteJid, data.messages, data.input);
|
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -346,7 +372,7 @@ export class TypebotService {
|
|||||||
pushName: msg.pushName,
|
pushName: msg.pushName,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.sendWAMessage(instance, remoteJid, data.messages, data.input);
|
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -414,7 +440,13 @@ export class TypebotService {
|
|||||||
|
|
||||||
const request = await axios.post(url + '/api/v1/sendMessage', reqData);
|
const request = await axios.post(url + '/api/v1/sendMessage', reqData);
|
||||||
|
|
||||||
await this.sendWAMessage(instance, remoteJid, request.data.messages, request.data.input);
|
await this.sendWAMessage(
|
||||||
|
instance,
|
||||||
|
remoteJid,
|
||||||
|
request.data.messages,
|
||||||
|
request.data.input,
|
||||||
|
request.data.clientSideActions,
|
||||||
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user