Frequently Asked Questions
Use the Infobip API with a Node.js library like Axios. The provided code example demonstrates sending SMS messages by making POST requests to the Infobip API endpoint with recipient phone numbers, message content, and webhook configuration for delivery status updates. A unique correlationId is also included in the request to track messages.
SSE provides a lightweight, unidirectional channel for the server to push updates to the client. In this setup, after sending an SMS via Infobip, the backend uses SSE to push delivery status updates to the frontend as they're received from Infobip webhooks. This allows for a real-time status display without the overhead of WebSockets.
PostgreSQL offers a robust and reliable database solution for storing message status data. Prisma, an ORM, simplifies database interactions, allowing you to define the schema in a type-safe manner and generate a client for easy database queries and updates in your Node.js code. The example code demonstrates how to store pending, sent, delivered, and failed message status updates in the database using Prisma, along with details from Infobip about the status of sent messages and associated error details if any.
Infobip uses webhooks to send delivery reports asynchronously. Configure a webhook URL in your Infobip account settings or within each message request, pointing to your Node.js backend. When Infobip attempts message delivery, it will POST status updates to this URL. The example code's server.js file reminds users to ensure that their webhook is correctly configured.
Since Infobip needs a publicly accessible URL to send webhooks, ngrok creates a tunnel that exposes your locally running server. Infobip can then send webhook updates to your local server during development via the ngrok forwarding URL. The provided code sets up ngrok automatically.
The frontend initiates the SMS request and establishes an SSE connection to the backend using the correlationId. The backend then pushes status updates to the frontend via this SSE connection in real-time. Basic understanding of REST APIs and asynchronous JavaScript are listed as prerequisites.
The correlationId is a unique identifier generated for each SMS request on the backend. It serves as a link between the frontend request, the corresponding message in the database, and the SSE connection used for real-time updates. This ensures that status updates are delivered to the correct client.
A webhook secret adds an extra layer of security. Use it to verify that webhook requests are coming from Infobip and not a malicious source. The code example provides optional WEBHOOK_SECRET validation middleware to ensure webhook integrity.
Yes, though the provided example uses PostgreSQL with Prisma, you can adapt it to other databases and ORMs. Modify the databaseService accordingly to use a different database client library and update your schema definitions. Ensure alignment between database schema and the logic that updates and retrieves message status from the database.
The primary dependencies are: express for the backend framework, axios for HTTP requests, dotenv for environment variables, cors for cross-origin requests, sse-channel for Server-Sent Events, uuid for generating unique IDs, @prisma/client for Prisma, nodemon (dev) for automatic server restarts, and prisma (dev) for database migrations. These are all installed when setting up the project using npm.
The code example includes error handling within the webhook handler (handleInfobipWebhook). Each webhook report is processed individually within a try...catch block to prevent a single failed report from stopping the others. Error information, if available from Infobip, is logged, and the database is updated accordingly.
Ensure ngrok is running correctly and that the WEBHOOK_PUBLIC_URL in your .env file matches the URL provided by ngrok. Infobip must be able to reach your local server through this public URL.
Use a free Infobip trial account (be aware of limitations) along with ngrok for local testing. Send test SMS messages and observe the status updates logged in your Node.js backend and displayed in your frontend application. For persistent webhook URLs during development, consider paid ngrok or other alternatives like localtunnel.