Contextual replies allow you to respond to specific messages, creating clear conversation threads by referencing previous messages. This feature enhances the user experience by providing context and maintaining organized conversations.
When you send a contextual reply, WhatsApp displays the original message above your response, making it clear which message you’re responding to. This is especially useful in group conversations or when responding to older messages.Visual Example:
[Original Message from User]📸 Here's the photo you requested[Your Reply - displayed with context]↳ Thanks! This looks perfect.
All messages now extend the BaseMessage interface which includes optional context:
export interface BaseMessage { messaging_product: 'whatsapp'; recipient_type: 'individual'; to: string; context?: { message_id: string; // ID of the message you're replying to };}
import { WhatsAppClient } from 'whatsapp-client-sdk';const client = new WhatsAppClient(accessToken, phoneNumberId);// Reply to a specific messageawait client.replyToMessage( '+1234567890', 'wamid.HBgLMTY1MDM4Nzk0MzkVAgARGBJDQjZCMzlEQUE4OTJCMTE4RTUA', 'Thanks for your message!');
// Reply with an imageawait client.replyWithImage( '+1234567890', messageId, { link: 'https://example.com/response-image.jpg', caption: 'Here\'s the image you requested' });// Reply with a documentawait client.replyWithDocument( '+1234567890', messageId, { link: 'https://example.com/document.pdf', filename: 'requested-document.pdf', caption: 'Here\'s the document you asked for' });
// ✅ Good: Reply to specific user queriesawait client.replyToMessage(userPhone, userQuestionId, answer);// ✅ Good: Acknowledge important informationawait client.replyWithButtons(userPhone, orderMessageId, 'Confirm order?', buttons);// ❌ Avoid: Replying to your own messages// ❌ Avoid: Excessive contextual replies in automated flows
// ✅ Good: Natural conversation threadingasync function handleOrderInquiry(message) { // First, acknowledge the question await client.replyToMessage( message.from, message.id, 'Let me check your order status...' ); // Then provide detailed response setTimeout(async () => { await client.sendText( message.from, 'Your order #12345 has been shipped and will arrive tomorrow.' ); }, 2000);}
// Before: Regular messageawait client.sendText('+1234567890', 'Thanks for your message!');// After: Contextual replyawait client.replyToMessage('+1234567890', messageId, 'Thanks for your message!');// Or using options parameterawait client.sendText( '+1234567890', 'Thanks for your message!', { replyToMessageId: messageId });