Frequently Asked Questions
You can schedule SMS messages by sending a POST request to the /schedule endpoint with the recipient's phone number, message content, and desired send time (scheduledAt) in ISO 8601 format. The application uses NestJS to handle the request, validate the data, and interact with the Infobip API to schedule the message. The scheduled message details are stored in a PostgreSQL database using Prisma.
The Infobip SMS API is used to send and schedule SMS messages. The NestJS application integrates with this API to handle the actual sending and scheduling of messages after they are stored in the database. The Infobip Node.js SDK simplifies the integration process.
NestJS provides a robust and structured framework for building server-side applications. Its modular architecture, dependency injection, and built-in features like validation and configuration make it ideal for building reliable and scalable SMS scheduling systems. NestJS also works well with TypeScript, enhancing type safety and code maintainability.
An SMS scheduler is beneficial for automated reminders, notifications, and time-sensitive alerts. Use cases include appointment reminders, marketing campaigns, two-factor authentication, and any scenario requiring automated SMS messages at specific times.
Yes, you can cancel a scheduled SMS message by sending a DELETE request to the /schedule/{id} endpoint, where {id} is the unique identifier of the scheduled message. The application will attempt to cancel the message with Infobip and update the status in the database.
The application uses PostgreSQL as the database to store scheduled SMS message information. Prisma, a next-generation ORM, simplifies database interactions and provides type safety.
Obtain your Infobip API Key and Base URL from your Infobip account dashboard. These credentials should be stored securely in a .env file as INFOBIP_API_KEY and INFOBIP_BASE_URL. The NestJS ConfigModule loads these environment variables.
Prisma is an Object-Relational Mapper (ORM) that simplifies database operations. It allows you to define your data models in a schema file (schema.prisma), generate migrations, and interact with the database using type-safe methods.
Create a new NestJS project using the NestJS CLI, install the required dependencies (@nestjs/config, @infobip-api/sdk, prisma, @prisma/client, etc.), configure the environment variables (database URL, Infobip credentials), and set up the Prisma schema.
You need Node.js, npm or yarn, an Infobip account, access to a PostgreSQL database, basic familiarity with TypeScript, REST APIs, and asynchronous programming. Docker and Docker Compose are optional but recommended.
The provided code uses date-fns-tz library to handle timezone conversions. Although the application stores all dates internally in UTC, it accepts input dates with timezone offsets and parses them correctly. For the Infobip API call, always send the scheduledAt parameter as a UTC Date object, which ensures timezone-independent scheduling.
If cancellation with Infobip fails, the application will log the error and still mark the message as CANCELED in the database. This simplifies error handling but might mask potential issues with the Infobip API. For production, consider more advanced error handling strategies.
Use the GET /schedule endpoint to retrieve all scheduled messages or /schedule/{id} to get a specific message by ID. You can optionally filter by status using the status query parameter (e.g., /schedule?status=PENDING).
The bulkId is a unique identifier generated for each batch of scheduled SMS messages. It's used to reference the scheduled messages within Infobip, particularly for cancellation or status updates. This ensures that operations target the correct message batch.
Scheduled messages can have the following statuses: PENDING (scheduled in our DB but not yet sent to Infobip), SCHEDULED_INFOBIP (successfully scheduled with Infobip), SENT (confirmed sent by Infobip - requires webhooks), FAILED (failed to schedule or send), and CANCELED (canceled by user request).