Your DispatchBot is designed to work seamlessly with your existing Mongoose models and data structure. No changes to your current system are required!
// Your existing Mongoose model - NO CHANGES NEEDED
const userSchema = new mongoose.Schema({
uuid: { type: String, required: true, unique: true },
fullname: { type: String, required: true },
phone: { type: String, required: true },
dob: { type: String, required: true },
race: { type: String, required: true, enum: ['black', 'white', 'asian', 'latino', 'native american', 'other', 'prefer not to say'] },
maritalStatus: { type: String, required: true, enum: ['single', 'married', 'divorced', 'widowed', 'separated', 'other', 'prefer not to say'] },
residence: {
current: { type: String, required: false },
last: { type: String, required: true }
},
income: {
current: { type: String, required: false },
last: { type: String, required: true }
},
serviceUserRole: { type: [String], required: true, enum: ['rider', 'caregiver', 'relative', 'guardian', 'case manager', 'other'] },
veteranStatus: { type: String, required: false, enum: ['veteran', 'not veteran', 'prefer not to say'] },
disabilityStatus: { type: String, required: false, enum: ['yes', 'no', 'prefer not to say'] }
}, { timestamps: true });// Your existing Mongoose model - NO CHANGES NEEDED
const serviceProviderSchema = new mongoose.Schema({
uuid: { type: Number, required: true, unique: true },
fullName: { type: String, required: true },
title: { type: String, required: true },
organization: { type: String, required: true, enum: ['EASTCONN', 'Generations Health', 'other'] },
phone: { type: String, required: true },
role: { type: String, required: true, enum: ['Transport Broker', 'Staff', 'Fleet Manager', 'Driver', 'Admin'] },
specializations: { type: String, enum: ['Caseworker', 'Nutritionist', 'Intake'] },
faxPhone: { type: String, required: false }
}, { timestamps: true });// Your existing ride request structure - NO CHANGES NEEDED
interface RideRequest {
rideRequestUuid: string;
serviceUserUuid: string;
pickupBaseAddress: string;
dropoffBaseAddress: string;
pickupLocationUuid: string;
dropoffLocationUuid: string;
assignedVehicleUuid?: string;
assignedDriverUuid?: string;
roundtrip: boolean;
pickupRequestedDatetime: Date;
dropoffRequestedDatetime: Date;
rideStartedActualDatetime?: Date;
pickupActualDatetime?: Date;
dropoffActualDatetime?: Date;
roundtripReturningActualDatetime?: Date;
roundtripCompletedActualDatetime?: Date;
rideCompleteRequestedDatetime?: Date;
rideCompletedActualDatetime?: Date;
rideStatus: RideRequestStatus; // Your exact status codes
purposeOfTrip: string;
rideRequestStatus: string;
notes?: string;
}// Your existing code - DispatchBot automatically detects this
const newUser = await User.create({
uuid: "USER_001",
fullname: "Margaret Johnson",
phone: "+1234567890",
dob: "1945-03-15",
race: "white",
maritalStatus: "widowed",
serviceUserRole: ["rider"],
// ... other fields
});
const newProvider = await ServiceProvider.create({
uuid: 1001,
fullName: "John Driver",
title: "Transportation Specialist",
organization: "EASTCONN",
phone: "+1987654321",
role: "Driver"
});// DispatchBot reads from your existing collections
const userPrefsManager = new UserPrefsManager(db);
// Get user from your existing 'users' collection
const user = await userPrefsManager.getServiceUser("USER_001");
// Get provider from your existing 'serviceproviders' collection
const provider = await userPrefsManager.getServiceProvider(1001);// When you update ride status, DispatchBot automatically sends SMS
PUT /api/rides/RIDE_123/status
{
"status": 300, // Your status code for "Rider Picked Up"
"reason": null
}
// DispatchBot automatically:
// 1. Updates your ride request
// 2. Sends SMS to elderly person: "You have been picked up!"
// 3. Logs the event
// 4. Updates notification queuenpm installcp env.example .env
# Edit .env with your MongoDB connection and Twilio credentialsnpm run devnode example-usage.js// Create service user (uses your exact model)
POST /api/users
{
"uuid": "USER_001",
"fullname": "Margaret Johnson",
"phone": "+1234567890",
"dob": "1945-03-15",
"race": "white",
"maritalStatus": "widowed",
"serviceUserRole": ["rider"],
"veteranStatus": "not veteran",
"disabilityStatus": "yes"
}
// Get user preferences
GET /api/users/USER_001/preferences
// Update user preferences
PUT /api/users/USER_001/preferences
{
"notificationPreferences": { "sms": true, "email": false },
"emergencyContacts": [
{
"name": "Jane Smith",
"phoneNumber": "+1234567890",
"relationship": "Daughter",
"priority": "primary"
}
]
}// Create service provider (uses your exact model)
POST /api/providers
{
"uuid": 1001,
"fullName": "John Driver",
"title": "Transportation Specialist",
"organization": "EASTCONN",
"phone": "+1987654321",
"role": "Driver"
}
// Get provider preferences
GET /api/providers/1001/preferences
// Update provider preferences
PUT /api/providers/1001/preferences
{
"availability": {
"days": [1, 2, 3, 4, 5],
"hours": { "start": "08:00", "end": "18:00" },
"isAvailable": true
},
"specializations": ["wheelchair", "oxygen"]
}// Create ride request (uses your exact format)
POST /api/rides
{
"rideRequestUuid": "RIDE_123",
"serviceUserUuid": "USER_001",
"pickupBaseAddress": "123 Main St",
"dropoffBaseAddress": "456 Oak Ave",
"rideStatus": 0, // Your status code
"roundtrip": true,
"purposeOfTrip": "Medical appointment"
}
// Update ride status (triggers automatic SMS)
PUT /api/rides/RIDE_123/status
{
"status": 100, // Your status code for "Confirmed"
"reason": null
}
// Assign driver
POST /api/rides/RIDE_123/assign
{
"driverUuid": 1001
}users- Your service usersserviceproviders- Your drivers/staffrideRequests- Your ride requests
userPreferences- Communication preferencesserviceProviderPreferences- Driver preferencesnotificationQueue- SMS notification queuerideEvents- Ride lifecycle eventsmessageTemplates- SMS message templates
// Your existing code - no changes needed
const rideRequest = await RideRequest.create({
rideRequestUuid: "RIDE_2024_001",
serviceUserUuid: "USER_001",
pickupBaseAddress: "123 Main St, Anytown",
dropoffBaseAddress: "456 Oak Ave, Anytown",
rideStatus: 0, // In Progress
roundtrip: true,
purposeOfTrip: "Doctor appointment"
});// DispatchBot automatically:
// - Stores ride request
// - Creates "REQUEST_CREATED" event
// - Sends SMS: "Your ride request has been received!"
// - Queues pickup reminder (15 min before)// Your existing code - no changes needed
await RideRequest.updateOne(
{ rideRequestUuid: "RIDE_2024_001" },
{ assignedDriverUuid: 1001 }
);// DispatchBot automatically:
// - Creates "DRIVER_ASSIGNED" event
// - Sends SMS to elderly: "Driver John assigned!"
// - Sends SMS to driver: "New ride request assigned"// Your system updates status
PUT /api/rides/RIDE_2024_001/status
{ "status": 300 } // Rider picked up
// DispatchBot automatically:
// - Updates ride status
// - Sends SMS: "You have been picked up!"
// - Logs the event// When emergency detected:
await sendEmergencyNotification(
"USER_001",
"Medical emergency during ride"
);
// DispatchBot automatically:
// 1. Sends urgent SMS to elderly person
// 2. Notifies all emergency contacts
// 3. Alerts support team
// 4. Updates ride status to interrupted (209)
// 5. Logs emergency for follow-up// Set up emergency contacts using your existing user UUIDs
PUT /api/users/USER_001/preferences
{
"emergencyContacts": [
{
"name": "Jane Smith",
"phoneNumber": "+1234567890",
"relationship": "Daughter",
"priority": "primary"
},
{
"name": "Robert Johnson",
"phoneNumber": "+1234567891",
"relationship": "Son",
"priority": "secondary"
}
]
}// Customize SMS messages for your organization
await templateManager.createTemplate({
name: 'EASTCONN Welcome',
category: 'general',
language: 'en',
template: 'Welcome to EASTCONN transportation! Your ride is scheduled for {pickupTime}.',
variables: ['pickupTime']
});// Set communication preferences per elderly person
PUT /api/users/USER_001/preferences
{
"notificationPreferences": {
"sms": true,
"email": false
},
"rideUpdates": {
"requestConfirmation": true,
"driverAssigned": true,
"pickupReminder": true,
"delays": true
},
"accessibility": {
"requiresLargeText": true,
"requiresVoiceCalls": false,
"preferredContactTime": "business-hours"
}
}// Get system status
GET /api/dispatchbot/status
// Get notification queue status
GET /api/notifications/queue/status
// Get ride notification statistics
GET /api/rides/RIDE_123/notifications- SMS delivery success rate
- Notification response times
- Queue processing speed
- Emergency response times
- Ride completion rates
# Check Twilio credentials
curl http://localhost:3000/api/dispatchbot/status
# Verify webhook URLs in Twilio console
# Check .env file for TWILIO_* variables# Test MongoDB connection
curl http://localhost:3000/health
# Verify MONGODB_URI in .env file
# Check MongoDB is running# Check queue status
curl http://localhost:3000/api/notifications/queue/status
# Verify notification queue is running
# Check for error logs- No system changes required - Works with existing data
- Automated operations - Reduces manual work
- Improved safety - Emergency alerts and monitoring
- Better user experience - Timely updates for elderly
- Scalable system - Handles multiple rides simultaneously
- Clear communication about ride status
- Timely reminders for pickup times
- Emergency support when needed
- Accessibility options (large text, voice calls)
- Real-time updates about loved ones' rides
- Emergency notifications for safety
- Ride tracking and status monitoring
- Voice calls for users who prefer phone communication
- Multi-language support (Spanish, French, etc.)
- Integration with medical alert systems
- Advanced analytics and reporting
- Mobile app for real-time updates
- GPS tracking for real-time location updates
- Weather alerts for ride scheduling
- Medical appointment integration
- Caregiver portal for ride management
- Documentation - Check this guide and README
- Example Code - Run
example-usage.js - API Testing - Use the health check endpoints
- Logs - Check console output for errors
For critical issues affecting production:
- Email - [email protected]
- Phone - +1-XXX-XXX-XXXX
- Slack - #dispatchbot-support
Your DispatchBot is now perfectly integrated with your existing system. It will:
โ
Automatically detect your service users and providers
โ
Work with your exact data models and field names
โ
Handle your status codes (0, 100, 200, 300, etc.)
โ
Send SMS notifications via Twilio
โ
Manage emergency situations automatically
โ
Provide real-time monitoring and analytics
No changes to your existing code required! Just start the DispatchBot and it will begin working with your data immediately.
DispatchBot - Making transportation accessible and safe for everyone
Built specifically for EASTCONN and Generations Health with your exact data structure.