adjusts in typebot

This commit is contained in:
Davidson Gomes
2024-06-08 19:22:12 -03:00
parent b7a34ec81a
commit ee9cdc51c0
4 changed files with 92 additions and 52 deletions

View File

@@ -935,38 +935,50 @@ export class TypebotService {
formattedText = formattedText.replace(/\n$/, '');
await instance.textMessage({
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
text: formattedText,
});
await instance.textMessage(
{
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
text: formattedText,
},
true,
);
}
if (message.type === 'image') {
await instance.mediaMessage({
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
mediatype: 'image',
media: message.content.url,
});
await instance.mediaMessage(
{
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
mediatype: 'image',
media: message.content.url,
},
true,
);
}
if (message.type === 'video') {
await instance.mediaMessage({
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
mediatype: 'video',
media: message.content.url,
});
await instance.mediaMessage(
{
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
mediatype: 'video',
media: message.content.url,
},
true,
);
}
if (message.type === 'audio') {
await instance.audioWhatsapp({
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
encoding: true,
audio: message.content.url,
});
await instance.audioWhatsapp(
{
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
encoding: true,
audio: message.content.url,
},
true,
);
}
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
@@ -988,11 +1000,14 @@ export class TypebotService {
formattedText = formattedText.replace(/\n$/, '');
await instance.textMessage({
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
text: formattedText,
});
await instance.textMessage(
{
number: remoteJid.split('@')[0],
delay: settings?.delayMessage || 1000,
text: formattedText,
},
true,
);
}
await prismaRepository.typebotSession.update({
@@ -1240,11 +1255,14 @@ export class TypebotService {
if (!content) {
if (unknownMessage) {
this.waMonitor.waInstances[instance.instanceName].textMessage({
number: remoteJid.split('@')[0],
delay: delayMessage || 1000,
text: unknownMessage,
});
this.waMonitor.waInstances[instance.instanceName].textMessage(
{
number: remoteJid.split('@')[0],
delay: delayMessage || 1000,
text: unknownMessage,
},
true,
);
}
return;
}
@@ -1349,11 +1367,14 @@ export class TypebotService {
if (data.messages.length === 0) {
if (!content) {
if (unknownMessage) {
this.waMonitor.waInstances[instance.instanceName].textMessage({
number: remoteJid.split('@')[0],
delay: delayMessage || 1000,
text: unknownMessage,
});
this.waMonitor.waInstances[instance.instanceName].textMessage(
{
number: remoteJid.split('@')[0],
delay: delayMessage || 1000,
text: unknownMessage,
},
true,
);
}
return;
}
@@ -1425,11 +1446,14 @@ export class TypebotService {
if (!content) {
if (unknownMessage) {
this.waMonitor.waInstances[instance.instanceName].textMessage({
number: remoteJid.split('@')[0],
delay: delayMessage || 1000,
text: unknownMessage,
});
this.waMonitor.waInstances[instance.instanceName].textMessage(
{
number: remoteJid.split('@')[0],
delay: delayMessage || 1000,
text: unknownMessage,
},
true,
);
}
return;
}

View File

@@ -74,6 +74,7 @@ export class MessageRouter extends RouterBroker {
return res.status(HttpStatus.CREATED).json(response);
})
// TODO: Revisar funcionamento do envio de Status
.post(this.routerPath('sendStatus'), ...guards, async (req, res) => {
const response = await this.dataValidate<SendStatusDto>({
request: req,

View File

@@ -1672,7 +1672,7 @@ export class BaileysStartupService extends ChannelStartupService {
number: string,
message: T,
options?: Options,
isChatwoot = false,
isIntegration = false,
) {
const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift();
@@ -1890,10 +1890,19 @@ export class BaileysStartupService extends ChannelStartupService {
this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isChatwoot) {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled && !isIntegration) {
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
}
if (this.configService.get<Typebot>('TYPEBOT').ENABLED && !isIntegration) {
if (messageRaw.messageType !== 'reactionMessage')
await this.typebotService.sendTypebot(
{ instanceName: this.instance.name, instanceId: this.instanceId },
messageRaw.key.remoteJid,
messageRaw,
);
}
await this.prismaRepository.message.create({
data: messageRaw,
});
@@ -1966,7 +1975,7 @@ export class BaileysStartupService extends ChannelStartupService {
}
// Send Message Controller
public async textMessage(data: SendTextDto, isChatwoot = false) {
public async textMessage(data: SendTextDto, isIntegration = false) {
const text = data.text;
if (!text || text.trim().length === 0) {
@@ -1988,7 +1997,7 @@ export class BaileysStartupService extends ChannelStartupService {
mentioned: data?.mentioned,
},
},
isChatwoot,
isIntegration,
);
}
@@ -2276,7 +2285,7 @@ export class BaileysStartupService extends ChannelStartupService {
return result;
}
public async mediaMessage(data: SendMediaDto, isChatwoot = false) {
public async mediaMessage(data: SendMediaDto, isIntegration = false) {
const generate = await this.prepareMediaMessage(data);
return await this.sendMessageWithTyping(
@@ -2291,7 +2300,7 @@ export class BaileysStartupService extends ChannelStartupService {
mentioned: data?.mentioned,
},
},
isChatwoot,
isIntegration,
);
}
@@ -2331,7 +2340,7 @@ export class BaileysStartupService extends ChannelStartupService {
});
}
public async audioWhatsapp(data: SendAudioDto, isChatwoot = false) {
public async audioWhatsapp(data: SendAudioDto, isIntegration = false) {
if (!data?.encoding && data?.encoding !== false) {
data.encoding = true;
}
@@ -2348,7 +2357,7 @@ export class BaileysStartupService extends ChannelStartupService {
mimetype: 'audio/mp4',
},
{ presence: 'recording', delay: data?.delay },
isChatwoot,
isIntegration,
);
fs.unlinkSync(convert);
@@ -2367,7 +2376,7 @@ export class BaileysStartupService extends ChannelStartupService {
mimetype: 'audio/ogg; codecs=opus',
},
{ presence: 'recording', delay: data?.delay },
isChatwoot,
isIntegration,
);
}