Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/app/api/whatsapp/webhook/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface WhatsAppMessage {
button_reply?: { id: string; title: string }
list_reply?: { id: string; title: string; description?: string }
}
button?: { payload?: string; text?: string }
/** Present when the customer swipe-replies to one of our messages. */
context?: { id: string }
}
Expand Down Expand Up @@ -653,7 +654,9 @@ async function processMessage(
? message.type
: message.type === 'sticker'
? 'image' // stickers are images
: 'text' // reaction, unknown → text fallback
: message.type === 'button'
? 'interactive' // quick replies are interactive button replies
: 'text' // reaction, unknown → text fallback

// Determine whether this is the contact's very first inbound message
// BEFORE we insert, so the count is accurate. Covers the case where
Expand Down Expand Up @@ -963,6 +966,17 @@ async function parseMessageContent(
return { ...empty, contentText: '[Interactive reply]' }
}

case 'button': {
if (message.button) {
return {
...empty,
contentText: message.button.text || null,
interactiveReplyId: message.button.payload || null,
}
}
return empty
}

default:
return {
...empty,
Expand Down
7 changes: 7 additions & 0 deletions src/components/contacts/contact-detail-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ export function ContactDetailView({
) {
if (!contactId) return;
setSendingTemplate(true);
const renderedBody = template.body_text.replace(/\{\{(\d+)\}\}/g, (_, raw) => {
const idx = Number(raw) - 1;
return values.body[idx] || `{{${raw}}}`;
});

try {
const res = await fetch('/api/whatsapp/send', {
method: 'POST',
Expand All @@ -344,9 +349,11 @@ export function ContactDetailView({
template_message_params: {
body: values.body,
headerText: values.headerText,
headerMediaUrl: values.headerMediaUrl,
buttonParams: values.buttonParams,
},
template_params: values.body,
content_text: renderedBody,
}),
});

Expand Down
Loading