mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 10:28:38 -06:00
Start Typebot com opcao de ativar chatbot ou não. -Update typebot.service.ts
Criada variável enabled_typebot . Se setada como true, o flow disparado é ativado como chatbot (original do Typebot), porém se false, dispara apenas como se fosse uma notificação e nao ativa o bot.
This commit is contained in:
parent
bddd6408ac
commit
f0ff4873b5
@ -99,6 +99,8 @@ export class TypebotService {
|
||||
const remoteJid = data.remoteJid;
|
||||
const url = data.url;
|
||||
const typebot = data.typebot;
|
||||
// linha incluida por Francis:
|
||||
const enabled_typebot = data.enabled_typebot;
|
||||
const variables = data.variables;
|
||||
const findTypebot = await this.find(instance);
|
||||
const sessions = (findTypebot.sessions as Session[]) ?? [];
|
||||
@ -115,9 +117,13 @@ export class TypebotService {
|
||||
variables.forEach((variable) => {
|
||||
prefilledVariables[variable.name] = variable.value;
|
||||
});
|
||||
// linha incluida por Francis:
|
||||
if (enabled_typebot === true) {
|
||||
|
||||
const response = await this.createNewSession(instance, {
|
||||
const response = await this.createNewSession(instance, {
|
||||
url: url,
|
||||
// linha incluida por Francis:
|
||||
enabled_typebot: enabled_typebot,
|
||||
typebot: typebot,
|
||||
remoteJid: remoteJid,
|
||||
expire: expire,
|
||||
@ -141,6 +147,8 @@ export class TypebotService {
|
||||
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
|
||||
remoteJid: remoteJid,
|
||||
url: url,
|
||||
// linha incluida por Francis:
|
||||
enabled_typebot: enabled_typebot,
|
||||
typebot: typebot,
|
||||
prefilledVariables: prefilledVariables,
|
||||
sessionId: `${response.sessionId}`,
|
||||
@ -149,10 +157,48 @@ export class TypebotService {
|
||||
throw new Error("Session ID not found in response");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
const id = Math.floor(Math.random() * 10000000000).toString();
|
||||
|
||||
const reqData = {
|
||||
sessionId: id,
|
||||
startParams: {
|
||||
typebot: data.typebot,
|
||||
prefilledVariables: prefilledVariables,
|
||||
},
|
||||
};
|
||||
|
||||
const request = await axios.post(data.url + '/api/v1/sendMessage', reqData);
|
||||
|
||||
await this.sendWAMessage(
|
||||
instance,
|
||||
remoteJid,
|
||||
request.data.messages,
|
||||
request.data.input,
|
||||
request.data.clientSideActions,
|
||||
);
|
||||
|
||||
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
|
||||
remoteJid: remoteJid,
|
||||
url: url,
|
||||
typebot: typebot,
|
||||
variables: variables,
|
||||
sessionId: id,
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ate aqui
|
||||
|
||||
return {
|
||||
typebot: {
|
||||
...instance,
|
||||
typebot: {
|
||||
// linha incluida por Francis:
|
||||
enabled_typebot: enabled_typebot,
|
||||
url: url,
|
||||
remoteJid: remoteJid,
|
||||
typebot: typebot,
|
||||
@ -231,7 +277,8 @@ export class TypebotService {
|
||||
});
|
||||
|
||||
const typebotData = {
|
||||
enabled: true,
|
||||
// linha incluida por Francis:
|
||||
enabled: data.enabled_typebot,
|
||||
url: data.url,
|
||||
typebot: data.typebot,
|
||||
expire: data.expire,
|
||||
@ -469,7 +516,6 @@ export class TypebotService {
|
||||
});
|
||||
|
||||
const typebotData = {
|
||||
enabled: true,
|
||||
url: url,
|
||||
typebot: typebot,
|
||||
expire: expire,
|
||||
@ -504,7 +550,6 @@ export class TypebotService {
|
||||
sessions.splice(sessions.indexOf(session), 1);
|
||||
|
||||
const typebotData = {
|
||||
enabled: true,
|
||||
url: url,
|
||||
typebot: typebot,
|
||||
expire: expire,
|
||||
|
Loading…
Reference in New Issue
Block a user