Revert "Start Typebot com opção de ativar chatbot ou não"

This commit is contained in:
Davidson Gomes 2023-10-02 19:10:34 +00:00 committed by GitHub
parent 99f3e77c12
commit 6fc37a4298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,7 +99,6 @@ export class TypebotService {
const remoteJid = data.remoteJid; const remoteJid = data.remoteJid;
const url = data.url; const url = data.url;
const typebot = data.typebot; const typebot = data.typebot;
const enabled_typebot = data.enabled_typebot;
const variables = data.variables; const variables = data.variables;
const findTypebot = await this.find(instance); const findTypebot = await this.find(instance);
const sessions = (findTypebot.sessions as Session[]) ?? []; const sessions = (findTypebot.sessions as Session[]) ?? [];
@ -117,13 +116,8 @@ export class TypebotService {
prefilledVariables[variable.name] = variable.value; prefilledVariables[variable.name] = variable.value;
}); });
if (enabled_typebot !== false ) { const response = await this.createNewSession(instance, {
let enabled_typebot = true;
const response = await this.createNewSession(instance, {
url: url, url: url,
enabled_typebot: enabled_typebot,
typebot: typebot, typebot: typebot,
remoteJid: remoteJid, remoteJid: remoteJid,
expire: expire, expire: expire,
@ -147,7 +141,6 @@ const response = await this.createNewSession(instance, {
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, { this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
remoteJid: remoteJid, remoteJid: remoteJid,
url: url, url: url,
enabled_typebot: enabled_typebot,
typebot: typebot, typebot: typebot,
prefilledVariables: prefilledVariables, prefilledVariables: prefilledVariables,
sessionId: `${response.sessionId}`, sessionId: `${response.sessionId}`,
@ -156,44 +149,10 @@ const response = await this.createNewSession(instance, {
throw new Error("Session ID not found in response"); 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,
});
}
return { return {
typebot: { typebot: {
...instance, ...instance,
typebot: { typebot: {
enabled_typebot: enabled_typebot,
url: url, url: url,
remoteJid: remoteJid, remoteJid: remoteJid,
typebot: typebot, typebot: typebot,
@ -545,6 +504,7 @@ const id = Math.floor(Math.random() * 10000000000).toString();
sessions.splice(sessions.indexOf(session), 1); sessions.splice(sessions.indexOf(session), 1);
const typebotData = { const typebotData = {
enabled: true,
url: url, url: url,
typebot: typebot, typebot: typebot,
expire: expire, expire: expire,