Skip to content

alrescha79-cmd/klinik-reservation-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ WhatsApp Bot Reservasi Klinik/Puskesmas

TypeScript Node.js Prisma License: ISC

Bot WhatsApp otomatis untuk sistem reservasi/pendaftaran pasien di Klinik atau Puskesmas. Dibangun dengan Node.js, TypeScript, Baileys MD, Prisma ORM, dan Express.js.


✨ Fitur Utama

  • 🏫 Manajemen Poli - Kelola departemen klinik (Poli Umum, Gigi, KIA, dll)
  • πŸ‘¨β€βš•οΈ Jadwal Poli & Dokter - Tampilkan jadwal praktik poli dan dokter
  • πŸ‘€ Pendaftaran Pasien - Daftar pasien baru langsung via WhatsApp
  • πŸ“… Sistem Reservasi - Buat reservasi dengan pilihan poli, dokter, tanggal & waktu
  • 🎫 Nomor Antrian - Generate nomor antrian otomatis per poli
  • πŸ“Š Cek Status - Cek status reservasi dan antrian
  • ❌ Pembatalan Fleksibel - Batalkan atau kembali ke menu kapan saja dengan BATAL/MENU
  • πŸ”Œ REST API - Full API endpoints untuk integrasi
  • πŸ’Ύ Database Support - PostgreSQL, MySQL, atau SQLite
  • οΏ½ Logging - Structured logging dengan Pino
  • βœ… Type-Safe - Full TypeScript dengan strict mode

πŸ“‹ Prerequisites

Sebelum memulai, pastikan sudah terinstall:

  • Node.js >= 18.x
  • npm atau yarn
  • Database: PostgreSQL / MySQL / SQLite
  • Git
  • Nomor WhatsApp untuk bot

πŸš€ Quick Start

1. Clone Repository

git clone https://github.com/alrescha79-cmd/klinik-reservation-bot.git
cd klinik-reservation-bot

2. Install Dependencies

npm install

3. Setup Environment

cp .env.example .env

Edit .env:

PORT=3000
DATABASE_URL="file:./dev.db"
ADMIN_PHONE="628xxxxxxxxx"
SESSION_FOLDER="./config/baileysSession"
NODE_ENV=development

4. Setup Database

# Generate Prisma client
npx prisma generate

# Run migrations
npx prisma migrate dev

# (Optional) Seed initial data
npx prisma db seed

5. Start Development Server

npm run dev

6. Scan QR Code

Buka terminal, scan QR Code yang muncul dengan WhatsApp:

  1. Buka WhatsApp di HP
  2. Pergi ke Settings > Linked Devices
  3. Tap Link a Device
  4. Scan QR code di terminal

βœ… Bot siap digunakan!


πŸ“± Cara Menggunakan Bot

Perintah WhatsApp

Perintah Fungsi
menu, mulai, hi, halo Tampilkan menu utama
daftar Pendaftaran pasien baru
jadwal Lihat jadwal poli (departemen klinik)
jadwal dokter Lihat jadwal praktik dokter
reservasi Buat reservasi/janji temu
cek antrian, cek Cek status reservasi
batal Batalkan reservasi
bantuan, help Tampilkan bantuan

πŸ†• Tip: Di setiap langkah interaktif, ketik BATAL atau MENU untuk kembali ke menu utama.

Flow Pendaftaran Pasien

  1. Kirim pesan: daftar
  2. Bot akan meminta data dengan format: Nama#NIK#TanggalLahir
  3. Contoh: Budi Santoso#1234567890123456#1990-05-15
  4. Bot konfirmasi pendaftaran berhasil

Flow Reservasi

  1. Kirim pesan: reservasi
  2. Pilih dokter (balas dengan angka)
  3. Pilih tanggal (balas dengan angka)
  4. Pilih waktu (balas dengan angka)
  5. Bot berikan nomor antrian (ex: A-015)

πŸ”™ Cancel: Ketik BATAL atau MENU kapan saja untuk kembali


πŸ”Œ REST API

Server berjalan di http://localhost:3000

Patient Endpoints

  • GET /api/patients - List semua pasien
  • GET /api/patients/:id - Detail pasien by ID
  • GET /api/patients/phone/:phone - Detail pasien by phone
  • POST /api/patients - Daftar pasien baru
  • PUT /api/patients/:id - Update data pasien
  • DELETE /api/patients/:id - Hapus pasien

Doctor Endpoints

  • GET /api/doctors - List semua dokter
  • GET /api/doctors/:id - Detail dokter by ID
  • POST /api/doctors - Tambah dokter baru
  • PUT /api/doctors/:id - Update data dokter
  • DELETE /api/doctors/:id - Hapus dokter
  • POST /api/doctors/seed - Seed data dokter sample

Reservation Endpoints

  • GET /api/reservations - List semua reservasi
  • GET /api/reservations/:id - Detail reservasi
  • GET /api/reservations/patient/:patientId - Reservasi by patient
  • GET /api/reservations/doctor/:doctorId - Reservasi by doctor
  • GET /api/reservations/date/:date - Reservasi by date
  • POST /api/reservations - Buat reservasi baru
  • PUT /api/reservations/:id - Update reservasi
  • DELETE /api/reservations/:id - Batalkan reservasi

Lihat dokumentasi lengkap API: docs/API.md


πŸ“ Struktur Project

/src
 β”œβ”€β”€ app.ts                 # Express app configuration
 β”œβ”€β”€ server.ts              # Server entry point
 β”œβ”€β”€ bot/
 β”‚    β”œβ”€β”€ index.ts          # Bot initialization
 β”‚    β”œβ”€β”€ baileys.ts        # Baileys WhatsApp connection
 β”‚    └── handlers/
 β”‚         β”œβ”€β”€ messageHandler.ts  # Handle incoming messages
 β”‚         └── eventHandler.ts    # Handle WA events
 β”œβ”€β”€ modules/
 β”‚    β”œβ”€β”€ patient/
 β”‚    β”‚    β”œβ”€β”€ patient.controller.ts  # HTTP handlers
 β”‚    β”‚    β”œβ”€β”€ patient.service.ts     # Business logic
 β”‚    β”‚    └── patient.route.ts       # Route definitions
 β”‚    β”œβ”€β”€ doctor/
 β”‚    β”‚    β”œβ”€β”€ doctor.controller.ts
 β”‚    β”‚    β”œβ”€β”€ doctor.service.ts
 β”‚    β”‚    └── doctor.route.ts
 β”‚    └── reservation/
 β”‚         β”œβ”€β”€ reservation.controller.ts
 β”‚         β”œβ”€β”€ reservation.service.ts
 β”‚         └── reservation.route.ts
 β”œβ”€β”€ prisma/
 β”‚    β”œβ”€β”€ schema.prisma     # Database schema
 β”‚    └── migrations/       # Database migrations
 β”œβ”€β”€ utils/
 β”‚    β”œβ”€β”€ logger.ts         # Pino logger wrapper
 β”‚    β”œβ”€β”€ formatter.ts      # Message formatters
 β”‚    └── validation.ts     # Zod validation schemas
 └── config/
      β”œβ”€β”€ env.ts            # Environment configuration
      └── baileysSession/   # WhatsApp session storage

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests with coverage
npm test -- --coverage

# Run tests in watch mode
npm test -- --watch

Lihat panduan testing: docs/TESTING.md


πŸ› οΈ Development

Available Scripts

npm run dev          # Start development server with hot-reload
npm run build        # Build TypeScript to JavaScript
npm start            # Start production server
npm test             # Run tests
npm run prisma:generate  # Generate Prisma client
npm run prisma:migrate   # Run database migrations
npm run prisma:studio    # Open Prisma Studio (DB GUI)

Development Tips

  • Gunakan npx prisma studio untuk GUI database
  • Log level bisa diubah di .env β†’ LOG_LEVEL=debug
  • Restart bot jika ada perubahan di schema.prisma
  • Session WhatsApp disimpan di config/baileysSession/

Lihat panduan development lengkap: docs/DEVELOPMENT.md


πŸš€ Production Deployment

Quick Deploy ke VPS

# Install dependencies
npm ci --production

# Setup database
npx prisma migrate deploy

# Build
npm run build

# Start with PM2
pm2 start dist/server.js --name wa-bot-klinik

Docker Deployment

docker-compose up -d

Lihat panduan deployment lengkap: docs/PRODUCTION.md


πŸ“š Documentation

Dokumentasi lengkap tersedia di folder /docs:


πŸ—„οΈ Database Schema

model Patient {
  id           Int           @id @default(autoincrement())
  name         String
  nik          String        @unique
  phone        String        @unique
  birthDate    DateTime
  address      String?
  createdAt    DateTime      @default(now())
  reservations Reservation[]
}

model Poli {
  id           Int           @id @default(autoincrement())
  name         String        @unique
  description  String?
  schedule     String        // JSON string
  isActive     Boolean       @default(true)
  createdAt    DateTime      @default(now())
  reservations Reservation[]
}

model Doctor {
  id           Int           @id @default(autoincrement())
  name         String
  specialty    String
  schedule     String        // JSON string
  createdAt    DateTime      @default(now())
  reservations Reservation[]
}

model Reservation {
  id              Int      @id @default(autoincrement())
  patientId       Int
  poliId          Int
  doctorId        Int?
  reservationDate DateTime
  reservationTime String
  queueNumber     String
  status          String   @default("pending")
  createdAt       DateTime @default(now())
  
  patient Patient @relation(fields: [patientId], references: [id])
  poli    Poli    @relation(fields: [poliId], references: [id])
  doctor  Doctor? @relation(fields: [doctorId], references: [id])
}

πŸ” Security

  • ⚠️ Jangan commit .env ke repository
  • ⚠️ Gunakan environment variables untuk credentials
  • ⚠️ Untuk production, tambahkan rate limiting dan authentication
  • ⚠️ Backup database secara berkala
  • ⚠️ Backup WhatsApp session di config/baileysSession/

πŸ› Troubleshooting

Bot tidak merespon pesan?

  1. Cek logs: Apakah ada error?
  2. Pastikan Message handler registered muncul di log
  3. Restart bot: rs di terminal nodemon
  4. Clear session & scan ulang QR

Database error?

# Reset database
npx prisma migrate reset

# Generate client ulang
npx prisma generate

Port sudah digunakan?

# Ganti PORT di .env
PORT=3001

# Atau kill process
lsof -ti:3000 | xargs kill -9

🀝 Contributing

Contributions are welcome! Please:

  1. Fork repository
  2. Create feature branch: git checkout -b feature/nama-fitur
  3. Commit changes: git commit -am 'Add feature'
  4. Push to branch: git push origin feature/nama-fitur
  5. Submit Pull Request

πŸ“„ License

This project is licensed under the ISC License.


πŸ‘¨β€πŸ’» Tech Stack

  • Runtime: Node.js 18+
  • Language: TypeScript 5.x
  • WhatsApp API: @whiskeysockets/baileys
  • Web Framework: Express.js
  • ORM: Prisma 6.x
  • Database: PostgreSQL / MySQL / SQLite
  • Validation: Zod
  • Logging: Pino
  • Testing: Jest
  • Process Manager: PM2 (production)

πŸ™ Acknowledgments

  • Baileys - WhatsApp Web API
  • Prisma - Next-generation ORM
  • Express - Fast, unopinionated web framework

πŸ“ž Support

Jika ada pertanyaan atau masalah:

  1. Check Documentation
  2. Review existing issues
  3. Create new issue

⭐ Star this repo if you find it useful!

Made with ❀️ for Indonesian Healthcare

About

πŸ₯ WhatsApp Bot untuk Sistem Reservasi Klinik/Puskesmas | Baileys MD + TypeScript + Prisma ORM | Auto Queue Management & Appointment Scheduling

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors