Developer Quick-Start: A step-by-step guide to building a Node.js and Express application for sending SMS via Infobip and handling real-time delivery status updates using webhooks. 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 Node.js application using the Express framework to send SMS messages via the Infobip API and receive real-time delivery status updates through webhooks (callbacks).
You will learn how to set up a project, send messages, configure Infobip webhooks, create an endpoint to receive status updates, handle potential errors, and deploy the application. This enables you to track the delivery status of every message sent, crucial for applications requiring reliable communication and reporting.
Project Goals:
- Send SMS messages using the Infobip API from a Node.js application.
- Receive delivery status reports (DLRs) from Infobip via webhooks.
- Store basic message status information.
- Provide a robust foundation for production use.
Technologies Used:
- Node.js: A JavaScript runtime environment for server-side development.
- Express: A minimal and flexible Node.js web application framework (version 4.16.0+ includes built-in JSON parsing).
- Infobip API: Used for sending SMS messages and configuring delivery report webhooks.
- axios: A promise-based HTTP client for making requests to the Infobip API.
- dotenv: To manage environment variables securely.
System Architecture:
(System Architecture Diagram Placeholder: Ideally, replace this text with an actual diagram image showing the flow: User/Service -> Node.js App -> Infobip API (for sending SMS), and then Infobip Platform -> Node.js App (for delivery report callback).)
Prerequisites:
- A free or paid Infobip account (https://www.infobip.com/).
- Node.js and npm (or yarn) installed on your system.
- Basic understanding of JavaScript, Node.js, Express, and REST APIs.
- A publicly accessible URL for receiving webhook callbacks (we'll use ngrok for local development).
Final Outcome:
By the end of this guide, you will have a running Node.js Express application capable of:
- Accepting API requests to send SMS messages.
- Calling the Infobip API to dispatch those messages.
- Receiving POST requests from Infobip on a dedicated endpoint (/delivery-report) containing the delivery status of sent messages.
- Logging the received delivery status.
Setting up the Project
Let's start by creating our project directory, initializing Node.js, and installing necessary dependencies.
Create Project Directory
Open your terminal or command prompt and create a new directory for the project.
mkdir infobip-delivery-callbacks
cd infobip-delivery-callbacks
Initialize Node.js Project
Initialize the project using npm. You can accept the defaults or customize them.
npm init -y
This creates a package.json file.
Install Dependencies
We need express for the web server, axios to make HTTP requests to Infobip, and
dotenv to manage environment variables. Note that modern Express versions (4.16.0+) include
built-in middleware for parsing JSON and URL-encoded bodies, so body-parser is often no longer
needed as a separate dependency.
npm install express axios dotenv
(Optional) Install Nodemon for Development: nodemon automatically restarts the server
upon file changes, speeding up development.
npm install --save-dev nodemon
If you installed nodemon, update the scripts section in your
package.json:
{
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
}
Project Structure
Create the basic files and folders.
touch server.js .env .env.example .gitignore
Your initial structure should look like this:
infobip-delivery-callbacks/
βββ node_modules/
βββ .env
βββ .env.example
βββ .gitignore
βββ package-lock.json
βββ package.json
βββ server.js
Configure Environment Variables
We need to store sensitive information like API keys securely.
- .env: This file will hold your actual secrets (API Key, Base URL). Do not commit this file to version control.
- .env.example: A template showing required variables. Commit this file.
- .gitignore: Ensures .env and node\_modules are not tracked by Git.
Add the following to your .gitignore:
# .gitignore
node_modules
.env
npm-debug.log
Add the following variable names to .env.example:
ini
INFOBIP_API_KEY=YOUR_INFOBIP_API_KEY
INFOBIP_BASE_URL=YOUR_INFOBIP_BASE_URL
PORT=3000
Now, populate your actual .env file with your credentials. See the "Obtaining API Credentials"
section for detailed instructions on obtaining your Infobip API Key and Base URL.
ini
INFOBIP_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
INFOBIP_BASE_URL=yyyyyy.api.infobip.com
PORT=3000
Purpose of Configuration:
.env/dotenv: Keeps sensitive credentials out of the codebase, adhering to security best practices. Different environments (development, production) can have different .env files.nodemon: Improves developer experience by automatically restarting the server on code changes.
Implementing Core Functionality
Now, let's write the code for our Express server, including sending SMS and preparing the endpoint for delivery reports.
Basic Express Server Setup
Open server.js and set up a minimal Express application.
require('dotenv').config();
const express = require('express');
const axios = require('axios');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
const messageStore = {};
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
Implementing SMS Sending
We'll adapt the logic from the Infobip Node.js blog post to create an API endpoint /send-sms.
Add the following code inside server.js where // --- Routes will go here --- is
indicated:
const buildUrl = (baseUrl) => {
const cleanBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
return `https://${cleanBaseUrl}/sms/2/text/advanced`;
};
const buildHeaders = (apiKey) => {
if (!apiKey) {
throw new Error('INFOBIP_API_KEY is missing.');
}
return {
'Authorization': `App ${apiKey}`,
'Content-Type': 'application/json',
'Accept': 'application/json',
};
};
const buildRequestBody = (destinationNumber, messageText, messageId) => {
if (!destinationNumber || !messageText) {
throw new Error('Destination number and message text are required.');
}
const message = {
destinations: [{ to: destinationNumber }],
text: messageText,
};
if (messageId) {
message.messageId = messageId;
}
return {
messages: [message],
tracking: {
track: ""SMS"",
type: ""ONE_TIME_PIN""
}
};
};
app.post('/send-sms', async (req, res) => {
const { to, text } = req.body;
if (!to || !text) {
return res.status(400).json({ error: 'Missing required fields: to, text' });
}
const apiKey = process.env.INFOBIP_API_KEY;
const baseUrl = process.env.INFOBIP_BASE_URL;
if (!apiKey || !baseUrl) {
console.error('Infobip API Key or Base URL missing in environment variables.');
return res.status(500).json({ error: 'Server configuration error.' });
}
try {
const url = buildUrl(baseUrl);
const headers = buildHeaders(apiKey);
const requestBody = buildRequestBody(to, text);
console.log(`Sending SMS to: ${to}`);
console.log('Request Body:', JSON.stringify(requestBody, null, 2));
const infobipResponse = await axios.post(url, requestBody, { headers });
console.log('Infobip API Response:', JSON.stringify(infobipResponse.data, null, 2));
if (infobipResponse.data && infobipResponse.data.messages && infobipResponse.data.messages.length > 0) {
const sentMessage = infobipResponse.data.messages[0];
messageStore[sentMessage.messageId] = {
to: sentMessage.to,
status: sentMessage.status.name,
group: sentMessage.status.groupName,
timestamp: new Date().toISOString()
};
console.log(`Message ID ${sentMessage.messageId} stored with status ${sentMessage.status.name}`);
}
res.status(infobipResponse.status).json(infobipResponse.data);
} catch (error) {
console.error('Error sending SMS via Infobip:');
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', JSON.stringify(error.response.data, null, 2));
res.status(error.response.status).json({
error: 'Failed to send SMS via Infobip.',
details: error.response.data
});
} else if (error.request) {
console.error('Request Error:', error.request);
res.status(500).json({ error: 'No response received from Infobip API.' });
} else {
console.error('Error:', error.message);
res.status(500).json({ error: 'Internal server error.', message: error.message });
}
}
});
Why this approach?
- Separation of Concerns: Helper functions (buildUrl, buildHeaders, buildRequestBody) keep the main route handler clean.
- Asynchronous Handling: Using async/await makes handling the promise returned by axios.post straightforward.
- Error Handling: The try...catch block specifically checks for error.response (errors from Infobip), error.request (network issues), and other general errors.
- Tracking Parameter: Adding the tracking object in the request body tells Infobip we want delivery reports for this message. The specific type or processKey can help categorize reports later.
- Built-in Middleware: Uses express.json() instead of the external body-parser package for simplicity and modern practice.
Implementing the Delivery Report Endpoint
This endpoint (/delivery-report) will receive POST requests from Infobip containing
status updates.
Add the following code inside server.js where
// --- Delivery Report Endpoint will go here --- is indicated:
app.post('/delivery-report', (req, res) => {
console.log('Received Delivery Report:');
console.log(JSON.stringify(req.body, null, 2));
const reports = req.body.results;
if (!reports || !Array.isArray(reports)) {
console.warn('Received invalid delivery report format.');
return res.status(200).send('Report received but format unexpected.');
}
try {
reports.forEach(report => {
const { messageId, status, error, doneAt, sentAt, price } = report;
const statusName = status ? status.name : 'UNKNOWN';
const groupName = status ? status.groupName : 'UNKNOWN';
const errorName = error ? error.name : 'NONE';
console.log(`---\nMessage ID: ${messageId}`);
console.log(`Status: ${statusName} (${groupName})`);
console.log(`Error: ${errorName}`);
console.log(`Sent At: ${sentAt}`);
console.log(`Done At: ${doneAt}`);
console.log(`Price: ${price ? price.pricePerMessage + ' ' + price.currency : 'N/A'}`);
if (messageStore[messageId]) {
messageStore[messageId].status = statusName;
messageStore[messageId].group = groupName;
messageStore[messageId].error = errorName;
messageStore[messageId].finalTimestamp = doneAt || new Date().toISOString();
console.log(`Updated status for Message ID ${messageId} to ${statusName}`);
} else {
console.warn(`Received report for unknown Message ID: ${messageId}`);
}
console.log(`---`);
});
} catch (processingError) {
console.error('Error processing delivery report:', processingError);
}
res.status(200).send('Delivery report received successfully.');
});
app.get('/message-status', (req, res) => {
res.status(200).json(messageStore);
});
Why this approach?
- Dedicated Endpoint: Clearly separates the logic for receiving reports.
- Logging: Logs the entire received payload for debugging, then extracts key fields.
- Data Structure: Parses the expected results array from Infobip's payload.
- Acknowledgement: Crucially sends a
200 OKresponse back to Infobip. This is highlighted due to its importance in preventing unnecessary retries from Infobip. - Robust Processing: Includes a try...catch around the report processing loop to handle potential errors without crashing the server or preventing the 200 OK response.
- Status Update: Demonstrates updating the status in our simple messageStore. In a real application, this would involve database operations.
Building a Complete API Layer
Our API layer currently consists of:
POST /send-sms: Triggers sending an SMS.- Request Body (JSON):
{
"to": "+12345678900",
"text": "Hello from the Infobip Guide!"
}
- Success Response (JSON - Example):
{
"bulkId": "some-bulk-id",
"messages": [
{
"to": "+12345678900",
"status": {
"groupId": 1,
"groupName": "PENDING",
"id": 26,
"name": "PENDING_ACCEPTED",
"description": "Message accepted, pending delivery."
},
"messageId": "unique-infobip-message-id-12345"
}
]
}
- Error Response (JSON - Example 400 Bad Request):
{
"error": "Missing required fields: to, text"
}
- Error Response (JSON - Example 500 Infobip Error):
{
"error": "Failed to send SMS via Infobip.",
"details": {
"requestError": {
"serviceException": {
"messageId": "INVALID_DESTINATION_ADDRESS",
"text": "Invalid destination address format."
}
}
}
}
POST /delivery-report: Receives delivery status updates from Infobip.- Request Body (JSON - Example from Infobip):
{
"results": [
{
"bulkId": "some-bulk-id",
"messageId": "unique-infobip-message-id-12345",
"to": "+12345678900",
"sentAt": "2023-10-26T10:00:05.123+0000",
"doneAt": "2023-10-26T10:00:07.456+0000",
"smsCount": 1,
"price": {
"pricePerMessage": 0.005,
"currency": "USD"
},
"status": {
"groupId": 3,
"groupName": "DELIVERED",
"id": 5,
"name": "DELIVERED_TO_HANDSET",
"description": "Message delivered to handset"
},
"error": {
"groupId": 0,
"groupName": "OK",
"id": 0,
"name": "NO_ERROR",
"description": "No Error",
"permanent": false
}
}
]
}
- Success Response (Text):
Delivery report received successfully.
GET /message-status: (Optional debugging endpoint) View stored statuses.- Success Response (JSON):
{
"unique-infobip-message-id-12345": {
"to": "+12345678900",
"status": "DELIVERED_TO_HANDSET",
"group": "DELIVERED",
"timestamp": "2023-10-26T10:00:05.150Z",
"error": "NO_ERROR",
"finalTimestamp": "2023-10-26T10:00:07.456+0000"
}
}
Testing with curl:
- Send SMS: (Make sure your server is running:
npm run devornpm start)
curl -X POST http://localhost:3000/send-sms \
-H "Content-Type: application/json" \
-d '{
"to": "+12345678900",
"text": "Test message from curl!"
}'
Note: Replace +12345678900 with your test number (must be verified on Infobip free
trial).
- Check Status (Optional Debugging):
curl http://localhost:3000/message-status
- Simulate Infobip Callback (Advanced): You would typically rely on Infobip sending the callback, but you could simulate it:
curl -X POST http://localhost:3000/delivery-report \
-H "Content-Type: application/json" \
-d '{
"results": [
{
"messageId": "unique-infobip-message-id-12345",
"to": "+12345678900",
"status": { "groupId": 3, "groupName": "DELIVERED", "id": 5, "name": "DELIVERED_TO_HANDSET", "description": "Simulated delivery" },
"error": { "groupId": 0, "groupName": "OK", "id": 0, "name": "NO_ERROR", "description": "No Error" },
"doneAt": "2023-10-26T11:00:00.000+0000",
"sentAt": "2023-10-26T10:59:58.000+0000"
}
]
}'
Note: Use a messageId from a previous /send-sms response. After
simulation, check /message-status again or watch the server logs.
Authentication/Authorization:
This basic example lacks robust API authentication. For production:
/send-sms: Protect this endpoint with API keys, JWT tokens, or other mechanisms suitable for your application's security model. Ensure only authorized clients can trigger messages./delivery-report: This endpoint needs to be public for Infobip to reach it. Security relies on:- Obscurity: The URL itself isn't widely known.
- (Strongly Recommended) Signature Validation: Consult the official Infobip documentation to determine if they currently offer webhook signature validation for SMS delivery reports. If they do, implement it. This typically involves obtaining a secret key from the Infobip portal and using cryptographic libraries (like Node.js crypto) to verify a signature sent in the request header (e.g., X-Infobip-Signature). This is the most reliable method to ensure the request genuinely originated from Infobip and prevent malicious POSTs to your callback URL.
- IP Whitelisting: If Infobip provides a stable list of IP addresses they use for sending webhooks, you could potentially whitelist these IPs at your firewall/infrastructure level. However, IPs can change, making signature validation generally preferable.
Integrating with Infobip
Obtaining API Credentials
- Log in to your Infobip account (portal.infobip.com).
- API Key:
- Navigate to the ""Developers"" section (often in the main menu or sidebar).
- Go to ""API Keys"".
- Create a new API key or use an existing one. Give it a descriptive name (e.g., ""Node Delivery Callback App"").
- Copy the generated API key immediately and securely store it. You usually cannot view it again.
- Paste this key into your .env file as INFOBIP\_API\_KEY.
- Base URL:
- On the same API Keys page, or sometimes in your account settings/profile, you will find your unique Base URL. It typically looks like xxxxx.api.infobip.com.
- Copy this URL (just the domain part, without https://).
- Paste it into your .env file as INFOBIP\_BASE\_URL.
Configuring the Delivery Report Webhook
This tells Infobip where to send the delivery status updates.
- In the Infobip portal, find the section for Webhooks or API Settings. This might be under ""Developers,"" ""Channels,"" or specific product settings like ""SMS.""
- Look for ""Delivery Reports,"" ""Status Updates,"" or a similar option for SMS.
- You will need to provide the URL for your /delivery-report endpoint.
- Local Development: Use a tunneling service like ngrok.
- Install ngrok (ngrok.com).
- Run your Node.js server (npm run dev or npm start). Let's assume it's on port 3000.
- In a new terminal window, run: ngrok http 3000
- ngrok will provide a public HTTPS URL (e.g., https://<random-id>.ngrok-free.app or similar).
- Copy this HTTPS URL and append your endpoint path: https://<random-id>.ngrok-free.app/delivery-report
- Production Deployment: Use the public URL of your deployed application (e.g., https://your-app-domain.com/delivery-report).
- Paste the complete, publicly accessible URL into the appropriate field in the Infobip webhook configuration section.
- Save the configuration. Infobip might send a test request to verify the URL is reachable.
Environment Variables Recap
- INFOBIP\_API\_KEY: Your secret key for authenticating API requests to Infobip. Found in Infobip portal > Developers > API Keys.
- INFOBIP\_BASE\_URL: Your unique domain for accessing the Infobip API. Found near your API Key in the portal. Format: xxxxx.api.infobip.com.
- PORT: The local port your Express server listens on (e.g., 3000). Used by server.js.
Fallback Mechanisms: Infobip handles retries for webhook delivery if your endpoint is
temporarily unavailable (as discussed under the 'Implementing the Delivery Report Endpoint' section). For
sending SMS, implement retries with exponential backoff in your client-side logic calling
/send-sms if the initial request fails due to network issues or temporary Infobip unavailability
(5xx errors).
Error Handling, Logging, and Retry Mechanisms
Error Handling Strategy
/send-smsEndpoint:- Validate incoming request bodies (presence of to, text). Return 400 Bad Request for invalid input.
- Wrap Infobip API calls in try...catch.
- Distinguish between Infobip API errors (error.response), network errors (error.request), and other server errors.
- Return appropriate HTTP status codes (4xx for client errors, 5xx for server/Infobip errors) and informative JSON error messages.
- Log detailed errors server-side for debugging (including Infobip's error payload).
/delivery-reportEndpoint:- Validate the basic structure of the incoming report (req.body.results array).
- Log received reports thoroughly.
- Wrap processing logic in try...catch to prevent crashes if a report has an unexpected format or processing fails.
- Crucially: Always return a 200 OK status to Infobip even if internal processing fails, unless the request format itself is completely unrecognizable. This acknowledges receipt and stops Infobip's retries. Log internal processing errors for later investigation.
Logging
- Current: Using console.log, console.warn, console.error. Suitable for development and simple cases.
- Production Recommendation: Use a dedicated logging library like Winston or Pino.
- Benefits: Structured logging (JSON format), different log levels (debug, info, warn, error), configurable outputs (console, file, external services), timestamps.
- Example Setup (Conceptual with Winston):
npm install winston
const winston = require('winston');
const logger = winston.createLogger({
level: process.env.LOG_LEVEL || 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.errors({ stack: true }),
winston.format.json()
),
defaultMeta: { service: 'infobip-callback-service' },
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),
],
});
if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
}));
}
module.exports = logger;
Replace console.log etc. with logger.info, logger.error, etc. in server.js (after importing the logger).
Retry Mechanisms
- Sending SMS (
/send-sms): Retries should be implemented by the client calling your /send-sms endpoint. If the client receives a 5xx error (indicating a server or temporary Infobip issue), it can retry using exponential backoff (e.g., wait 1s, then 2s, then 4s...). Avoid retrying on 4xx errors. - Receiving Delivery Reports (
/delivery-report): Infobip handles retries automatically if your endpoint doesn't respond with a 2xx status code. Your primary responsibility is to ensure your endpoint is reliable and acknowledges receipt promptly with a 200 OK.
Testing Error Scenarios:
- Send requests to /send-sms with missing to or text fields (expect 400).
- Temporarily use an invalid INFOBIP\_API\_KEY in .env and send an SMS (expect 401/500 with Infobip auth error).
- Send an SMS to an invalid phone number format (expect 4xx/500 with Infobip validation error).
- Temporarily stop your server after sending an SMS and observe Infobip's retry attempts in the Infobip portal logs (if available) or by restarting your server later and checking logs for delayed reports.
- Send a malformed JSON payload to /delivery-report using curl (expect 200 response but a warning in server logs).
Creating a Database Schema and Data Layer (Conceptual)
The current in-memory messageStore is unsuitable for production as it loses data on server
restart and doesn't scale.
Conceptual Schema (e.g., SQL):
CREATE TABLE sms_messages (
infobip_message_id VARCHAR(255) PRIMARY KEY,
application_message_id VARCHAR(255) NULL UNIQUE,
recipient_number VARCHAR(20) NOT NULL,
message_text TEXT NULL,
status_group VARCHAR(50) NULL,
status_name VARCHAR(100) NOT NULL,
status_description TEXT NULL,
error_group VARCHAR(50) NULL,
error_name VARCHAR(100) NULL,
error_description TEXT NULL,
is_permanent_error BOOLEAN DEFAULT FALSE,
segments_count INT NULL,
price_per_message DECIMAL(10, 5) NULL,
price_currency VARCHAR(3) NULL,
sent_at TIMESTAMPTZ NULL,
done_at TIMESTAMPTZ NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
last_updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE INDEX idx_sms_recipient_timestamp ON sms_messages (recipient_number, created_at DESC);
CREATE INDEX idx_sms_status_group ON sms_messages (status_group);
CREATE INDEX idx_sms_created_at ON sms_messages (created_at DESC);
CREATE OR REPLACE FUNCTION update_last_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.last_updated_at = NOW();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER update_sms_messages_last_updated
BEFORE UPDATE ON sms_messages
FOR EACH ROW
EXECUTE FUNCTION update_last_updated_at_column();
Data Access Layer (Conceptual using an ORM like Prisma or Sequelize):
- Setup: Install ORM (npm install @prisma/client, npm install prisma --save-dev or npm install sequelize pg pg-hstore). Initialize it (npx prisma init, npx sequelize init).
- Schema Definition: Define the model matching the table above in the ORM's schema definition language (e.g., schema.prisma, Sequelize models).
- Migrations: Generate and apply database migrations to create the table (npx prisma migrate dev, npx sequelize db:migrate).
- Implementation:
- Replace the messageStore object with an instance of your ORM client (e.g., const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient();).
- In /send-sms: After successfully getting a response from Infobip, use the ORM's create method to insert a new record into sms\_messages, storing the messageId, to, initial status, etc.
const sentMessage = infobipResponse.data.messages[0];
try {
await prisma.sms_message.create({
data: {
infobip_message_id: sentMessage.messageId,
recipient_number: sentMessage.to,
status_name: sentMessage.status.name,
status_group: sentMessage.status.groupName,
status_description: sentMessage.status.description,
}
});
console.log(`Stored initial record for Message ID ${sentMessage.messageId}`);
} catch (dbError) {
console.error(`Database error storing initial record for ${sentMessage.messageId}:`, dbError);
}
- In /delivery-report: For each report, use the ORM's update method (with a where clause on infobip\_message\_id) to update the status fields (status\_group, status\_name, error\_name, done\_at, etc.) and last\_updated\_at. Handle cases where the messageId might not exist in your database (e.g., log a warning).
try {
const updatedMessage = await prisma.sms_message.update({
where: { infobip_message_id: messageId },
data: {
status_name: statusName,
status_group: groupName,
status_description: status?.description,
error_name: errorName,
error_group: error?.groupName,
error_description: error?.description,
is_permanent_error: error?.permanent,
done_at: doneAt ? new Date(doneAt) : null,
price_per_message: price?.pricePerMessage,
price_currency: price?.currency,
segments_count: report.smsCount,
}
});
console.log(`Updated DB status for Message ID ${messageId} to ${statusName}`);
} catch (dbError) {
if (dbError.code === 'P2025') {
console.warn(`DB record not found for Message ID: ${messageId}. Storing report info might be needed.`);
} else {
console.error(`Database error updating status for ${messageId}:`, dbError);
}
}
This provides a persistent and scalable way to track message statuses. Remember to add proper database connection management, error handling for database operations, and potentially connection pooling for production environments.
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 β