Developer Quick-Start: A guide on setting up a NestJS application to receive WhatsApp messages using AWS SNS and AWS End User Messaging Social. Want to skip 10DLC vetting queues, carrier surcharges, and multi-step SDK boilerplate? You can send the same SMS directly via SMSRoute's REST API with instant no-KYC provisioning.
This guide provides a step-by-step walkthrough for building a production-ready system to receive incoming WhatsApp messages within a Node.js NestJS application. We'll leverage AWS Simple Notification Service (SNS) as the message bus, triggered by AWS End User Messaging Social, which connects directly to your WhatsApp Business Account (WABA).
Project Goal: To create a reliable backend service that listens for incoming WhatsApp messages sent to a specific business number, processes them securely, and makes the message content available within a NestJS application for further action.
Problem Solved: This architecture decouples your application logic from the direct WhatsApp integration complexities, providing a scalable and manageable way to handle incoming messages via standard cloud infrastructure patterns. It enables developers to focus on business logic rather than managing WebSocket connections or Meta's Webhook infrastructure directly.
Technologies Used:
- Node.js: The runtime environment.
- NestJS: A progressive Node.js framework for building efficient, reliable, and scalable server-side applications. Chosen for its modular architecture, dependency injection, and built-in support for various application patterns.
- AWS End User Messaging Social: An AWS service that connects your Meta Business Portfolio (including WABA) to your AWS account, simplifying integration and billing.
- AWS Simple Notification Service (SNS): A fully managed pub/sub messaging service. Used here to receive notifications from AWS End User Messaging Social when a WhatsApp message arrives.
- Meta Business Account & WABA: Required to have an official WhatsApp presence for your business.
- (Optional) AWS CLI & Serverless Application Model (SAM) CLI: For infrastructure setup and deployment automation.
System Architecture:
- An end user sends a message via WhatsApp.
- The message reaches the Meta/WhatsApp Platform.
- Meta forwards the message to AWS End User Messaging Social based on your WABA configuration.
- AWS End User Messaging Social publishes a notification to a configured AWS SNS Topic.
- The SNS Topic sends an HTTP/S POST notification to your NestJS application's designated HTTPS endpoint.
- Your NestJS application receives the notification, validates it, parses the message, and processes it (e.g., saving to a database, triggering application logic).
Prerequisites:
- An active AWS account with appropriate permissions to manage SNS, IAM, and potentially compute resources (e.g., EC2, Fargate, Lambda) for deployment.
- A Meta Business Portfolio with a configured WhatsApp Business Account (WABA) and an associated phone number. Follow Meta's instructions if you don't have one.
- A separate phone with the WhatsApp Messenger app installed for testing (cannot be the same number as the WABA).
- Node.js (v18 LTS or later recommended) and npm/yarn installed locally.
- NestJS CLI installed globally: npm install -g @nestjs/cli
- AWS CLI installed and configured with credentials.
- Note on Credentials: While the AWS CLI often uses access keys stored locally (~/.aws/credentials), this is generally suitable only for local development. For production environments, strongly prefer using IAM roles assigned to your compute resources (EC2 instances, ECS tasks, Lambda functions). The AWS SDK automatically retrieves credentials from these roles without needing hardcoded keys.
- A publicly accessible HTTPS endpoint for your deployed NestJS application (required for SNS subscription confirmation). Services like ngrok can be used for local development testing, but a proper deployment is needed for production.
1. Setting up the NestJS Project
Let's initialize a new NestJS project and install necessary dependencies.
- Create NestJS Project: Open your terminal and run:
nest new whatsapp-sns-nestjs
cd whatsapp-sns-nestjs
- Install Dependencies: We need packages to handle incoming HTTP requests, manage
configuration, parse raw text bodies (SNS sends
text/plain), validate SNS messages, and potentially make HTTP requests (for subscription confirmation).
npm install @nestjs/config dotenv body-parser sns-validator axios
npm install --save-dev @types/body-parser @types/node
- @nestjs/config: Manages environment variables.
- dotenv: Loads environment variables from a .env file (primarily for local development).
- body-parser: Middleware to parse request bodies. We specifically need its text parser.
- sns-validator: To verify the authenticity of incoming SNS messages.
- axios: To make HTTP requests (e.g., confirming SNS subscription).
- Environment Variables Setup: Create a
.envfile in the project root (primarily for local development):
.env
# .env
# AWS Credentials (ONLY for local testing if IAM roles/profiles aren't used)
# Avoid committing this file or hardcoding keys in production. Use IAM roles instead.
# AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
AWS_REGION=us-east-1 # Replace with your target AWS region
# Application Port
PORT=3000
# SNS Topic ARN (Replace this with the actual ARN after creating the topic in AWS)
SNS_INCOMING_WHATSAPP_TOPIC_ARN=arn:aws:sns:us-east-1:123456789012:YourWhatsAppIncomingTopic
# Optional: Log level
LOG_LEVEL=debug
- Important: For production environments, avoid bundling .env files or hardcoding AWS credentials. Use IAM roles associated with your compute environment (EC2, Fargate, Lambda) or retrieve secrets from AWS Secrets Manager at runtime. The AWS SDK automatically picks up credentials from standard locations like IAM roles.
- Configure ConfigModule: Import and configure
ConfigModuleinsrc/app.module.tsto load the.envfile.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config';
import { SnsWebhookModule } from './sns-webhook/sns-webhook.module';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: '.env',
}),
SnsWebhookModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
- Enable Raw Body Parsing: SNS sends notifications with
Content-Type: text/plain. NestJS, by default, only parses JSON and URL-encoded bodies. We need to enable raw text parsing specifically for the SNS webhook route before the standard NestJS parsers might handle the request.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ConfigService } from '@nestjs/config';
import { Logger, ValidationPipe } from '@nestjs/common';
import * as bodyParser from 'body-parser';
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
bodyParser: false,
});
const configService = app.get(ConfigService);
const port = configService.get<number>('PORT', 3000);
const logger = new Logger('Bootstrap');
app.use('/webhook/sns', bodyParser.text({ type: 'text/plain' }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
await app.listen(port);
logger.log(`Application listening on port ${port}`);
logger.log(`SNS Webhook Endpoint expected at: /webhook/sns`);
}
bootstrap();
- Explanation: We disable the default bodyParser during app creation. Then, we selectively apply bodyParser.text() middleware only to the route where we expect SNS notifications (/webhook/sns). Finally, we apply standard JSON and URL-encoded parsers globally, which will handle other routes. This setup relies on the middleware execution order; ensure it functions correctly for all your application's routes.
2. Implementing Core Functionality: The SNS Webhook Listener
We'll create a dedicated module, controller, and service to handle incoming SNS messages.
- Generate Module, Controller, Service:
nest g module sns-webhook
nest g controller sns-webhook --no-spec
nest g service sns-webhook --no-spec
- Implement the SNS Webhook Controller (
sns-webhook.controller.ts): This controller defines the endpoint that AWS SNS will send HTTP POST requests to.
import { Controller, Post, Body, Headers, Logger, HttpCode, Req, BadRequestException } from '@nestjs/common';
import { SnsWebhookService } from './sns-webhook.service';
@Controller('webhook/sns')
export class SnsWebhookController {
private readonly logger = new Logger(SnsWebhookController.name);
constructor(private readonly snsWebhookService: SnsWebhookService) {}
@Post()
@HttpCode(200)
async handleSnsNotification(
@Headers('x-amz-sns-message-type') messageType: string,
@Body() rawBody: string,
@Req() req: any,
) {
this.logger.debug(`Received SNS notification. Type: ${messageType}`);
if (!rawBody || typeof rawBody !== 'string') {
this.logger.warn('Received empty or non-string body.');
return 'OK';
}
if (!messageType) {
this.logger.warn('Missing x-amz-sns-message-type header.');
return 'OK';
}
try {
await this.snsWebhookService.processSnsMessage(messageType, rawBody);
return 'OK';
} catch (error) {
this.logger.error(`Error processing SNS message: ${error.message}`, error.stack);
if (error instanceof BadRequestException) {
return 'Bad Request Logged';
}
return 'Processing Error Logged';
}
}
}
- Explanation:
- The @Post() decorator marks the handleSnsNotification method to handle POST requests to /webhook/sns.
- @HttpCode(200) ensures a 200 OK response is sent back to SNS upon successful handling (or even logged processing errors) to prevent unnecessary retries. SNS treats any 2xx response as success.
- @Headers('x-amz-sns-message-type') extracts the crucial header indicating if it's a SubscriptionConfirmation or Notification.
- @Body() rawBody: string receives the raw request body as a string. This works because the bodyParser.text() middleware configured in main.ts specifically handles the /webhook/sns route and makes the raw text available via @Body() when the parameter type is string.
- The logic is delegated to SnsWebhookService. Error handling is included, aiming to return 200 OK to SNS even for processing errors to avoid retry storms, while logging the actual error.
- Implement the SNS Webhook Service (
sns-webhook.service.ts): This service contains the logic for validating the SNS message signature and processing different message types.
import { Injectable, Logger, BadRequestException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import axios from 'axios';
import { MessageValidator } from 'sns-validator';
interface SnsMessage {
Type: string;
MessageId: string;
TopicArn: string;
Subject?: string;
Message: string;
Timestamp: string;
SignatureVersion: string;
Signature: string;
SigningCertURL: string;
UnsubscribeURL?: string;
SubscribeURL?: string;
Token?: string;
[key: string]: unknown;
}
@Injectable()
export class SnsWebhookService {
private readonly logger = new Logger(SnsWebhookService.name);
private readonly validator = new MessageValidator('utf8');
constructor(private configService: ConfigService) {}
async processSnsMessage(messageType: string, rawBody: string): Promise<void> {
let message: SnsMessage;
try {
message = JSON.parse(rawBody);
if (typeof message !== 'object' || message === null) {
throw new Error('Parsed body is not an object.');
}
} catch (error) {
this.logger.error(`Failed to parse SNS message body: ${error.message}`, rawBody);
throw new BadRequestException('Invalid SNS message format.');
}
try {
await this.validateSnsMessage(message);
this.logger.debug('SNS message signature validated successfully.');
} catch (error) {
this.logger.error(`SNS message validation failed: ${error.message}`, error.stack);
throw new BadRequestException(`Invalid SNS signature: ${error.message}`);
}
switch (message.Type) {
case 'SubscriptionConfirmation':
await this.handleSubscriptionConfirmation(message);
break;
case 'Notification':
await this.handleNotification(message);
break;
default:
this.logger.warn(`Received unknown SNS message type: ${message.Type}`);
break;
}
}
private validateSnsMessage(message: SnsMessage): Promise<SnsMessage> {
return new Promise((resolve, reject) => {
this.validator.validate(message, (err, validatedMessage) => {
if (err) {
this.logger.warn(`SNS validation error details: ${err.message}`, err);
return reject(err);
}
resolve(validatedMessage as SnsMessage);
});
});
}
private async handleSubscriptionConfirmation(message: SnsMessage): Promise<void> {
const subscribeUrl = message.SubscribeURL;
if (!subscribeUrl || typeof subscribeUrl !== 'string') {
this.logger.error('SubscriptionConfirmation message missing or invalid SubscribeURL.', message);
throw new BadRequestException('Missing or invalid SubscribeURL in SubscriptionConfirmation.');
}
this.logger.log(`Received SubscriptionConfirmation. Visiting SubscribeURL to confirm...`);
try {
const response = await axios.get(subscribeUrl);
this.logger.log(`Successfully confirmed SNS topic subscription via GET request. Status: ${response.status}`);
} catch (error) {
const errorMessage = error.response ? `Status ${error.response.status}: ${error.response.data}` : error.message;
this.logger.error(`Failed to confirm SNS subscription via GET request: ${errorMessage}`, error.stack);
throw new Error('Failed to confirm SNS subscription.');
}
}
private async handleNotification(message: SnsMessage): Promise<void> {
this.logger.log(`Received Notification. Message ID: ${message.MessageId}`);
try {
const messageContentString = message.Message;
if (!messageContentString || typeof messageContentString !== 'string') {
this.logger.warn('Notification received but Message field is empty, missing, or not a string.', message);
return;
}
const notificationPayload = JSON.parse(messageContentString);
if (typeof notificationPayload !== 'object' || notificationPayload === null) {
throw new Error('Parsed Message field content is not an object.');
}
this.logger.log('Successfully parsed notification payload from Message field.');
const messageEntry = notificationPayload?.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
if (messageEntry && typeof messageEntry === 'object') {
const sender = messageEntry.from;
const messageType = messageEntry.type;
const text = messageType === 'text' ? messageEntry.text?.body : null;
if (sender && typeof sender === 'string' && messageType && typeof messageType === 'string') {
this.logger.log(`Processing '${messageType}' message from ${sender}`);
if (text && typeof text === 'string') {
this.logger.log(` -> Text: ""${text}""`);
}
} else {
this.logger.warn('Could not extract valid sender or message type from notification payload structure.', messageEntry);
}
} else {
this.logger.warn('Could not find message details in the expected path within notification payload.', notificationPayload);
}
} catch (error) {
this.logger.error(`Failed to parse or process SNS Notification Message field: ${error.message}`, error.stack);
throw new Error(`Failed to process Notification payload: ${error.message}`);
}
}
}
- Explanation:
- The service parses the rawBody.
- Crucially, it uses sns-validator's validate method to verify the message's signature against the certificate provided by AWS. This prevents attackers from sending fake SNS messages to your endpoint. Never skip this step.
- It handles SubscriptionConfirmation by extracting the SubscribeURL and making an HTTP GET request using axios to confirm the endpoint ownership to AWS.
- It handles Notification by parsing the Message field (which contains the actual WhatsApp payload from AWS End User Messaging Social as a JSON string). An example structure and extraction logic are provided. This is where you integrate your application's business logic. You'll need to adapt the extraction logic based on the exact payload structure you receive from AWS/Meta for various message types.
3. Building the API Layer
The API layer is the SNS Webhook endpoint we just created (POST /webhook/sns). It
doesn't require traditional REST API authentication because security is handled by:
- HTTPS: The endpoint must be served over HTTPS. SNS will not send to HTTP endpoints.
- SNS Signature Verification: The sns-validator logic in SnsWebhookService ensures only legitimate messages from your configured AWS SNS topic are processed.
- (Optional) Obscurity: While not true security, the webhook URL isn't typically guessable if made complex.
Testing the Endpoint (Simulated):
You can simulate an SNS message using curl or Postman, but signature verification will
fail unless you craft a valid signed message (which is complex). It's better to test the processing
logic directly or wait for the full integration test.
However, you can test the path and basic parsing (before validation):
curl -X POST http://localhost:3000/webhook/sns \
-H "Content-Type: text/plain" \
-H "x-amz-sns-message-type: Notification" \
-d '{
"Type" : "Notification",
"MessageId" : "some-fake-message-id",
"TopicArn" : "arn:aws:sns:us-east-1:123456789012:YourWhatsAppIncomingTopic",
"Subject" : "Optional Subject",
"Message" : "{\"object\":\"whatsapp_business_account\",\"entry\":[{\"id\":\"FAKE_WABA_ID\",\"changes\":[{\"value\":{\"messaging_product\":\"whatsapp\",\"metadata\":{\"display_phone_number\":\"+15550001234\",\"phone_number_id\":\"FAKE_PHONE_ID\"},\"contacts\":[{\"profile\":{\"name\":\"Test User\"},\"wa_id\":\"14155552671\"}],\"messages\":[{\"from\":\"14155552671\",\"id\":\"wamid.FAKE_ID\",\"timestamp\":\"1678886400\",\"text\":{\"body\":\"Hello from curl!\"},\"type\":\"text\"}]},\"field\":\"messages\"}]}]}",
"Timestamp" : "2025-04-20T12:00:00.000Z",
"SignatureVersion" : "1",
"Signature" : "FAKE_SIGNATURE",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-xxxxxxxxxxxxxxx.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/unsubscribe..."
}'
This is where we configure the AWS services to talk to our NestJS application.
Step 4.1: Create the SNS Topic
- Navigate to the Amazon SNS console in your chosen AWS Region.
- Click Topics in the left navigation pane.
- Click Create topic.
- Select Standard as the type (FIFO is not needed here).
- Enter a Name for your topic (e.g., whatsapp-incoming-messages).
- Scroll down and click Create topic.
- Once created, copy the Topic ARN. It will look like arn:aws:sns:us-east-1:123456789012:whatsapp-incoming-messages.
- Paste this ARN into your .env file for the SNS\_INCOMING\_WHATSAPP\_TOPIC\_ARN variable (or configure it via environment variables in your deployment).
Step 4.2: Configure AWS End User Messaging Social
This step connects your WABA to the SNS topic. Follow the AWS documentation closely, as the UI might change. Reference: AWS Blog Post on WhatsApp Integration
- Navigate to the AWS End User Messaging Social console (ensure you select your correct AWS region in the console).
- Click Add WhatsApp phone number.
- Click Launch Facebook portal. This will open a pop-up window from Meta.
- Follow the instructions in the Meta pop-up:
- Log in to your Facebook/Meta account that manages your Meta Business Portfolio.
- Select the Meta Business Account you want to use.
- Select the WhatsApp Business Account (WABA) you want to integrate.
- Confirm the permissions AWS requires.
- Once the connection is established, you should be redirected back to the AWS console, and your WABA should appear.
- Configure the WABA integration within AWS End User Messaging Social:
- Select the newly added WABA phone number.
- Find the section for configuring incoming message notifications (the exact naming might vary, look for ""Incoming messages"" or similar).
- Choose Forward to Amazon SNS topic.
- Select or paste the ARN of the SNS topic you created in Step 4.1.
- Grant IAM Permissions: Ensure AWS End User Messaging Social can publish to your SNS topic. The console might guide you to automatically update the topic's Access Policy. If not, you must manually edit the SNS topic's Access Policy (found under the Access policy tab in the SNS topic details). Add or modify a statement to allow the eum.amazonaws.com service principal to perform the sns:Publish action on your specific topic ARN.
- Example Policy Statement:
{
""Sid"": ""AllowEUMSPublishToSNSTopic"",
""Effect"": ""Allow"",
""Principal"": {
""Service"": ""eum.amazonaws.com""
},
""Action"": ""sns:Publish"",
""Resource"": ""YOUR_SNS_TOPIC_ARN"",
""Condition"": {
""StringEquals"": {
""aws:SourceAccount"": ""YOUR_AWS_ACCOUNT_ID""
}
}
}
- Save the configuration.
Step 4.3: Deploy Your NestJS Application
Your NestJS application needs to be running and accessible via a public HTTPS URL for SNS to confirm the subscription and send notifications.
- Choose a Deployment Strategy: Options include AWS EC2, AWS Fargate, AWS Elastic Beanstalk, AWS App Runner, or potentially AWS Lambda (though handling webhooks in Lambda requires specific patterns like Function URLs or API Gateway integration).
- Configure HTTPS: Ensure your deployment includes a load balancer (like Application Load Balancer) or a reverse proxy (like Nginx, Caddy) that terminates TLS/SSL and provides a public HTTPS URL. Services like App Runner or Elastic Beanstalk often handle this automatically.
- Deploy: Deploy your application using your chosen method. Note the full public HTTPS URL including the webhook path (e.g., https://your-app-domain.com/webhook/sns).
Step 4.4: Create the SNS Subscription
- Navigate back to the Amazon SNS console.
- Go to Topics and select the topic you created (e.g., whatsapp-incoming-messages).
- Click the Create subscription button.
- Topic ARN: Should be pre-filled.
- Protocol: Select HTTPS.
- Endpoint: Enter the full public HTTPS URL of your deployed NestJS webhook listener (e.g., https://your-app-domain.com/webhook/sns).
- Enable raw message delivery: Keep this unchecked. We are handling the standard JSON structure SNS sends, which includes metadata and the message content within the Message field. Raw delivery would only send the content of the Message field directly, skipping metadata and signature details needed for validation.
- Click Create subscription.
Step 4.5: Confirm the Subscription
- AWS SNS will immediately send a SubscriptionConfirmation message (with Type: SubscriptionConfirmation) to your HTTPS endpoint.
- Your running NestJS application should receive this message.
- The SnsWebhookService's handleSubscriptionConfirmation logic will parse the message, validate its signature, extract the SubscribeURL, and automatically make a GET request to that URL.
- Check your NestJS application logs for messages indicating the receipt of the SubscriptionConfirmation and the attempt to visit the SubscribeURL. Look for success or error messages related to the confirmation GET request.
- In the AWS SNS console, the subscription status should change from ""Pending confirmation"" to ""Confirmed"". If it doesn't confirm within a minute or two, check:
- Your application logs for errors (parsing, validation, network errors calling SubscribeURL).
- Ensure the endpoint URL entered in the subscription is correct and publicly accessible via HTTPS (use tools like curl or an online SSL checker).
- Verify firewall rules, security groups, or network ACLs are not blocking requests from SNS servers to your endpoint.
5. Error Handling, Logging, and Retry Mechanisms
- Error Handling: The provided code includes basic try...catch blocks. Log errors clearly using NestJS Logger. Distinguish between errors that should prevent acknowledgment to SNS (e.g., invalid signature - return 4xx or handle gracefully but log severity) and processing errors where you might still want to acknowledge receipt (return 2xx) but log the failure for investigation (e.g., database connection issue). Use specific exceptions like BadRequestException where appropriate.
- Logging: Use the built-in NestJS Logger service. Configure log levels via environment variables (e.g., LOG\_LEVEL). Log key events: message received (DEBUG), validation success/failure (DEBUG/ERROR), confirmation attempts (INFO/ERROR), notification processing start/end/error (INFO/ERROR), extracted data (DEBUG or INFO, be careful with PII). Log the MessageId from SNS notifications to correlate logs across systems. Consider structured logging (JSON format) for easier parsing in log aggregation tools (like CloudWatch Logs Insights, Datadog, Splunk).
- Retry Mechanisms (SNS): SNS automatically retries delivery to HTTPS endpoints if they fail (return a non-2xx status code or time out). The default retry policy includes multiple retries over several hours with exponential backoff. You can customize this policy or configure a dead-letter queue (DLQ) on the SNS subscription to capture messages that consistently fail delivery after all retries.
- To configure a DLQ: Create an SQS queue to serve as the DLQ. Then, edit your SNS subscription settings. Under Redrive policy (dead-letter queue), enable it and select the SQS queue you created. This allows for later analysis or reprocessing of failed messages without losing them. See AWS Docs on SNS DLQs.
6. Database Schema and Data Layer (Conceptual)
While not implemented in the core guide, you would typically store incoming messages or related data.
- Schema: Consider a table like whatsapp\_messages with columns such as:
- id (Primary Key, e.g., UUID or auto-increment)
- sns\_message\_id (VARCHAR, Unique - from SNS Notification MessageId, useful for idempotency/debugging)
- whatsapp\_message\_id (VARCHAR, Unique - from WhatsApp payload messages[0].id)
- sender\_number (VARCHAR - from WhatsApp payload messages[0].from)
- recipient\_number (VARCHAR - your WABA number, from metadata.display\_phone\_number)
- message\_timestamp (TIMESTAMP WITH TIME ZONE - derived from WhatsApp payload messages[0].timestamp)
- message\_type (VARCHAR - from WhatsApp payload messages[0].type, e.g., 'text', 'image', 'interactive')
- message\_body (TEXT - for text messages, from messages[0].text.body, nullable)
- media\_id (VARCHAR - for media messages, from messages[0].image.id, etc., nullable)
- media\_mime\_type (VARCHAR - if applicable, nullable)
- raw\_payload (JSONB or TEXT - store the parsed notificationPayload for future reference or reprocessing)
- status (VARCHAR - e.g., 'received', 'processing', 'processed', 'failed')
- created\_at (TIMESTAMP WITH TIME ZONE - record creation time)
- updated\_at (TIMESTAMP WITH TIME ZONE - record update time)
- Data Layer: Implement a NestJS service (e.g., MessagePersistenceService) injected into SnsWebhookService to handle database interactions using an ORM like TypeORM or Prisma, or a database client. Ensure database operations are handled asynchronously and include error handling. Consider idempotency checks based on whatsapp\_message\_id or sns\_message\_id to avoid processing duplicate messages if SNS retries occur after successful processing but before a successful response was sent.
Simpler Alternative: Send the Same SMS With SMSRoute (No-KYC, Direct Routes)
If you want to replace legacy aggregator SDK boilerplate, multi-week compliance queues, and opaque carrier surcharges with a single HTTP request, SMSRoute delivers global SMS over direct Tier-1 carrier interconnects with instant API access and transparent per-country pricing.
curl -X POST https://api.sendsmsnokyc.com/messages \
-H "x-api-key: $SMSROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": ["+14155551234"],
"channel": ["sms"],
"body": "Your verification code is 482910"
}'
- Instant onboarding: No KYC paperwork or sales queues β grab an API key and fund with crypto (BTC/USDT) or card.
- Direct Tier-1 routes: Verify real handset delivery, DLR latency, and Sender ID preservation before launch via SMSRoute Live Carrier Testing.
- Transparent global pricing: Compare exact per-country termination rates on our live pricing page.
Ship Global SMS in One API Call
Skip legacy SDK sprawl and carrier bottlenecks. Send OTPs, alerts, and bulk campaigns across 190+ countries with SMSRoute.
Explore SMSRoute Developers β