Skip to content

Commit dd7d91c

Browse files
committed
refactor: guard cta_url fields and drop no-op ternary
Address review: use an if for the quoted context instead of the no-op ternary, only treat a url button as cta_url when it actually has a url, and fall back display_text to the url when displayText is absent.
1 parent f7303e1 commit dd7d91c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/api/integrations/channel/meta/whatsapp.business.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,17 @@ export class BusinessStartupService extends ChannelStartupService {
11751175
action: {
11761176
name: 'cta_url',
11771177
parameters: {
1178-
display_text: ctaUrlButton.displayText,
1178+
display_text: ctaUrlButton.displayText ?? ctaUrlButton.url,
11791179
url: ctaUrlButton.url,
11801180
},
11811181
},
11821182
},
11831183
};
1184-
quoted ? (content.context = { message_id: quoted.id }) : content;
1184+
if (quoted) {
1185+
content.context = { message_id: quoted.id };
1186+
}
11851187
message = {
1186-
conversation: `${message['text'] || 'Select'}\n▶️ ${ctaUrlButton.displayText}: ${ctaUrlButton.url}\n`,
1188+
conversation: `${message['text'] || 'Select'}\n▶️ ${ctaUrlButton.displayText ?? ctaUrlButton.url}: ${ctaUrlButton.url}\n`,
11871189
};
11881190
return await this.post(content, 'messages');
11891191
}
@@ -1565,7 +1567,7 @@ export class BusinessStartupService extends ChannelStartupService {
15651567
{
15661568
text: !embeddedMedia?.mediaKey ? data.title : undefined,
15671569
buttons: data.buttons.map((button) => {
1568-
if (button.type === 'url') {
1570+
if (button.type === 'url' && button.url) {
15691571
return {
15701572
type: 'cta_url',
15711573
displayText: button.displayText,

0 commit comments

Comments
 (0)