Tutorials

Build Production-Ready SMS Appointment Scheduling & Reminders with NestJS and Vonage

A guide to building an SMS appointment scheduling and reminder system using NestJS, Vonage, PostgreSQL, and Prisma, including setup, API implementation, and scheduling.

JH
Jacky Hossein
β€’ Principal Telecommunications Architect β€’ Published Nov 4, 2026 β€’ 15 min read

Developer Quick-Start: A guide to building an SMS appointment scheduling and reminder system using NestJS, Vonage, PostgreSQL, and Prisma, including setup, API implementation, and scheduling. 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 complete walkthrough for building a robust SMS appointment scheduling and reminder system using NestJS, Node.js, PostgreSQL, Prisma, and the Vonage Messages API. You will learn how to create an API endpoint to schedule appointments, store them in a database, and automatically send SMS reminders at a specified time before the appointment.

We aim to build a reliable backend service capable of handling appointment creation and triggering timely SMS notifications. This solves the common business need for reducing no-shows and keeping users informed about their upcoming appointments.

Key Technologies:

  • Node.js: The JavaScript runtime environment.
  • NestJS: A progressive Node.js framework for building efficient, reliable, and scalable server-side applications. Its modular architecture, built-in dependency injection, and scheduling capabilities make it ideal.
  • Vonage Messages API: Used for sending SMS messages programmatically.
  • PostgreSQL: A powerful, open-source relational database.
  • Prisma: A modern database toolkit including an ORM (Object-Relational Mapper) for Node.js and TypeScript.
  • @nestjs/schedule: For running scheduled tasks (cron jobs) within NestJS to trigger reminders.
  • @nestjs/config: For managing environment variables securely.
  • class-validator & class-transformer: For robust request data validation.

System Architecture:

graph LR
    A[User/Client App] -- HTTP POST --> B(NestJS API /appointments);
    B -- Creates Appointment --> C{PostgreSQL Database};
    B -- Schedules Reminder --> D(NestJS Scheduler @Cron);
    D -- Queries DB for due reminders --> C;
    D -- Triggers SMS --> E(Vonage Messages API);
    E -- Sends SMS --> F[User's Phone];
    C -- Stores Appointment Data & Reminder Status --> C;
    B -- Returns Success/Error --> A;

    style B fill:#f9f,stroke:#333,stroke-width:2px
    style C fill:#ccf,stroke:#333,stroke-width:2px
    style D fill:#ff9,stroke:#333,stroke-width:2px
    style E fill:#f6e,stroke:#333,stroke-width:2px

Final Outcome & Prerequisites:

By the end of this guide, you will have a functional NestJS application with:

  • An API endpoint (POST /appointments) to schedule new appointments.
  • Database integration (PostgreSQL via Prisma) to store appointment details.
  • Automated SMS reminders sent via Vonage before the scheduled appointment time.
  • Configuration management, validation, error handling, and basic security.

Prerequisites:

  • Node.js (LTS version recommended) and npm or yarn installed.
  • Access to a PostgreSQL database (local or cloud-hosted).
  • A Vonage API account.
  • Vonage CLI installed (npm install -g @vonage/cli).
  • ngrok installed (optional, for testing inbound webhooks if needed later).
  • Basic understanding of TypeScript, NestJS concepts, and REST APIs.
  • Docker and Docker Compose (optional, for easy local database setup).

1. Setting up the Project

Let's initialize our NestJS project and install the necessary dependencies.

1.1 Install NestJS CLI:

If you don't have it installed globally, run:

npm install -g @nestjs/cli

1.2 Create New NestJS Project:

nest new vonage-sms-scheduler
cd vonage-sms-scheduler

Choose your preferred package manager (npm or yarn) when prompted.

1.3 Install Dependencies:

We need several packages for configuration, scheduling, database interaction, validation, and the Vonage SDK.

npm install @nestjs/config @nestjs/schedule @vonage/server-sdk class-validator class-transformer @prisma/client @nestjs/terminus @nestjs/axios

npm install --save-dev prisma typescript @nestjs/testing supertest jest @types/jest @types/supertest ts-jest ts-loader ts-node @types/express
  • @nestjs/config: For environment variable management.
  • @nestjs/schedule: For scheduling reminder jobs (uses node-cron internally).
  • @vonage/server-sdk: The official Vonage Node.js library.
  • class-validator, class-transformer: For input validation using DTOs.
  • @prisma/client, prisma: Prisma client and CLI for database interactions.
  • @nestjs/terminus, @nestjs/axios: For implementing health check endpoints.

1.4 Set up Prisma:

Initialize Prisma in your project:

npx prisma init --datasource-provider postgresql

This creates:

  • A prisma directory with a schema.prisma file.
  • A .env file at the project root (if it doesn't exist).

1.5 Configure Environment Variables (.env):

Open the .env file created by Prisma and add your database connection string and Vonage API credentials. Never commit this file to version control. Create a .env.example file to track necessary variables.

.env:

.env

# ---------------------
# DATABASE
# ---------------------
# Example for PostgreSQL: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public
DATABASE_URL="postgresql://your_db_user:your_db_password@localhost:5432/sms_scheduler?schema=public"

# ---------------------
# VONAGE API
# ---------------------
# Get these from your Vonage Dashboard -> API Settings
VONAGE_API_KEY="YOUR_VONAGE_API_KEY"
VONAGE_API_SECRET="YOUR_VONAGE_API_SECRET"

# ---------------------
# VONAGE APPLICATION
# ---------------------
# Create an application in the Vonage Dashboard or via CLI
# (See Vonage Integration section for details)
VONAGE_APPLICATION_ID="YOUR_VONAGE_APPLICATION_ID"
# Path relative to project root where the private key file is stored
# NOTE: For production, manage this key securely (e.g., volume mount, env var content), don't copy it into the image.
VONAGE_PRIVATE_KEY_PATH="./private.key"
VONAGE_SMS_FROM_NUMBER="YOUR_VONAGE_VIRTUAL_NUMBER" # Must be in E.164 format, e.g., 12015550123

# ---------------------
# APPLICATION
# ---------------------
# Port the NestJS app will run on
PORT=3000
# Reminder time in minutes before the appointment
REMINDER_LEAD_TIME_MINUTES=60

.env.example (Commit this file):

.env

# ---------------------
# DATABASE
# ---------------------
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public"

# ---------------------
# VONAGE API
# ---------------------
VONAGE_API_KEY=""
VONAGE_API_SECRET=""

# ---------------------
# VONAGE APPLICATION
# ---------------------
VONAGE_APPLICATION_ID=""
VONAGE_PRIVATE_KEY_PATH="./private.key"
VONAGE_SMS_FROM_NUMBER="" # Must be in E.164 format, e.g., 12015550123

# ---------------------
# APPLICATION
# ---------------------
PORT=3000
REMINDER_LEAD_TIME_MINUTES=60

Note: Ensure your VONAGE_SMS_FROM_NUMBER is a number purchased from Vonage and linked to your application (see Section 4). It should be in E.164 format (e.g., 14155552671).

1.6 Project Structure (Conceptual):

NestJS encourages a modular structure. We'll create modules for different concerns:

src/
β”œβ”€β”€ app.module.ts               # Root module
β”œβ”€β”€ main.ts                     # Application entry point
β”œβ”€β”€ config/                     # Configuration setup (optional explicit module, used via @nestjs/config)
β”œβ”€β”€ database/                   # Prisma setup
β”‚   β”œβ”€β”€ prisma.module.ts
β”‚   └── prisma.service.ts
β”œβ”€β”€ vonage/                     # Vonage integration
β”‚   β”œβ”€β”€ vonage.module.ts
β”‚   └── vonage.service.ts
β”œβ”€β”€ appointments/               # Core feature: Appointments
β”‚   β”œβ”€β”€ appointments.module.ts
β”‚   β”œβ”€β”€ appointments.controller.ts
β”‚   β”œβ”€β”€ appointments.service.ts
β”‚   β”œβ”€β”€ dto/
β”‚   β”‚   └── create-appointment.dto.ts
β”‚   └── entities/               # Not strictly needed with Prisma models
β”œβ”€β”€ scheduler/                  # Reminder scheduling task
β”‚   β”œβ”€β”€ scheduler.module.ts
β”‚   └── reminder.task.service.ts
└── health/                     # Health check endpoint
    β”œβ”€β”€ health.module.ts
    └── health.controller.ts
prisma/
β”œβ”€β”€ schema.prisma
└── migrations/
.env
.env.example
.gitignore
tsconfig.json
...

We will create these modules and files in the subsequent steps.


2. Implementing Core Functionality (Appointments & Scheduling)

Now, let's build the core logic for creating appointments and scheduling reminders.

2.1 Create Prisma Module:

This module provides the Prisma service for database interactions throughout the application.

nest g module database
nest g service database --no-spec

src/database/prisma.service.ts:

import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
  async onModuleInit() {


    await this.$connect();
  }

  async onModuleDestroy() {
    await this.$disconnect();
  }
}

src/database/prisma.module.ts:

import { Module, Global } from '@nestjs/common';
import { PrismaService } from './prisma.service';

@Global()
@Module({
  providers: [PrismaService],
  exports: [PrismaService],
})
export class PrismaModule {}

Register PrismaModule in AppModule:

src/app.module.ts:

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { PrismaModule } from './database/prisma.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    PrismaModule,

  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

2.2 Create Vonage Module:

Encapsulate Vonage SDK interaction within its own module and service.

nest g module vonage
nest g service vonage --no-spec

src/vonage/vonage.service.ts:

import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Vonage } from '@vonage/server-sdk';
import { MessageSendRequest } from '@vonage/messages';
import * as fs from 'fs';

@Injectable()
export class VonageService implements OnModuleInit {
  private readonly logger = new Logger(VonageService.name);
  private vonage: Vonage;
  private smsFromNumber: string;

  constructor(private configService: ConfigService) {}

  onModuleInit() {
    const apiKey = this.configService.get<string>('VONAGE_API_KEY');
    const apiSecret = this.configService.get<string>('VONAGE_API_SECRET');
    const applicationId = this.configService.get<string>('VONAGE_APPLICATION_ID');
    const privateKeyPath = this.configService.get<string>('VONAGE_PRIVATE_KEY_PATH');
    this.smsFromNumber = this.configService.get<string>('VONAGE_SMS_FROM_NUMBER');

    if (!apiKey || !apiSecret || !applicationId || !privateKeyPath || !this.smsFromNumber) {
      this.logger.error('Vonage API credentials or Application ID/Private Key path/From Number are missing in environment variables.');


      return;
    }

    try {



      const privateKey = fs.readFileSync(privateKeyPath, 'utf8');

      this.vonage = new Vonage({
        apiKey: apiKey,
        apiSecret: apiSecret,
        applicationId: applicationId,
        privateKey: privateKey,
      });
      this.logger.log('Vonage SDK Initialized Successfully.');

    } catch (error) {
        this.logger.error(`Failed to read private key file at ${privateKeyPath} or initialize Vonage SDK: ${error.message}`);

    }
  }

  async sendSms(to: string, text: string): Promise<string | null> {
    if (!this.vonage) {
        this.logger.error('Vonage SDK not initialized. Cannot send SMS.');
        return null;
    }
    if (!to || !text) {
        this.logger.warn('Missing recipient (to) or message text. SMS not sent.');
        return null;
    }


    const formattedTo = to.startsWith('+') ? to.replace(/\s+/g, '') : `+${to.replace(/\s+/g, '')}`;

    const message: MessageSendRequest = {
      message_type: 'text',
      to: formattedTo,
      from: this.smsFromNumber,
      channel: 'sms',
      text: text,
    };

    try {
      const response = await this.vonage.messages.send(message);
      this.logger.log(`SMS sent to ${formattedTo}. Message UUID: ${response.message_uuid}`);
      return response.message_uuid;
    } catch (error) {
      this.logger.error(`Failed to send SMS to ${formattedTo}: ${error.message}`, error.stack);

      if (error.response && error.response.data) {
          this.logger.error(`Vonage Error Details: ${JSON.stringify(error.response.data)}`);
      }
      return null;
    }
  }
}

src/vonage/vonage.module.ts:

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { VonageService } from './vonage.service';

@Module({
  imports: [ConfigModule],
  providers: [VonageService],
  exports: [VonageService],
})
export class VonageModule {}

Register VonageModule in AppModule:

src/app.module.ts:

import { VonageModule } from './vonage/vonage.module';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    PrismaModule,
    VonageModule,

  ],

})
export class AppModule {}

2.3 Create Appointments Module:

This module handles the creation and management of appointments.

nest g module appointments
nest g controller appointments --no-spec
nest g service appointments --no-spec

Define Data Transfer Object (DTO) for Validation:

src/appointments/dto/create-appointment.dto.ts:

import {
  IsNotEmpty,
  IsString,
  IsPhoneNumber,
  IsDateString,
  MinLength,
  IsOptional,
} from 'class-validator';

export class CreateAppointmentDto {
  @IsNotEmpty()
  @IsString()
  @MinLength(2)
  patientName: string;


  @IsNotEmpty()
  @IsPhoneNumber(null)
  patientPhone: string;

  @IsNotEmpty()
  @IsDateString()
  appointmentTime: string;

  @IsOptional()
  @IsString()
  notes?: string;
}

Implement Appointments Service:

src/appointments/appointments.service.ts:

import { Injectable, Logger, InternalServerErrorException, BadRequestException } from '@nestjs/common';
import { PrismaService } from '../database/prisma.service';
import { CreateAppointmentDto } from './dto/create-appointment.dto';
import { Appointment } from '@prisma/client';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class AppointmentsService {
  private readonly logger = new Logger(AppointmentsService.name);
  private readonly reminderLeadTimeMinutes: number;

  constructor(
      private prisma: PrismaService,
      private configService: ConfigService,
  ) {
      this.reminderLeadTimeMinutes = parseInt(
          this.configService.get<string>('REMINDER_LEAD_TIME_MINUTES', '60'),
          10,
      );
  }

  async create(createAppointmentDto: CreateAppointmentDto): Promise<Appointment> {
    const { patientName, patientPhone, appointmentTime, notes } = createAppointmentDto;


    const appointmentDateTime = new Date(appointmentTime);
    if (isNaN(appointmentDateTime.getTime())) {

        this.logger.error(`Invalid date format received: ${appointmentTime}`);
        throw new BadRequestException('Invalid appointmentTime format. Please use ISO 8601 format (UTC).');
    }


    const reminderTime = new Date(appointmentDateTime.getTime());
    reminderTime.setMinutes(reminderTime.getMinutes() - this.reminderLeadTimeMinutes);

    this.logger.log(`Scheduling appointment for ${patientName} at ${appointmentDateTime.toISOString()}, reminder at ${reminderTime.toISOString()}`);

    try {
        const newAppointment = await this.prisma.appointment.create({
            data: {
                patientName,

                patientPhone: patientPhone,
                appointmentTime: appointmentDateTime,
                reminderTime: reminderTime,
                notes,
                status: 'SCHEDULED',

            },
        });
        this.logger.log(`Appointment created with ID: ${newAppointment.id}`);
        return newAppointment;
    } catch (error) {
        this.logger.error(`Failed to create appointment: ${error.message}`, error.stack);

        throw new InternalServerErrorException('Could not create appointment.');
    }
  }

  async findDueReminders(checkTime: Date): Promise<Appointment[]> {
      const lookAheadMinutes = 2;
      const futureCheckTime = new Date(checkTime.getTime() + lookAheadMinutes * 60 * 1000);

      this.logger.log(`Checking for reminders due between now and ${futureCheckTime.toISOString()}`);

      try {
          const dueAppointments = await this.prisma.appointment.findMany({
              where: {
                  reminderTime: {
                      lte: futureCheckTime,
                  },
                  status: 'SCHEDULED',
                  reminderSentAt: null,
              },
          });
          this.logger.log(`Found ${dueAppointments.length} appointments needing reminders.`);
          return dueAppointments;
      } catch (error) {
          this.logger.error(`Error fetching due reminders: ${error.message}`, error.stack);
          return [];
      }
  }

  async markReminderSent(appointmentId: string): Promise<Appointment | null> {
      try {
          const updatedAppointment = await this.prisma.appointment.update({
              where: { id: appointmentId },
              data: {
                  reminderSentAt: new Date(),
                  status: 'REMINDER_SENT',
              },
          });
          this.logger.log(`Marked reminder as sent for appointment ID: ${appointmentId}`);
          return updatedAppointment;
      } catch (error) {

          this.logger.error(`Error marking reminder sent for appointment ID ${appointmentId}: ${error.message}`, error.stack);
          return null;
      }
  }
}

Implement Appointments Controller:

src/appointments/appointments.controller.ts:

import { Controller, Post, Body, ValidationPipe, UsePipes, Logger, HttpCode, HttpStatus, InternalServerErrorException, BadRequestException } from '@nestjs/common';
import { AppointmentsService } from './appointments.service';
import { CreateAppointmentDto } from './dto/create-appointment.dto';
import { Appointment } from '@prisma/client';

@Controller('appointments')
export class AppointmentsController {
  private readonly logger = new Logger(AppointmentsController.name);

  constructor(private readonly appointmentsService: AppointmentsService) {}

  @Post()
  @UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
  @HttpCode(HttpStatus.CREATED)
  async create(@Body() createAppointmentDto: CreateAppointmentDto): Promise<Appointment> {
    this.logger.log(`Received request to create appointment: ${JSON.stringify(createAppointmentDto)}`);

    try {
        const appointment = await this.appointmentsService.create(createAppointmentDto);
        return appointment;
    } catch (error) {

        this.logger.error(`Error creating appointment in controller: ${error.message}`, error.stack);



        if (error instanceof InternalServerErrorException || error instanceof BadRequestException) {
            throw error;
        }
        throw new InternalServerErrorException('An unexpected error occurred while creating the appointment.');
    }
  }
}

Configure Appointments Module:

src/appointments/appointments.module.ts:

import { Module } from '@nestjs/common';
import { AppointmentsService } from './appointments.service';
import { AppointmentsController } from './appointments.controller';

@Module({

  controllers: [AppointmentsController],
  providers: [AppointmentsService],
  exports: [AppointmentsService],
})
export class AppointmentsModule {}

Register AppointmentsModule in AppModule:

src/app.module.ts:

import { AppointmentsModule } from './appointments/appointments.module';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    PrismaModule,
    VonageModule,
    AppointmentsModule,

  ],

})
export class AppModule {}

2.4 Create Scheduler Module for Reminders:

This module will contain the scheduled task (cron job) that checks for due reminders and triggers SMS sending.

nest g module scheduler
nest g service scheduler/ReminderTask --flat --no-spec

src/scheduler/reminder.task.service.ts:

import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { AppointmentsService } from '../appointments/appointments.service';
import { VonageService } from '../vonage/vonage.service';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class ReminderTaskService {
  private readonly logger = new Logger(ReminderTaskService.name);
  private readonly reminderLeadTimeMinutes: number;

  constructor(
    private appointmentsService: AppointmentsService,
    private vonageService: VonageService,
    private configService: ConfigService,
  ) {
     this.reminderLeadTimeMinutes = parseInt(
         this.configService.get<string>('REMINDER_LEAD_TIME_MINUTES', '60'),
         10,
     );
  }


  @Cron(CronExpression.EVERY_MINUTE)
  async handleCron() {
    this.logger.log('Running reminder check cron job...');
    const now = new Date();

    const dueAppointments = await this.appointmentsService.findDueReminders(now);

    if (dueAppointments.length === 0) {
      this.logger.log('No reminders due at this time.');
      return;
    }

    this.logger.log(`Processing ${dueAppointments.length} reminders...`);

    for (const appointment of dueAppointments) {



      const reminderText = `Hi ${appointment.patientName}, this is a reminder for your appointment scheduled at ${appointment.appointmentTime.toLocaleString()}.`;

      this.logger.log(`Attempting to send reminder for appointment ID: ${appointment.id} to ${appointment.patientPhone}`);

      const messageUuid = await this.vonageService.sendSms(
        appointment.patientPhone,
        reminderText,
      );

      if (messageUuid) {

        await this.appointmentsService.markReminderSent(appointment.id);
        this.logger.log(`Reminder SMS sent successfully for appointment ID: ${appointment.id}, Vonage Message UUID: ${messageUuid}`);
      } else {


        this.logger.warn(`Failed to send reminder SMS for appointment ID: ${appointment.id}. It will be retried on the next run if not marked as sent.`);

      }
    }
    this.logger.log('Finished processing reminders.');
  }
}

src/scheduler/scheduler.module.ts:

import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { ReminderTaskService } from './reminder.task.service';
import { AppointmentsModule } from '../appointments/appointments.module';
import { VonageModule } from '../vonage/vonage.module';
import { ConfigModule } from '@nestjs/config';

@Module({
  imports: [
    ScheduleModule.forRoot(),
    AppointmentsModule,
    VonageModule,
    ConfigModule,
  ],
  providers: [ReminderTaskService],
})
export class AppSchedulerModule {}

Register AppSchedulerModule in AppModule:

src/app.module.ts:

import { AppSchedulerModule } from './scheduler/scheduler.module';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    PrismaModule,
    VonageModule,
    AppointmentsModule,
    AppSchedulerModule,

  ],

})
export class AppModule {}

2.5 Enable Validation Pipe Globally:

To ensure all incoming requests are validated against DTOs, enable the ValidationPipe globally.

src/main.ts:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const configService = app.get(ConfigService);
  const port = configService.get<number>('PORT', 3000);
  const logger = new Logger('Bootstrap');


  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true,
      forbidNonWhitelisted: true,
      transform: true,
      transformOptions: {
        enableImplicitConversion: true,
      },
    }),
  );


  app.enableCors({
      origin: '*',
      methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
      credentials: true,
  });

  await app.listen(port);
  logger.log(`Application is running on: ${await app.getUrl()}`);
  logger.log(`Reminder lead time set to: ${configService.get('REMINDER_LEAD_TIME_MINUTES')} minutes`);
  logger.log(`Vonage App ID: ${configService.get('VONAGE_APPLICATION_ID')}`);
  logger.log(`Vonage From Number: ${configService.get('VONAGE_SMS_FROM_NUMBER')}`);

}
bootstrap();

3. Building the API Layer

The primary API endpoint is POST /appointments, which we created in the previous section.

Endpoint Definition:

  • Method: POST
  • Path: /appointments
  • Description: Creates a new appointment and schedules an SMS reminder.
  • Request Body: CreateAppointmentDto (JSON)
  • Success Response: 201 Created with the created Appointment object (JSON).
  • Error Responses:
  • 400 Bad Request: If validation fails (e.g., invalid phone number, missing fields).
  • 500 Internal Server Error: If database operation or other internal process fails.

Request Example (JSON):

{
  "patientName": "Alice Wonderland",
  "patientPhone": "+12025550149",
  "appointmentTime": "2025-08-15T10:00:00.000Z",
  "notes": "Checkup"
}

Response Example (JSON - Success 201 Created):

{
  "id": "clxkpz4v00000unrp6hgz7r8q",
  "patientName": "Alice Wonderland",
  "patientPhone": "+12025550149",
  "appointmentTime": "2025-08-15T10:00:00.000Z",
  "reminderTime": "2025-08-15T09:00:00.000Z",
  "notes": "Checkup",
  "status": "SCHEDULED",
  "reminderSentAt": null,
  "createdAt": "2025-04-20T12:00:00.000Z",
  "updatedAt": "2025-04-20T12:00:00.000Z"
}

Testing with curl:

Replace placeholders with your actual data and running application URL (e.g., http://localhost:3000).

curl -X POST http://localhost:3000/appointments \
-H "Content-Type: application/json" \
-d '{
  "patientName": "Bob The Builder",
  "patientPhone": "+16505550162",
  "appointmentTime": "2025-09-20T15:30:00.000Z",
  "notes": "Follow-up visit"
}'

4. Integrating with Vonage

This involves setting up your Vonage account, application, and number correctly.

4.1 Vonage Account & Credentials:

  • Sign up for a Vonage API account if you haven't already.
  • Navigate to your Vonage API Dashboard.
  • Find your API Key and API Secret at the top of the dashboard. Add these to your .env file (VONAGE\_API\_KEY, VONAGE\_API\_SECRET).

4.2 Create a Vonage Application:

An application acts as a container for your configurations and links your virtual number. You can create this via the Dashboard or the CLI. Using the CLI is often faster for developers.

  • Authenticate CLI (if first time):
  vonage config:set --apiKey=YOUR_API_KEY --apiSecret=YOUR_API_SECRET
  • Create Application: We only need the Messages capability for sending SMS. Webhooks aren't strictly required for this guide's core functionality (sending reminders), but you might enable them if you plan to handle inbound messages later.
  vonage apps:create ""My SMS Scheduler App"" --capabilities=messages --messages_version=v1 --keyfile=private.key

4.3 Purchase and Link a Vonage Number:

You need a Vonage virtual number to send SMS messages from.

  • Search for Available Numbers (Example: US):
  vonage numbers:search US --features=SMS
  • Buy a Number: Choose a number from the list and buy it.
  vonage numbers:buy <NUMBER> US
  • Link the Number to Your Application:
  vonage apps:link <APP_ID> --number=<NUMBER>
  • Update .env: Add the purchased number (in E.164 format, e.g., 12015550123) to VONAGE\_SMS\_FROM\_NUMBER in your .env file.

4.4 Configure Private Key:

  • The vonage apps:create command generated a private.key file.
  • Ensure the VONAGE\_PRIVATE\_KEY\_PATH in your .env file correctly points to the location of this file relative to your project root (e.g., ./private.key).
  • Security: Add private.key to your .gitignore file. In production, manage this key securely (e.g., environment variable content, secrets manager, mounted volume) rather than committing it or copying it directly into container images.

Your Vonage integration setup is now complete. The VonageService uses these credentials and the private key to authenticate with the Vonage API for sending SMS messages.

Use NestJS's @nestjs/schedule module along with the Vonage Messages API. Create a scheduled task (cron job) that queries your database for upcoming appointments and sends SMS reminders via the Vonage API at the designated time before the appointment. This guide provides a complete walkthrough using PostgreSQL, Prisma, and other key technologies.

NestJS provides a structured, scalable backend framework. It facilitates API endpoint creation for scheduling, database integration with PostgreSQL via Prisma, and scheduled task management for sending SMS reminders through the Vonage Messages API. Its modular architecture and dependency injection simplify development and maintenance.

The Vonage Messages API allows you to programmatically send SMS messages. This is ideal for appointment reminders as it enables automation and ensures timely notifications to reduce no-shows and improve communication with users.

This guide uses PostgreSQL, a robust and open-source relational database, combined with Prisma, a modern database toolkit and ORM. Prisma simplifies database interactions and data modeling within the NestJS application.

These packages are crucial for request data validation. class-validator provides decorators for defining validation rules (e.g., required fields, data types, string length). class-transformer facilitates transforming request payloads into data transfer objects (DTOs), enforcing data integrity and security.

Obtain your API Key and API Secret from your Vonage API Dashboard. Store these securely in a .env file (never commit this to version control) and access them within your NestJS application using @nestjs/config for secure configuration management.

Use the Vonage CLI to create a new application with the Messages capability. The command vonage apps:create "My SMS Scheduler App" --capabilities=messages --messages_version=v1 --keyfile=private.key sets up an application and generates a private key file (ensure this key is stored securely).

A Vonage virtual number is required to send SMS messages via the Vonage API. After purchasing and linking a Vonage number to your application, add it to your .env file (VONAGE\_SMS\_FROM\_NUMBER) as the sender ID for your reminders. Ensure the number is in E.164 format (+12015550123).

Never commit the private.key file to version control. Instead, manage it through a secure method such as environment variables, a dedicated secrets manager, or mounting it as a volume in containerized environments (e.g. Kubernetes secrets).

Prisma is a modern database toolkit that includes an ORM (Object-Relational Mapper). It simplifies database interactions, schema management, and data modeling in your Node.js and TypeScript applications, making it easier to work with PostgreSQL or other supported databases.

The @nestjs/schedule module allows you to define cron jobs (scheduled tasks). A cron job runs every minute (using CronExpression.EVERY\_MINUTE) to check the database for appointments whose reminder time has passed but haven't had a reminder sent. If found, the app sends an SMS using the Vonage Messages API.

The @nestjs/config module provides a way to manage environment variables and application configuration securely. It helps access sensitive data like database credentials and API keys from a .env file without exposing them directly in the codebase. Create a .env.example file to track these environment variables.

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 β†’