Skip to content

Commit

Permalink
fix: Correction in response returns from buttons, lists and templates
Browse files Browse the repository at this point in the history
Fixes the display of unnecessary logs in the webhook controller and updates the way context data is handled in the Whatsapp Business service. Adds private methods to handle different types of messages, such as buttons, reactions and contacts.

Modified files:
- webhook.controller.ts
- whatsapp.business.service.ts
  • Loading branch information
dgcode-tec committed Jul 12, 2024
1 parent c782305 commit 49ad981
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/api/controllers/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class WebhookController {
}

public async receiveWebhook(data: any) {
console.log('webhook/meta', data);
this.webhookService.receiveWebhook(data);

return {
Expand Down
28 changes: 24 additions & 4 deletions src/api/services/channels/whatsapp.business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export class BusinessStartupService extends ChannelStartupService {
return content;
}

private messageButtonJson(received: any) {
const message = received.messages[0];
let content: any = { conversation: received.messages[0].button?.text };
message.context ? (content = { ...content, contextInfo: { stanzaId: message.context.id } }) : content;
return content;
}

private messageReactionJson(received: any) {
const message = received.messages[0];
let content: any = {
Expand Down Expand Up @@ -315,7 +322,7 @@ export class BusinessStartupService extends ChannelStartupService {
...this.messageMediaJson(received),
base64: buffer ? buffer.toString('base64') : undefined,
},
contextInfo: this.messageTextJson(received)?.contextInfo,
contextInfo: this.messageMediaJson(received)?.contextInfo,
messageType: this.renderMessageType(received.messages[0].type),
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
source: 'unknown',
Expand All @@ -328,7 +335,20 @@ export class BusinessStartupService extends ChannelStartupService {
message: {
...this.messageInteractiveJson(received),
},
contextInfo: this.messageTextJson(received)?.contextInfo,
contextInfo: this.messageInteractiveJson(received)?.contextInfo,
messageType: 'conversation',
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
source: 'unknown',
instanceId: this.instanceId,
};
} else if (received?.messages[0].button) {
messageRaw = {
key,
pushName,
message: {
...this.messageButtonJson(received),
},
contextInfo: this.messageButtonJson(received)?.contextInfo,
messageType: 'conversation',
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
source: 'unknown',
Expand All @@ -341,7 +361,7 @@ export class BusinessStartupService extends ChannelStartupService {
message: {
...this.messageReactionJson(received),
},
contextInfo: this.messageTextJson(received)?.contextInfo,
contextInfo: this.messageReactionJson(received)?.contextInfo,
messageType: 'reactionMessage',
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
source: 'unknown',
Expand All @@ -354,7 +374,7 @@ export class BusinessStartupService extends ChannelStartupService {
message: {
...this.messageContactsJson(received),
},
contextInfo: this.messageTextJson(received)?.contextInfo,
contextInfo: this.messageContactsJson(received)?.contextInfo,
messageType: 'conversation',
messageTimestamp: parseInt(received.messages[0].timestamp) as number,
source: 'unknown',
Expand Down

0 comments on commit 49ad981

Please sign in to comment.