@peopl-health/nexus 3.15.7 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const KIND_VALUES = ['freeform', 'recovery_template'];
|
|
4
|
+
const STATUS_VALUES = [null, 'queued', 'sending', 'sent', 'delivered', 'undelivered', 'failed', 'read'];
|
|
5
|
+
|
|
6
|
+
const deliveryAttemptSchema = new mongoose.Schema({
|
|
7
|
+
messageId: {
|
|
8
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
9
|
+
ref: 'Message',
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
kind: {
|
|
13
|
+
type: String,
|
|
14
|
+
enum: KIND_VALUES,
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
twilioSid: { type: String, default: null },
|
|
18
|
+
contentSid: { type: String, default: null },
|
|
19
|
+
status: {
|
|
20
|
+
type: String,
|
|
21
|
+
enum: STATUS_VALUES,
|
|
22
|
+
default: null
|
|
23
|
+
},
|
|
24
|
+
errorCode: { type: String, default: null },
|
|
25
|
+
errorMessage: { type: String, default: null },
|
|
26
|
+
attemptedAt: { type: Date, default: Date.now, required: true },
|
|
27
|
+
completedAt: { type: Date, default: null },
|
|
28
|
+
raw: { type: mongoose.Schema.Types.Mixed, default: null }
|
|
29
|
+
}, { timestamps: true });
|
|
30
|
+
|
|
31
|
+
deliveryAttemptSchema.index({ messageId: 1, attemptedAt: 1 }, { name: 'message_attempt_history_idx' });
|
|
32
|
+
deliveryAttemptSchema.index({ kind: 1, status: 1, attemptedAt: -1 }, { name: 'analytics_idx' });
|
|
33
|
+
deliveryAttemptSchema.index({ twilioSid: 1 }, { name: 'twilio_sid_idx', sparse: true });
|
|
34
|
+
|
|
35
|
+
const DeliveryAttempt = mongoose.model('DeliveryAttempt', deliveryAttemptSchema);
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
DeliveryAttempt,
|
|
39
|
+
DELIVERY_ATTEMPT_KINDS: KIND_VALUES,
|
|
40
|
+
DELIVERY_ATTEMPT_STATUSES: STATUS_VALUES
|
|
41
|
+
};
|
|
@@ -8,6 +8,7 @@ const { logger } = require('../utils/logger');
|
|
|
8
8
|
const { getClinicalContext } = require('../helpers/patientInformationHelper');
|
|
9
9
|
|
|
10
10
|
const { updateRecordByFilter } = require('../services/airtableService');
|
|
11
|
+
const { DELIVERY_ATTEMPT_STATUSES } = require('./deliveryAttemptModel');
|
|
11
12
|
|
|
12
13
|
const { Thread } = require('./threadModel');
|
|
13
14
|
|
|
@@ -75,7 +76,7 @@ const messageSchema = new mongoose.Schema({
|
|
|
75
76
|
statusInfo: {
|
|
76
77
|
status: {
|
|
77
78
|
type: String,
|
|
78
|
-
enum:
|
|
79
|
+
enum: DELIVERY_ATTEMPT_STATUSES,
|
|
79
80
|
default: null
|
|
80
81
|
},
|
|
81
82
|
errorCode: { type: String, default: null },
|
|
@@ -85,7 +86,12 @@ const messageSchema = new mongoose.Schema({
|
|
|
85
86
|
recoveryStartedAt: { type: Date, default: null },
|
|
86
87
|
recoverySentAt: { type: Date, default: null },
|
|
87
88
|
recoveryMessageId: { type: String, default: null },
|
|
88
|
-
recoveryRejectedAt: { type: Date, default: null }
|
|
89
|
+
recoveryRejectedAt: { type: Date, default: null },
|
|
90
|
+
latestDeliveryStatus: {
|
|
91
|
+
type: String,
|
|
92
|
+
enum: DELIVERY_ATTEMPT_STATUSES,
|
|
93
|
+
default: null
|
|
94
|
+
}
|
|
89
95
|
},
|
|
90
96
|
prompt: { type: Object, default: null },
|
|
91
97
|
preset: { type: Object, default: null },
|