-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample-usage.js
More file actions
201 lines (166 loc) Β· 5.97 KB
/
example-usage.js
File metadata and controls
201 lines (166 loc) Β· 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Example usage of DispatchBot for Elderly Care Ride Service
// This script demonstrates how to integrate with your existing ride request system
// Updated to match your exact Mongoose models
const axios = require('axios');
// Configuration
const API_BASE = 'http://localhost:3000';
// Example data structures matching your exact models
const exampleServiceUser = {
uuid: "USER_001",
fullname: "John Smith",
phone: "+1234567890",
dob: "1940-05-15",
race: "white",
maritalStatus: "married",
residence: { current: "123 Main St", last: "123 Main St" },
income: { current: "retired", last: "retired" },
serviceUserRole: ["rider"],
veteranStatus: "veteran",
disabilityStatus: "yes"
};
const exampleServiceProvider = {
uuid: 1001,
fullName: "Mike Driver",
title: "Transportation Specialist",
organization: "EASTCONN",
phone: "+1987654321",
role: "Driver"
};
const exampleUserPreferences = {
notificationPreferences: { sms: true, email: false },
emergencyContacts: [
{
name: "Jane Smith",
phoneNumber: "+1234567890",
relationship: "Daughter",
priority: "primary"
}
],
roundtripUpdates: true,
mobilityAssistance: true,
communicationAssistance: false,
specialNeeds: ["wheelchair access"]
};
const exampleProviderPreferences = {
availability: {
days: [1, 2, 3, 4, 5], // Monday to Friday
hours: { start: "08:00", end: "18:00" },
isAvailable: true
},
specializations: ["wheelchair", "oxygen"],
emergencyAlerts: true,
systemMaintenance: false
};
// π― **SIMPLIFIED USAGE - Now Fully Automatic!**
// 1. **Set up user preferences** (one-time setup)
async function setupUserPreferences() {
try {
console.log('π§ Setting up user preferences...');
const response = await axios.put(`${API_BASE}/api/users/USER_001/preferences`, exampleUserPreferences);
console.log('β
User preferences set:', response.data);
} catch (error) {
console.error('β Error setting user preferences:', error.response?.data || error.message);
throw error;
}
}
// 2. **Set up driver preferences** (one-time setup)
async function setupDriverPreferences() {
try {
console.log('π§ Setting up driver preferences...');
const response = await axios.put(`${API_BASE}/api/drivers/1001/preferences`, exampleProviderPreferences);
console.log('β
Driver preferences set:', response.data);
} catch (error) {
console.error('β Error setting driver preferences:', error.response?.data || error.message);
throw error;
}
}
// 3. **Send emergency notification** (when needed)
async function sendEmergencyAlert() {
try {
console.log('π¨ Sending emergency alert...');
const response = await axios.post(`${API_BASE}/api/notifications/emergency`, {
recipient: "USER_001",
message: "Medical emergency during ride - immediate assistance needed"
});
console.log('β
Emergency alert sent:', response.data);
} catch (error) {
console.error('β Error sending emergency alert:', error.response?.data || error.message);
throw error;
}
}
// 4. **Check system status** (monitoring)
async function checkSystemStatus() {
try {
console.log('π Checking system status...');
const response = await axios.get(`${API_BASE}/api/dispatchbot/status`);
console.log('β
System status:', response.data);
} catch (error) {
console.error('β Error checking system status:', error.response?.data || error.message);
throw error;
}
}
// 5. **Check notification queue** (monitoring)
async function checkNotificationQueue() {
try {
console.log('π Checking notification queue...');
const response = await axios.get(`${API_BASE}/api/notifications/queue/status`);
console.log('β
Queue status:', response.data);
} catch (error) {
console.error('β Error checking queue status:', error.response?.data || error.message);
throw error;
}
}
// π **That's It! Everything Else is Automatic!**
// **What happens automatically when you use your ride app:**
// 1. Create ride β DispatchBot automatically detects and sends SMS
// 2. Update status β DispatchBot automatically detects and sends SMS
// 3. Assign driver β DispatchBot automatically detects and sends SMS
// 4. Assign vehicle β DispatchBot automatically detects and sends SMS
// 5. Complete ride β DispatchBot automatically detects and sends SMS
// **Complete setup and test example**
async function runCompleteSetup() {
try {
console.log('π Starting DispatchBot setup and test...\n');
// 1. Set up user preferences
await setupUserPreferences();
console.log('');
// 2. Set up driver preferences
await setupDriverPreferences();
console.log('');
// 3. Check system status
await checkSystemStatus();
console.log('');
// 4. Check notification queue
await checkNotificationQueue();
console.log('');
// 5. Test emergency alert
await sendEmergencyAlert();
console.log('');
console.log('π Setup complete! DispatchBot is now fully automatic!');
console.log('');
console.log('π± **To test automatic SMS:**');
console.log(' 1. Create a ride in your ride app (no changes needed)');
console.log(' 2. Update the ride status in your ride app (no changes needed)');
console.log(' 3. Watch DispatchBot automatically send SMS!');
console.log('');
console.log('π **Monitor everything:**');
console.log(' - Check status: GET /api/dispatchbot/status');
console.log(' - Check queue: GET /api/notifications/queue/status');
console.log(' - Emergency: POST /api/notifications/emergency');
} catch (error) {
console.error('β Setup failed:', error.message);
}
}
// Export functions for use
module.exports = {
setupUserPreferences,
setupDriverPreferences,
sendEmergencyAlert,
checkSystemStatus,
checkNotificationQueue,
runCompleteSetup
};
// Run setup if this file is executed directly
if (require.main === module) {
runCompleteSetup();
}