Frequently Asked Questions
Use the Vonage SMS API with the Node.js SDK and the Express framework. Set up an Express server with an endpoint to handle incoming requests, validate input, and send messages using the SDK's vonage.sms.send
method. Initialize the Vonage SDK with API credentials from environment variables.
The Vonage API, accessed via its Node.js SDK, enables sending SMS messages, receiving inbound SMS, making and receiving calls, and more. It's a Communication Platform as a Service (CPaaS) that simplifies integrating communication functionalities into Node.js applications.
Dotenv loads environment variables from a .env
file into process.env
, allowing you to store sensitive data like Vonage API keys outside your codebase. This enhances security by preventing accidental exposure of credentials in version control.
A database is not strictly required for basic SMS sending through Vonage. A database becomes useful when you need to store message logs for analytics or auditing, manage scheduled messages, keep track of user preferences, or handle delivery receipts and callbacks.
Yes, Vonage supports alphanumeric sender IDs (like "MyBrand") for enhanced branding. However, support and regulations vary by country and carrier. Some countries don't allow them, and they often can't receive replies. Always verify compatibility with Vonage's documentation and local regulations.
Store your Vonage API Key, API Secret, and virtual number in a .env
file. Use the dotenv
package to load these variables into process.env
within your Node.js application. Then, use these environment variables to initialize the Vonage Node.js SDK client.
A Vonage virtual number is a phone number you purchase through Vonage that can be used as a sender ID for your SMS messages. This gives a recognizable and consistent identity to your outgoing communications.
Wrap the Vonage API call within a try...catch
block in your Express route handler. Log the error for debugging, and return an appropriate error response (e.g., 500 status code) to the client with a descriptive message derived from the caught error object.
A typical project structure includes an index.js
as the main entry point for the Express server, a vonageService.js
module to encapsulate Vonage SDK interactions, a .env
file for credentials, and a .gitignore
file for excluding sensitive files from version control.
This error usually occurs with trial Vonage accounts. Add the recipient's phone number to your whitelisted test numbers in the Vonage Dashboard. Vonage will send a verification code; enter it in the dashboard to whitelist the number.
The express.json()
middleware is crucial for parsing incoming requests with a JSON payload (Content-Type: application/json). It parses the request body and makes the data available in req.body
within your Express route handlers.
Use a library like libphonenumber-js
for robust phone number validation. This ensures the numbers are in a valid format (ideally E.164) and can help prevent issues with sending messages to invalid numbers. Basic format validation within the API handler also provides another layer of filtering.
Standard SMS messages have limits (160 for GSM-7 encoding, 70 for UCS-2 if using extended characters). Vonage handles segmentation for longer messages automatically, but be mindful of costs as each segment is billed.
Vonage's SMS API uses '0' to indicate a successfully submitted message. Any other status code represents an error that requires investigation, even if the HTTP request to the API is successful.
Sinch WhatsApp Integration: Next.js + Supabase Complete Guide
Learn how to build a production-ready WhatsApp Business messaging application using the Sinch Conversation API, Next.js 15, and Supabase. This comprehensive tutorial covers user authentication, sending and receiving WhatsApp messages, secure webhook handling, PostgreSQL database integration, real-time updates, and production deployment.
Learning outcomes: By completing this guide, you will build a full-stack WhatsApp messaging application with user authentication, message persistence, real-time updates, secure webhook handling, and production deployment capabilities. Estimated time: 3-4 hours.
Related guides: Looking for other messaging integrations? Check out our guides for Twilio WhatsApp with Next.js, MessageBird WhatsApp integration, and Plivo WhatsApp messaging.
What You'll Build: WhatsApp Messaging Platform Overview
What We're Building:
A full-stack WhatsApp Business messaging application with:
Problem Solved:
This integration enables businesses to leverage WhatsApp's 2.7+ billion active users for customer communication, support, notifications, and engagement through a unified, scalable platform managed via the Sinch Conversation API.
Technologies Used:
System Architecture:
Prerequisites:
node --version
Prerequisites Verification:
Final Outcome:
A production-ready WhatsApp messaging application with authenticated users, persistent message storage in Supabase, real-time UI updates, secure webhook handling with signature verification, 24-hour window tracking, and template message support for conversation initiation.
1. Setting Up Your Next.js 15 WhatsApp Project
Initialize your Next.js 15 project with TypeScript and configure Supabase integration.
1.1. Create Next.js Project
When prompted:
src/
directory: Yes1.2. Install Dependencies
Dependency Notes:
@supabase/ssr
is the current recommended package (replaces deprecated@supabase/auth-helpers-nextjs
)axios
provides cleaner error handling and interceptors compared to nativefetch
zod
enables runtime environment variable validation1.3. Project Structure
Create the following directory structure:
1.4. Environment Variables
Create
.env.local
in the project root:Where to find these values:
us
oreu
depending on where your Conversation API app was created1.5. Environment Validation (Optional but Recommended)
Create
src/lib/env.ts
:This validates environment variables at startup, providing clear error messages if any are missing or invalid.
2. Configuring PostgreSQL Database Schema for WhatsApp Messages
Design and implement the PostgreSQL schema for storing conversations and messages.
2.1. Database Schema
Create
supabase/migrations/20250115000000_initial_schema.sql
:2.2. Run Migration
Apply the migration to your Supabase project:
Option 1: Using Supabase CLI (Recommended)
Option 2: Via Supabase Dashboard
2.3. Enable Realtime (Optional)
For real-time message updates in the UI:
messages
table3. Implementing Supabase Authentication in Next.js
Implement cookie-based authentication using Supabase Auth with Next.js 15 App Router.
3.1. Supabase Client Utilities
Create
src/lib/supabase/client.ts
for browser-side client:Create
src/lib/supabase/server.ts
for server-side client:3.2. Next.js Middleware for Auth
Create
src/middleware.ts
:3.3. Auth Pages
Create
src/app/auth/login/page.tsx
:Create
src/app/auth/callback/route.ts
:4. Integrating Sinch WhatsApp Conversation API
Implement authentication and message sending using the Sinch Conversation API with HMAC-SHA256 signatures.
4.1. Sinch Authentication
According to Sinch Conversation API documentation, authentication requires HMAC-SHA256 signature generation. Create
src/lib/sinch/auth.ts
:4.2. Sinch API Client
Create
src/lib/sinch/client.ts
:4.3. TypeScript Types
Create
src/lib/types.ts
:5. Setting Up WhatsApp Webhooks for Incoming Messages
Implement secure webhook endpoint with HMAC-SHA256 signature verification for receiving WhatsApp messages.
5.1. Webhook Signature Verification
Create
src/lib/sinch/webhooks.ts
:5.2. Webhook Route Handler
Create
src/app/api/webhooks/sinch/route.ts
:5.3. Configure Webhook in Sinch Dashboard
https://your-domain.com/api/webhooks/sinch
(use ngrok URL for local development)SINCH_WEBHOOK_SECRET
)For local development with ngrok:
6. Building the WhatsApp Dashboard User Interface
Create the user interface for sending and viewing WhatsApp messages.
6.1. Dashboard Page
Create
src/app/dashboard/page.tsx
:6.2. Message List Component
Create
src/components/MessageList.tsx
:6.3. Send Message Form Component
Create
src/components/SendMessageForm.tsx
:6.4. Auth Button Component
Create
src/components/AuthButton.tsx
:7. Creating the Message Sending API with 24-Hour Window Support
Create the API endpoint for sending messages with 24-hour window validation.
Create
src/app/api/messages/send/route.ts
:8. Testing Your WhatsApp Integration
8.1. Local Development Setup
8.2. Configure Sinch Webhook
https://abc123.ngrok.io
)https://abc123.ngrok.io/api/webhooks/sinch
8.3. Test Message Flow
http://localhost:3000/auth/login
8.4. Common Testing Issues
Webhook not receiving events:
.env.local
Authentication failures:
24-hour window errors:
last_inbound_message_at
timestamp in database9. Deploying to Production (Vercel)
9.1. Deploy to Vercel
Add all variables from
.env.local
to Vercel environment variables.9.2. Update Sinch Webhook URL
After deployment, update webhook URL to production:
https://your-domain.vercel.app/api/webhooks/sinch
9.3. Production Considerations
Security:
Performance:
Monitoring:
10. Common Issues and Troubleshooting Guide
10.1. Message Sending Failures
Error: "Outside 24-hour window"
Error: "Invalid template ID"
Error: "Authentication failed"
.env.local
(encoding happens in auth.ts)10.2. Webhook Issues
Webhooks not arriving:
Signature verification failing:
10.3. Database Issues
RLS policy errors:
user_id
matchesauth.uid()
in RLS policiesConversation window not tracking:
last_inbound_message_at
is being updated by webhook handleris_within_24h_window
function logicFrequently Asked Questions (FAQ)
How do I set up WhatsApp Business API with Sinch?
To set up WhatsApp Business API with Sinch, you need a postpay Sinch account, create a Conversation API app in the Sinch dashboard, provision a WhatsApp Business number (Sender ID), and generate access keys for authentication. Follow Section 1 for detailed setup instructions.
What is the WhatsApp 24-hour messaging window?
WhatsApp enforces a 24-hour customer service window for free-form messages. You can only send generic text messages within 24 hours of the customer's last inbound message. Outside this window, you must use pre-approved template messages to initiate conversations.
How do I create WhatsApp message templates in Sinch?
WhatsApp message templates are created and approved through the Sinch Customer Dashboard under Conversation API → Templates. Templates must follow WhatsApp's guidelines and receive Meta approval before use in production.
Can I use this integration with other messaging platforms?
Yes, the Sinch Conversation API supports multiple channels including SMS, RCS, Facebook Messenger, Viber, and more. You can extend this integration to support additional messaging platforms by configuring additional channel credentials in your Sinch app.
What are the costs of using WhatsApp Business API?
WhatsApp Business API pricing is based on conversation-based pricing from Meta, plus Sinch platform fees. Costs vary by country and conversation type (marketing, utility, authentication, service). Check the WhatsApp Business Platform pricing documentation for current rates.
Source Citations
Sinch Conversation API:
Supabase Authentication:
Next.js Documentation:
WhatsApp Business Platform: