Skip to content

Commit

Permalink
Merge branch 'release/1.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Apr 3, 2024
2 parents b87558d + 324dc01 commit 128119d
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 28 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 1.7.1 (2024-04-03 10:19)

### Fixed

* Correction when sending files with captions on Whatsapp Business
* Correction in receiving messages with response on WhatsApp Business
* Correction when sending a reaction to a message on WhatsApp Business
* Correction of receiving reactions on WhatsApp business
* Removed mandatory description of rows from sendList
* Feature to collect message type in typebot

# 1.7.0 (2024-03-11 18:23)

### Feature
Expand Down
2 changes: 1 addition & 1 deletion src/validate/validate.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export const listMessageSchema: JSONSchema7 = {
description: { type: 'string' },
rowId: { type: 'string' },
},
required: ['title', 'description', 'rowId'],
required: ['title', 'rowId'],
...isNotEmpty('title', 'description', 'rowId'),
},
},
Expand Down
1 change: 1 addition & 0 deletions src/whatsapp/dto/typebot.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class Session {
export class PrefilledVariables {
remoteJid?: string;
pushName?: string;
messageType?: string;
additionalData?: { [key: string]: any };
}

Expand Down
129 changes: 118 additions & 11 deletions src/whatsapp/services/typebot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,27 @@ export class TypebotService {
}

private getTypeMessage(msg: any) {
this.logger.verbose('get type message');

const types = {
conversation: msg.conversation,
extendedTextMessage: msg.extendedTextMessage?.text,
responseRowId: msg.listResponseMessage?.singleSelectReply?.selectedRowId,
};

this.logger.verbose('type message: ' + types);
this.logger.verbose('get type message');
const types = {
conversation: msg.conversation,
extendedTextMessage: msg.extendedTextMessage?.text,
audioMessage: msg.audioMessage?.url,
imageMessage: msg.imageMessage?.url,
videoMessage: msg.videoMessage?.url,
documentMessage: msg.documentMessage?.fileName,
contactMessage: msg.contactMessage?.displayName,
locationMessage: msg.locationMessage?.degreesLatitude,
viewOnceMessageV2: msg.viewOnceMessageV2?.message?.imageMessage?.url || msg.viewOnceMessageV2?.message?.videoMessage?.url || msg.viewOnceMessageV2?.message?.audioMessage?.url,
listResponseMessage: msg.listResponseMessage?.singleSelectReply?.selectedRowId,
responseRowId: msg.listResponseMessage?.singleSelectReply?.selectedRowId,
};

return types;
const messageType = Object.keys(types).find(key => types[key] !== undefined) || 'unknown';

this.logger.verbose('Type message: ' + JSON.stringify(types));
return { ...types, messageType };
}

private getMessageContent(types: any) {
this.logger.verbose('get message content');
const typeKey = Object.keys(types).find((key) => types[key] !== undefined);
Expand All @@ -305,6 +313,101 @@ export class TypebotService {
return messageContent;
}

private getAudioMessageContent(msg: any) {
this.logger.verbose('get audio message content');

const types = this.getTypeMessage(msg);

const audioContent = types.audioMessage;

this.logger.verbose('audio message URL: ' + audioContent);

return audioContent;
}

private getImageMessageContent(msg: any) {
this.logger.verbose('get image message content');

const types = this.getTypeMessage(msg);

const imageContent = types.imageMessage;

this.logger.verbose('image message URL: ' + imageContent);

return imageContent;
}

private getVideoMessageContent(msg: any) {
this.logger.verbose('get video message content');

const types = this.getTypeMessage(msg);

const videoContent = types.videoMessage;

this.logger.verbose('video message URL: ' + videoContent);

return videoContent;
}

private getDocumentMessageContent(msg: any) {
this.logger.verbose('get document message content');

const types = this.getTypeMessage(msg);

const documentContent = types.documentMessage;

this.logger.verbose('document message fileName: ' + documentContent);

return documentContent;
}

private getContactMessageContent(msg: any) {
this.logger.verbose('get contact message content');

const types = this.getTypeMessage(msg);

const contactContent = types.contactMessage;

this.logger.verbose('contact message displayName: ' + contactContent);

return contactContent;
}

private getLocationMessageContent(msg: any) {
this.logger.verbose('get location message content');

const types = this.getTypeMessage(msg);

const locationContent = types.locationMessage;

this.logger.verbose('location message degreesLatitude: ' + locationContent);

return locationContent;
}

private getViewOnceMessageV2Content(msg: any) {
this.logger.verbose('get viewOnceMessageV2 content');

const types = this.getTypeMessage(msg);

const viewOnceContent = types.viewOnceMessageV2;

this.logger.verbose('viewOnceMessageV2 URL: ' + viewOnceContent);

return viewOnceContent;
}

private getListResponseMessageContent(msg: any) {
this.logger.verbose('get listResponseMessage content');

const types = this.getTypeMessage(msg);

const listResponseContent = types.listResponseMessage || types.responseRowId;

this.logger.verbose('listResponseMessage selectedRowId: ' + listResponseContent);

return listResponseContent;
}
public async createNewSession(instance: InstanceDto, data: any) {
if (data.remoteJid === 'status@broadcast') return;
const id = Math.floor(Math.random() * 10000000000).toString();
Expand Down Expand Up @@ -565,6 +668,7 @@ export class TypebotService {
const delay_message = findTypebot.delay_message;
const unknown_message = findTypebot.unknown_message;
const listening_from_me = findTypebot.listening_from_me;
const messageType = this.getTypeMessage(msg.message).messageType;

const session = sessions.find((session) => session.remoteJid === remoteJid);

Expand Down Expand Up @@ -687,6 +791,9 @@ export class TypebotService {
sessions: sessions,
remoteJid: remoteJid,
pushName: msg.pushName,
prefilledVariables: {
messageType: messageType,
},
});

await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
Expand Down
Loading

0 comments on commit 128119d

Please sign in to comment.