Frequently Asked Questions
Integrate Infobip WhatsApp with RedwoodJS by setting up a new RedwoodJS project, configuring Infobip credentials as environment variables, implementing a service to handle sending messages, creating a GraphQL mutation to expose the sending functionality, setting up a webhook function to receive incoming messages and delivery reports, and optionally setting up a database schema to log message interactions. This guide uses TypeScript, GraphQL, Prisma, and Node.js to achieve the integration.
ngrok
creates a secure tunnel to your local RedwoodJS development server, making it publicly accessible for receiving webhooks from Infobip. This is necessary because Infobip needs a public URL to send real-time message and delivery report notifications to during development.
Create a RedwoodJS service function that constructs the message payload, including recipient number, template name, placeholders, and language. This function then calls the Infobip API using an HTTP client like fetch
or axios
. You'll need your Infobip API key, base URL, and WhatsApp sender number, all configured as environment variables.
Infobip is an official Business Solution Provider (BSP) for the WhatsApp Business API. They provide the necessary infrastructure and API access to connect your application with the WhatsApp network, enabling you to send and receive messages and manage templates.
RedwoodJS offers a robust, full-stack, serverless framework with built-in features like GraphQL and Prisma, simplifying development and deployment. Its integrated frontend/backend structure streamlines the process of connecting user interfaces with WhatsApp communication flows.
Incoming messages are forwarded from WhatsApp through the Infobip platform to a RedwoodJS function acting as a webhook. This function processes the message, potentially interacts with a database to log the message, and acknowledges receipt to Infobip. Security measures like shared secrets or signature validation protect the webhook.
The guide provides a basic security example using a shared secret passed in an HTTP header. For production, you must implement robust signature validation (e.g., HMAC) according to Infobip's documentation to prevent unauthorized access to your webhook.
You will need Node.js, Yarn, the RedwoodJS CLI, an Infobip account, a registered WhatsApp Sender number, and basic understanding of RedwoodJS, GraphQL, and TypeScript. ngrok
is necessary for local webhook development. An active and approved template on Infobip is required to send templated messages.
InfobipTemplatePlaceholder
is a TypeScript interface defined to enforce the structure of data required by WhatsApp message templates. It ensures that the message sent to the Infobip API contains the correct placeholders for variables like body text, buttons, and headers, which get populated with dynamic values when sending the message.
Yes, the provided code can be extended to send free-form messages. Ensure the free-form messages comply with WhatsApp Business API guidelines and consider that initiating a conversation usually requires a pre-approved message template first, followed by a 24-hour window.
Infobip sends delivery reports (sent, delivered, read, failed) to the same webhook as inbound messages. The webhook handler must distinguish between message types by analyzing the payload structure. You can then update message status in your database based on the delivery reports received.
The guide recommends defining a Prisma schema with a MessageLog
model to store message details (sender, recipient, status, content preview). Update your service and webhook functions to create and update MessageLog
entries when sending and receiving messages and delivery reports. Be mindful of PII when logging content.
While the example uses Node's native fetch
, a dedicated HTTP client like axios
might be beneficial for more complex API interactions, features like interceptors for managing auth tokens or retries, or if you're more familiar with its API.
Use the language code that aligns with your approved WhatsApp message template and your target audience's language. The guide uses 'en' for English, but change this to match your template's language, e.g., 'es' for Spanish, 'fr' for French.
Integrate Infobip WhatsApp Business API with RedwoodJS
This guide provides a step-by-step walkthrough for integrating the Infobip WhatsApp Business API into your RedwoodJS application. You'll learn how to send messages, handle incoming messages via webhooks, manage templates, and set up a robust foundation for production use.
By the end of this tutorial, you will have a RedwoodJS application capable of:
This guide solves the common challenge of connecting a modern full-stack framework like RedwoodJS with a powerful communication channel like WhatsApp, leveraging Infobip as an official WhatsApp Business Solution Provider (BSP).
Technologies Used:
System Architecture Overview:
The system involves the user's WhatsApp application interacting with the WhatsApp network. Messages sent by the user are forwarded by WhatsApp through the Infobip platform to a RedwoodJS Function (webhook). This function processes the message, potentially interacts with a service layer and database (Prisma), and acknowledges receipt. To send messages, the RedwoodJS frontend triggers a GraphQL mutation in the RedwoodJS API. This API calls a service layer function, which interacts with the database and then calls the Infobip WhatsApp API. Infobip delivers the message via the WhatsApp network to the user's device. Delivery reports follow a similar path back from Infobip to the RedwoodJS webhook.
Prerequisites:
yarn global add @redwoodjs/cli
)ngrok
or a similar tunneling service for local webhook development1. RedwoodJS Project Setup for WhatsApp Integration
Initialize a new RedwoodJS project and configure the necessary environment variables for Infobip.
Create RedwoodJS App: Open your terminal and run:
Follow the prompts (choose TypeScript).
Infobip Account Setup & Credentials:
https://<your-unique-id>.api.infobip.com
.Configure Environment Variables: RedwoodJS uses a
.env
file for environment variables. Create this file in the project root:Add your Infobip credentials and sender number:
INFOBIP_WEBHOOK_SECRET
is a simple shared secret for basic webhook validation. For production, implement HMAC signature validation as described in Infobip's webhook security documentation.env
to your.gitignore
file to prevent committing secrets. RedwoodJS does this by default, but always verifyInstall Dependencies (Optional – HTTP Client): Node's native
fetch
is sufficient for this guide. If you preferaxios
for complex scenarios:2. Implementing Core Functionality: Sending WhatsApp Messages
Create a RedwoodJS service on the API side to encapsulate the logic for interacting with the Infobip API.
Generate Infobip Service:
This creates
api/src/services/infobip/infobip.ts
and related test files.Implement
sendTemplateMessage
Function: Sending pre-approved template messages is often the starting point, especially for initiating conversations outside the 24-hour customer service window.Open
api/src/services/infobip/infobip.ts
and add the following code:Explanation:
InfobipTemplatePlaceholder
,InfobipSendMessagePayload
,InfobipSendResponse
) are defined based on Infobip's API documentation. AdjustInfobipTemplatePlaceholder
based on the actual placeholders your specific templates require (body text, button parameters, header variables, etc.).process.env
callInfobipApi
helper function handles constructing the request (URL, headers, authorization, body) and basic error checking/logging. Crucially, it uses theAuthorization: App YOUR_API_KEY
header format specified by InfobipsendTemplateMessage
constructs the specific payload for the/whatsapp/1/message/template
endpoint and calls the helper functionsrc/lib/logger
) for debugging3. Building the API Layer (GraphQL Mutation for WhatsApp)
Expose the
sendTemplateMessage
functionality through a GraphQL mutation so your frontend (or other services) can trigger it.Define GraphQL Schema: Open
api/src/graphql/infobip.sdl.ts
(create it if it doesn't exist) and define the mutation:Explanation:
InfobipTemplateDataInput
, etc.) to structure the data passed into the mutation. Make these specific to match theInfobipTemplatePlaceholder
interface in your service and the requirements of your actual templatesInfobipSendResponse
, etc.) to match the expected structure returned by thesendTemplateMessage
service functionsendWhatsAppTemplate
mutation takes the necessary arguments@requireAuth
(or a more specific roles-based directive) should be added to protect this mutation. This guide doesn't implement the auth logic itself, but it's crucial for productionImplement Mutation Resolver: RedwoodJS automatically maps the
sendWhatsAppTemplate
mutation to thesendTemplateMessage
function in theapi/src/services/infobip/infobip.ts
service because the names match. No extra resolver code is needed for this mapping.Testing the Mutation:
yarn rw dev
http://localhost:8911/graphql
)templateName
used below ("welcome_multiple_languages"
) is just an example. Replace this with the exact name of an active, approved template associated with your Infobip sender number. Ensure thetemplateData
matches the placeholders defined in your specific template.4. Webhook Integration for Inbound WhatsApp Messages
To receive messages sent to your WhatsApp number or get delivery status updates, Infobip needs to send HTTP requests (webhooks) to your application. Use a RedwoodJS Function for this.
Generate Webhook Function:
This creates
api/src/functions/inboundWebhook.ts
.Implement Webhook Handler: Open
api/src/functions/inboundWebhook.ts
and add the handler logic:Explanation:
x-webhook-secret
). This is minimal security. For production, implement HMAC signature validation using Infobip'sX-Hub-Signature
header. Reference: Infobip Webhook Securityresults
array structurefrom
,receivedAt
vs.sentAt
,status
). Consult actual payloads from Infobip and their documentation to adjust this logic accurately// TODO:
) indicate where you'd add your application-specific logic (database interaction, notifications, etc.)200 OK
status code to Infobip upon successful processing, or appropriate error codes (401, 400, 500). Infobip generally expects a 2xx response to consider the webhook deliveredExpose Webhook Locally with ngrok: Infobip needs a publicly accessible URL to send webhooks to. During development,
ngrok
creates a secure tunnel to your local machine.yarn rw dev
(Note the API server port, usually 8911)ngrok
will display forwarding URLs (e.g.,https://<random-string>.ngrok.io
). Copy thehttps
URL.Configure Webhook in Infobip:
ngrok
HTTPS URL, appending the path to your Redwood function:/inboundWebhook
. The full URL will be:https://<random-string>.ngrok.io/api/functions/inboundWebhook
x-webhook-secret
(or your chosen name) with the value set to yourINFOBIP_WEBHOOK_SECRET
from the.env
file. For production, configure HMAC signature validation following Infobip's documentationTesting the Webhook:
yarn rw dev
and the terminal runningngrok
. You should see log output from yourinboundWebhook
function indicating it received and processed the message.5. Error Handling, Logging, and Retry Mechanisms
Error Handling:
callInfobipApi
helper includes basictry…catch
blocks and checks the HTTP response status. Expand this to handle specific Infobip error codes or messages if needed (refer to Infobip API documentation for error details)try…catch
and returns appropriate HTTP status codes (4xx for client errors/bad data, 500 for server errors). Infobip may retry webhooks on receiving 5xx errors or timeoutsLogging:
src/lib/logger
) is used extensively. Use different log levels (debug
,info
,warn
,error
) appropriatelyRetry Mechanisms (API Calls):
callInfobipApi
function using libraries likeasync-retry
or a manual loop with exponential backoff. Be cautious not to retry excessively for errors that are unlikely to resolve (e.g., invalid API key, malformed request)6. Database Schema and Data Layer (Optional but Recommended)
Storing message logs helps with tracking, debugging, and analytics.
Define Prisma Schema: Open
api/db/schema.prisma
and add a model:Run Migration:
Update Services/Functions to Use DB:
api/src/services/infobip/infobip.ts
(sendTemplateMessage
), after a successful API call, create aMessageLog
entryapi/src/functions/inboundWebhook.ts
, inside the loop processing results, create or updateMessageLog
entries for inbound messages and delivery reportsFrequently Asked Questions (FAQ)
How do I get a WhatsApp Business number for Infobip?
Log in to your Infobip account and navigate to the WhatsApp section. For development, Infobip provides shared test sender numbers that you can activate by sending a specific keyword from your personal WhatsApp. For production, you'll need to register your own business number through the Infobip onboarding process, which requires Meta (Facebook) approval and typically takes 1-2 weeks.
What is the 24-hour customer service window for WhatsApp?
WhatsApp Business API enforces a 24-hour customer service window. You can only send free-form messages to users who have messaged you within the last 24 hours. Outside this window, you must use pre-approved message templates. This window resets each time the user sends you a message.
How do I create and approve WhatsApp message templates?
Create templates in your Infobip portal under the WhatsApp templates section. Templates must follow WhatsApp's guidelines and include placeholders for dynamic content. Submit templates for Meta's approval – this process typically takes 1-2 business days. Only approved templates can be used to initiate conversations outside the 24-hour window.
Why is my webhook not receiving messages?
Common issues include: (1) Your webhook URL is not publicly accessible – ensure ngrok is running during development, (2) The webhook is not configured correctly in Infobip portal – verify the URL includes the correct path
/api/functions/inboundWebhook
, (3) Security headers don't match – ensure yourx-webhook-secret
matches between.env
and Infobip configuration, or (4) Your webhook is returning an error status code – check your application logs.Can I send media files (images, documents, videos) via WhatsApp?
Yes, Infobip supports sending media through the WhatsApp API. You'll need to implement additional service functions for media messages using the
/whatsapp/1/message/image
,/whatsapp/1/message/document
, and/whatsapp/1/message/video
endpoints. Media files can be sent via URL or uploaded directly to Infobip's servers.How do I implement HMAC signature validation for webhooks?
For production, replace the basic shared secret validation with HMAC-SHA256 signature validation. Infobip sends a
X-Hub-Signature
header with each webhook request. Compute the HMAC-SHA256 hash of the request body using your webhook secret as the key, and compare it to the signature in the header. Reference: Infobip Webhook Security DocumentationWhat are the rate limits for Infobip WhatsApp API?
Rate limits vary based on your Infobip account tier and the Meta-approved messaging throughput for your WhatsApp Business number. New numbers typically start with lower limits (e.g., 1,000 messages per day) that increase based on message quality and user engagement. Check your Infobip account dashboard for your specific limits and contact support to request increases.
Next Steps and Additional Resources
After implementing your RedwoodJS + Infobip WhatsApp integration, consider these enhancements:
For more information, consult: