Examples & Use Cases
Ready-to-use code snippets for the most common transactional messaging patterns. These examples demonstrate sending emails and WhatsApp messages for critical business events.
1. OTP Delivery (One-Time Password)
Send a secure OTP via WhatsApp with a 5-minute expiration.
await cp.whatsapp.messages.send({ to: '+1234567890', type: 'template', template: { name: 'otp_auth', language: { code: 'en_US' }, components: [ { type: 'body', parameters: [{ type: 'text', text: '849201' }] }, { type: 'button', sub_type: 'url', index: 0, parameters: [{ type: 'text', text: '849201' }] } ] }});2. Order Notifications
Send an order confirmation email with a styled HTML receipt.
await cp.emails.send({ from: 'orders@yourstore.com', to: ['customer@gmail.com'], subject: 'Order #9928 Confirmed', html: '<h1>Thanks for your order!</h1><p>Your package will ship in 24 hours.</p>', tags: ['ecommerce', 'receipt']});3. Password Reset
A high-priority email with a secure reset link.
await cp.emails.send({ from: 'security@myapp.com', to: ['user@example.com'], subject: 'Reset your password', html: '<p>Click <a href="https://myapp.com/reset?token=xyz">here</a> to reset your password.</p>', priority: 'high'});4. Invoice Delivery
Send an email with a PDF invoice attached.
import fs from 'fs';const invoicePdf = fs.readFileSync('./invoice_102.pdf').toString('base64');await cp.emails.send({ from: 'billing@saas.com', to: ['client@corp.com'], subject: 'Invoice for October', html: '<p>Please find your invoice attached.</p>', attachments: [ { filename: 'invoice_102.pdf', content: invoicePdf, type: 'application/pdf' } ]});5. Appointment Reminders
Send an interactive WhatsApp message with RSVP buttons 24 hours before an appointment.
await cp.whatsapp.messages.send({ to: '+1234567890', type: 'interactive', interactive: { type: 'button', body: { text: 'You have a dentist appointment tomorrow at 10:00 AM.' }, action: { buttons: [ { type: 'reply', reply: { id: 'confirm', title: 'Confirm' } }, { type: 'reply', reply: { id: 'cancel', title: 'Cancel' } } ] } }});