This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
conversationMessages.ts
96 lines (86 loc) · 2.41 KB
/
conversationMessages.ts
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
import { Document, Schema } from 'mongoose';
import { field } from './utils';
interface IEngageDataRules {
kind: string;
text: string;
condition: string;
value?: string;
}
interface IEngageDataRulesDocument extends IEngageDataRules, Document {}
export interface IEngageData {
messageId: string;
brandId: string;
content: string;
fromUserId: string;
kind: string;
sentAs: string;
rules?: IEngageDataRules[];
}
interface IEngageDataDocument extends IEngageData, Document {
rules?: IEngageDataRulesDocument[];
}
export interface IMessage {
content?: string;
attachments?: any;
mentionedUserIds?: string[];
conversationId: string;
internal?: boolean;
customerId?: string;
userId?: string;
fromBot?: boolean;
isCustomerRead?: boolean;
formWidgetData?: any;
messengerAppData?: any;
engageData?: IEngageData;
}
export interface IMessageDocument extends IMessage, Document {
_id: string;
engageData?: IEngageDataDocument;
createdAt: Date;
}
const attachmentSchema = new Schema(
{
url: field({ type: String }),
name: field({ type: String }),
size: field({ type: Number }),
type: field({ type: String }),
},
{ _id: false },
);
const engageDataRuleSchema = new Schema(
{
kind: field({ type: String }),
text: field({ type: String }),
condition: field({ type: String }),
value: field({ type: String, optional: true }),
},
{ _id: false },
);
const engageDataSchema = new Schema(
{
messageId: field({ type: String }),
brandId: field({ type: String }),
content: field({ type: String }),
fromUserId: field({ type: String }),
kind: field({ type: String }),
sentAs: field({ type: String }),
rules: field({ type: [engageDataRuleSchema], optional: true }),
},
{ _id: false },
);
export const messageSchema = new Schema({
_id: field({ pkey: true }),
content: field({ type: String }),
attachments: [attachmentSchema],
mentionedUserIds: field({ type: [String] }),
conversationId: field({ type: String, index: true }),
internal: field({ type: Boolean, index: true }),
customerId: field({ type: String, index: true }),
fromBot: field({ type: Boolean }),
userId: field({ type: String, index: true }),
createdAt: field({ type: Date, index: true }),
isCustomerRead: field({ type: Boolean }),
formWidgetData: field({ type: Object }),
messengerAppData: field({ type: Object }),
engageData: field({ type: engageDataSchema }),
});