Frequently Asked Questions
Use Next.js API routes to handle scheduling requests, store them in a database (like Vercel Postgres), and trigger sending via a cron job. The frontend UI collects recipient details, message, and scheduled time, while the backend manages storage and interaction with the Plivo SMS API.
Plivo is the cloud communications platform used to actually send the SMS messages. The Next.js app interacts with Plivo's API using the Plivo Node.js SDK, providing the recipient's phone number and message content.
Vercel Cron Jobs offer a serverless way to trigger the SMS sending process at specified intervals. The cron job calls a dedicated Next.js API route, which queries the database for pending messages and initiates sending via Plivo.
Use prisma db push for initial setup and simple schema updates during development. For production environments or complex schema changes, use prisma migrate dev (locally) and prisma migrate deploy (in CI/CD) for safer, versioned migrations.
Create a Postgres database from the Vercel Dashboard Storage tab. Connect this database to your Vercel project, and then copy the provided POSTGRES_PRISMA_URL and POSTGRES_URL_NON_POOLING connection strings into your project's .env.local file.
Prisma acts as the Object-Relational Mapper (ORM) simplifying database interactions. It enables type-safe data access, schema management, and handles the connection to the Vercel Postgres database.
After setting up a Plivo account and purchasing a number, use the Plivo Node.js SDK within your Next.js API route. Provide your Plivo Auth ID, Auth Token, sender number, recipient number, and message body to the client.messages.create method.
The status field in the Schedule model tracks the state of each scheduled message (PENDING, SENT, or FAILED). This allows the cron job to identify which messages need processing and provides a record of successful and failed attempts.
The application stores all dates and times in UTC. The frontend handles time zone conversion, ensuring that the backend receives and stores times in UTC, preventing discrepancies and ensuring messages are sent at the correct time.
Yes, run npm run dev to start the development server. Then use curl, Postman, or Insomnia to send test POST requests to the API endpoint (/api/schedule), providing the necessary data in JSON format.
Wrap your Plivo API calls in a try...catch block. The sendPlivoSms helper function already provides error handling and returns a result object with a success flag and an optional error message to handle specific issues.
Zod provides robust schema validation for incoming API requests, ensuring that data conforms to the expected format and preventing potential errors or security vulnerabilities from malformed data.
Store Plivo credentials (Auth ID, Auth Token), database URLs, and other secrets in environment variables (.env.local). This file is automatically excluded from Git, preventing accidental exposure.
Vercel automatically captures console output from Serverless Functions and Cron Jobs. You can view these logs in your Vercel project dashboard under the deployments section for the corresponding function.