-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.js
More file actions
35 lines (31 loc) · 857 Bytes
/
Copy pathMessage.js
File metadata and controls
35 lines (31 loc) · 857 Bytes
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
// models/Message.js
// Individual chat messages that belong to a Conversation.
const mongoose = require('mongoose');
const messageSchema = new mongoose.Schema(
{
conversation: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Conversation',
required: true,
},
// Who sent the message: the customer, an agent, or the AI bot itself
senderType: {
type: String,
enum: ['customer', 'agent', 'bot'],
required: true,
},
// Reference to the User document - null when senderType is 'bot'
sender: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
default: null,
},
content: {
type: String,
required: true,
},
},
{ timestamps: true }
);
messageSchema.index({ conversation: 1, createdAt: 1 });
module.exports = mongoose.model('Message', messageSchema);