Frequently Asked Questions
Create a NestJS controller with a POST endpoint that uses the Infobip Node.js SDK. This endpoint should handle user input (recipient and message content), construct the appropriate Infobip API request, and send the SMS message.
Infobip's callback mechanism provides asynchronous delivery status updates for sent SMS messages. This allows your application to track if and when a message was delivered, rather than relying solely on the initial send API response.
Delivery callbacks are crucial for knowing the final status of an SMS message. This information is essential for critical applications like two-factor authentication, appointment reminders, and emergency alerts, as network issues can cause delays or failures after the initial 'send' confirmation.
Implement delivery callbacks when reliable delivery tracking is crucial for the functionality of your application. This is particularly important when sending time-sensitive or transactional messages, such as one-time passwords or delivery confirmations.
Create a dedicated controller endpoint (/sms/callback/infobip
) in your NestJS app to receive POST requests from Infobip. This endpoint should process the callback data, validate its structure using a DTO, and then update the corresponding message status in your database.
The callbackData
field allows you to include a unique identifier (such as a UUID generated by your system) that Infobip will return in its delivery callbacks. This allows you to reliably correlate the callback data with the original message sent.
Parse the callback data (which includes delivery status, message ID, and your 'callbackData') using class-transformer. Use the 'callbackData' to locate the corresponding message in your database and then update the status accordingly. Implement idempotency checks to prevent duplicate processing if Infobip retries callbacks.
Prisma, an ORM, is used for database schema management and data access. You define the database schema (including an SmsMessage model to store information about each sent message) and Prisma generates efficient queries. This allows you to save message details, update their status after receiving callbacks, and easily access historical data.
Ngrok creates a secure public URL that tunnels to your local development server. Since Infobip needs to send callbacks to a publicly accessible URL, ngrok allows you to receive these callbacks while developing locally without deploying your application to a public server.
Use ngrok to create a public URL pointing to your local NestJS server. Update your .env file's APP_BASE_URL to the ngrok URL. Send a test SMS through your application and monitor your logs and the ngrok dashboard to confirm the callback is received and processed. Check your database to see updated message status from callbacks.
The article recommends using Node.js with NestJS, the Infobip API and Node.js SDK, Prisma as an ORM, SQLite or PostgreSQL/MySQL for the database, and tools like @nestjs/config, class-validator, @nestjs/throttler, and @nestjs/terminus.
The client interacts with the NestJS API to send SMS messages. The NestJS API uses the Infobip API to send messages, stores message status in a database, and receives callbacks from Infobip at a designated endpoint to update message status.
Decorate the PrismaModule with @Global() and export PrismaService in its exports array. This allows any service that needs database access to inject PrismaService without additional imports.
The notifyUrl
is the callback URL of your NestJS application that Infobip will use to send delivery reports (callbacks) asynchronously. This URL must be publicly accessible, often handled by ngrok during development and a public domain/IP in production.
Yes, Prisma supports other database providers like PostgreSQL and MySQL. Simply adjust the provider and URL configuration in your prisma/schema.prisma file and .env file. The rest of the setup remains largely the same.
Content Loading Error
We encountered an error while processing this content.