Skip to content

Commit 99f3e77

Browse files
Merge pull request #154 from francisbreit/evolution-api-1.5.2-develop-francis
Start Typebot com opção de ativar chatbot ou não
2 parents 5c74cbf + 3f43330 commit 99f3e77

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/whatsapp/services/typebot.service.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class TypebotService {
9999
const remoteJid = data.remoteJid;
100100
const url = data.url;
101101
const typebot = data.typebot;
102+
const enabled_typebot = data.enabled_typebot;
102103
const variables = data.variables;
103104
const findTypebot = await this.find(instance);
104105
const sessions = (findTypebot.sessions as Session[]) ?? [];
@@ -116,8 +117,13 @@ export class TypebotService {
116117
prefilledVariables[variable.name] = variable.value;
117118
});
118119

119-
const response = await this.createNewSession(instance, {
120+
if (enabled_typebot !== false ) {
121+
let enabled_typebot = true;
122+
123+
124+
const response = await this.createNewSession(instance, {
120125
url: url,
126+
enabled_typebot: enabled_typebot,
121127
typebot: typebot,
122128
remoteJid: remoteJid,
123129
expire: expire,
@@ -141,18 +147,53 @@ export class TypebotService {
141147
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
142148
remoteJid: remoteJid,
143149
url: url,
150+
enabled_typebot: enabled_typebot,
144151
typebot: typebot,
145152
prefilledVariables: prefilledVariables,
146153
sessionId: `${response.sessionId}`,
147154
});
148155
} else {
149156
throw new Error("Session ID not found in response");
150157
}
158+
159+
} else {
160+
161+
const id = Math.floor(Math.random() * 10000000000).toString();
162+
163+
const reqData = {
164+
sessionId: id,
165+
startParams: {
166+
typebot: data.typebot,
167+
prefilledVariables: prefilledVariables,
168+
},
169+
};
170+
171+
const request = await axios.post(data.url + '/api/v1/sendMessage', reqData);
172+
173+
await this.sendWAMessage(
174+
instance,
175+
remoteJid,
176+
request.data.messages,
177+
request.data.input,
178+
request.data.clientSideActions,
179+
);
180+
181+
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_START, {
182+
remoteJid: remoteJid,
183+
url: url,
184+
typebot: typebot,
185+
variables: variables,
186+
sessionId: id,
187+
});
188+
189+
190+
}
151191

152192
return {
153193
typebot: {
154194
...instance,
155195
typebot: {
196+
enabled_typebot: enabled_typebot,
156197
url: url,
157198
remoteJid: remoteJid,
158199
typebot: typebot,
@@ -504,7 +545,6 @@ export class TypebotService {
504545
sessions.splice(sessions.indexOf(session), 1);
505546

506547
const typebotData = {
507-
enabled: true,
508548
url: url,
509549
typebot: typebot,
510550
expire: expire,

0 commit comments

Comments
 (0)