Developer Guide: Implementing RedwoodJS WhatsApp Integration Using Plivo - code-examples -

Frequently Asked Questions

Integrate WhatsApp into your RedwoodJS application using the Plivo communications platform. This involves setting up a RedwoodJS project, installing the Plivo SDK, configuring your Plivo account, and implementing the necessary backend and frontend logic to send and receive WhatsApp messages.
Plivo is a cloud communications platform that provides the necessary APIs for sending and receiving WhatsApp messages. It acts as a bridge between your RedwoodJS application and the WhatsApp Business API.
RedwoodJS is chosen for its full-stack capabilities, serverless-friendly nature, and excellent developer experience. It provides conventions, integrated tooling for GraphQL, Prisma, and Jest, making development smoother.
ngrok is essential during local development to create a publicly accessible URL for your RedwoodJS API server, which Plivo's webhook uses to send incoming WhatsApp messages. For production, replace the ngrok URL with your application's stable public URL.
Yes, sending WhatsApp message templates is a key part of this integration. Templates are required for initiating conversations or sending messages outside the 24-hour customer service window and must be pre-approved by Meta.
You send WhatsApp messages by calling the Plivo API from your RedwoodJS backend service. The provided code example demonstrates using the `sendWhatsAppText` function for standard text messages and `sendWhatsAppTemplate` for templated messages. Both functions use the Plivo Node.js SDK to interact with the API.
The webhook acts as a receiver for incoming WhatsApp messages. Plivo sends a POST request to your designated RedwoodJS API endpoint (the webhook) whenever a new message arrives. The webhook processes the incoming message data and can trigger further actions like saving to a database.
Configure your Plivo WhatsApp number's messaging settings to point to your RedwoodJS API endpoint. Use ngrok for local development and your application's public URL for production. Ensure the HTTP Method is set to POST.
Prerequisites include Node.js v18 or later, Yarn v1.x, a Plivo account, a Meta Business Manager account, a phone number for WhatsApp registration, and a basic understanding of RedwoodJS, GraphQL, and Node.js.
Validating Plivo webhook signatures is critical for security. Use the `X-Plivo-Signature-V3` and `X-Plivo-Signature-V3-Nonce` headers, the request URL, and the request body along with your Plivo Auth Token to verify that incoming requests originate from Plivo. Refer to the Plivo documentation for the most up-to-date validation method.
Prisma is used as the Object-Relational Mapper (ORM) in RedwoodJS, enabling convenient interaction with your database. It simplifies database operations, such as creating, reading, updating, and deleting records.
Store your Plivo `AUTH_ID`, `AUTH_TOKEN`, and `PLIVO_WHATSAPP_NUMBER` as environment variables in a `.env` file in the root of your project. This file should be added to your `.gitignore` to prevent committing sensitive information.
Create WhatsApp message templates in your Meta Business Manager under WhatsApp Manager -> Message Templates. You'll need to categorize them and submit them for approval by Meta before you can use them in your application.
WhatsApp message templates are crucial for initiating conversations with users or sending messages outside the 24-hour customer service window. Using pre-approved templates ensures compliance with WhatsApp Business API guidelines.