/
IRoom.ts
378 lines (323 loc) · 10.3 KB
/
IRoom.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import type { ILivechatPriority } from './ILivechatPriority';
import type { ILivechatVisitor } from './ILivechatVisitor';
import type { IMessage, MessageTypesValues } from './IMessage';
import type { IOmnichannelServiceLevelAgreements } from './IOmnichannelServiceLevelAgreements';
import type { IRocketChatRecord } from './IRocketChatRecord';
import type { IUser, Username } from './IUser';
import type { RoomType } from './RoomType';
type CallStatus = 'ringing' | 'ended' | 'declined' | 'ongoing';
export type RoomID = string;
export type ChannelName = string;
interface IRequestTranscript {
email: string; // the email address to send the transcript to
subject: string; // the subject of the email
requestedAt: Date;
requestedBy: Pick<IUser, '_id' | 'username' | 'name' | 'utcOffset'>;
}
export interface IRoom extends IRocketChatRecord {
_id: RoomID;
t: RoomType;
name?: string;
fname?: string;
msgs: number;
default?: boolean;
broadcast?: true;
featured?: true;
announcement?: string;
joinCodeRequired?: boolean;
announcementDetails?: {
style?: string;
};
encrypted?: boolean;
topic?: string;
reactWhenReadOnly?: boolean;
// TODO: this boolean might be an accident
sysMes?: MessageTypesValues[] | boolean;
u: Pick<IUser, '_id' | 'username' | 'name'>;
uids?: Array<string>;
lastMessage?: IMessage;
lm?: Date;
usersCount: number;
callStatus?: CallStatus;
webRtcCallStartTime?: Date;
servedBy?: {
_id: string;
};
streamingOptions?: {
id?: string;
type?: string;
url?: string;
thumbnail?: string;
isAudioOnly?: boolean;
message?: string;
};
prid?: string;
avatarETag?: string;
teamMain?: boolean;
teamId?: string;
teamDefault?: boolean;
open?: boolean;
autoTranslateLanguage?: string;
autoTranslate?: boolean;
unread?: number;
alert?: boolean;
hideUnreadStatus?: boolean;
hideMentionStatus?: boolean;
muted?: string[];
unmuted?: string[];
usernames?: string[];
ts?: Date;
cl?: boolean;
ro?: boolean;
favorite?: boolean;
archived?: boolean;
description?: string;
createdOTR?: boolean;
e2eKeyId?: string;
/* @deprecated */
federated?: boolean;
/* @deprecated */
customFields?: Record<string, any>;
channel?: { _id: string };
}
export const isRoomWithJoinCode = (room: Partial<IRoom>): room is IRoomWithJoinCode =>
'joinCodeRequired' in room && (room as any).joinCodeRequired === true;
export interface IRoomWithJoinCode extends IRoom {
joinCodeRequired: true;
joinCode: string;
}
export interface IRoomFederated extends IRoom {
federated: true;
}
export const isRoomFederated = (room: Partial<IRoom>): room is IRoomFederated => 'federated' in room && (room as any).federated === true;
export interface ICreatedRoom extends IRoom {
rid: string;
inserted: boolean;
}
export interface ITeamRoom extends IRoom {
teamMain: boolean;
teamId: string;
}
export const isTeamRoom = (room: Partial<IRoom>): room is ITeamRoom => !!room.teamMain;
export const isPrivateTeamRoom = (room: Partial<IRoom>): room is ITeamRoom => isTeamRoom(room) && room.t === 'p';
export const isPublicTeamRoom = (room: Partial<IRoom>): room is ITeamRoom => isTeamRoom(room) && room.t === 'c';
export const isDiscussion = (room: Partial<IRoom>): room is IRoom => !!room.prid;
export const isPrivateDiscussion = (room: Partial<IRoom>): room is IRoom => isDiscussion(room) && room.t === 'p';
export const isPublicDiscussion = (room: Partial<IRoom>): room is IRoom => isDiscussion(room) && room.t === 'c';
export const isPublicRoom = (room: Partial<IRoom>): room is IRoom => room.t === 'c';
export interface IDirectMessageRoom extends Omit<IRoom, 'default' | 'featured' | 'u' | 'name'> {
t: 'd';
uids: Array<string>;
usernames: Array<Username>;
}
export const isDirectMessageRoom = (room: Partial<IRoom> | IDirectMessageRoom): room is IDirectMessageRoom => room.t === 'd';
export const isMultipleDirectMessageRoom = (room: IRoom | IDirectMessageRoom): room is IDirectMessageRoom =>
isDirectMessageRoom(room) && room.uids.length > 2;
export enum OmnichannelSourceType {
WIDGET = 'widget',
EMAIL = 'email',
SMS = 'sms',
APP = 'app',
API = 'api',
OTHER = 'other', // catch-all source type
}
export interface IOmnichannelGenericRoom extends Omit<IRoom, 'default' | 'featured' | 'broadcast' | ''> {
t: 'l' | 'v';
v: Pick<ILivechatVisitor, '_id' | 'username' | 'status' | 'name' | 'token' | 'activity'> & {
lastMessageTs?: Date;
phone?: string;
};
email?: {
// Data used when the room is created from an email, via email Integration.
inbox: string;
thread: string[];
replyTo: string;
subject: string;
};
source: {
// TODO: looks like this is not so required as the definition suggests
// The source, or client, which created the Omnichannel room
type: OmnichannelSourceType;
// An optional identification of external sources, such as an App
id?: string;
// A human readable alias that goes with the ID, for post analytical purposes
alias?: string;
// A label to be shown in the room info
label?: string;
// The sidebar icon
sidebarIcon?: string;
// The default sidebar icon
defaultIcon?: string;
};
// Note: this field is used only for email transcripts. For Pdf transcripts, we have a separate field.
transcriptRequest?: IRequestTranscript;
servedBy?: {
_id: string;
ts: Date;
username: IUser['username'];
};
onHold?: boolean;
departmentId?: string;
lastMessage?: IMessage & { token?: string };
tags?: string[];
closedAt?: Date;
metrics?: {
serviceTimeDuration?: number;
};
// set to true when the room is waiting for a response from the visitor
waitingResponse: any;
// contains information about the last response from an agent
responseBy?: {
_id: string;
username: string;
// when the agent first responded to the visitor after the latest message from visitor
// this will reset when the visitor sends a new message
firstResponseTs: Date;
// when the agent last responded to the visitor
// This is almost the same as firstResponseTs, but here we hold the timestamp of the last response
// and it gets updated after each message from agent
// So if an agent sends multiple messages to visitor, then firstResponseTs will store timestamp
// of their first reply, and lastMessageTs will store timestamp of their latest response
lastMessageTs: Date;
};
livechatData: any;
queuedAt?: Date;
status?: 'queued' | 'taken' | 'ready'; // TODO: missing types for this
ts: Date;
label?: string;
crmData?: unknown;
// optional keys for closed rooms
closer?: 'user' | 'visitor';
closedBy?: {
_id: string;
username: IUser['username'];
};
closingMessage?: IMessage;
departmentAncestors?: string[];
}
export interface IOmnichannelRoom extends IOmnichannelGenericRoom {
t: 'l';
omnichannel?: {
predictedVisitorAbandonmentAt: Date;
};
// sms field is used when the room is created from one of the internal SMS integrations (e.g. Twilio)
sms?: {
from: string;
};
// Following props are used for priorities feature
priorityId?: string;
priorityWeight: ILivechatPriority['sortItem']; // It should always have a default value for sorting mechanism to work
// Following props are used for SLA feature
slaId?: string;
estimatedWaitingTimeQueue: IOmnichannelServiceLevelAgreements['dueTimeInMinutes']; // It should always have a default value for sorting mechanism to work
// Signals if the room already has a pdf transcript requested
// This prevents the user from requesting a transcript multiple times
pdfTranscriptRequested?: boolean;
// The ID of the pdf file generated for the transcript
// This will help if we want to have this file shown on other places of the UI
pdfTranscriptFileId?: string;
metrics?: {
serviceTimeDuration?: number;
chatDuration?: number;
v?: {
lq: Date;
};
servedBy?: {
lr: Date;
};
response?: {
tt: number;
total: number;
avg: number;
ft: number;
};
reaction?: {
ft: number;
};
};
// Both fields are being used for the auto transfer feature for unanswered chats
// which is controlled by Livechat_auto_transfer_chat_timeout setting
autoTransferredAt?: Date;
autoTransferOngoing?: boolean;
}
export interface IVoipRoom extends IOmnichannelGenericRoom {
t: 'v';
name: string;
// The timestamp when call was started
callStarted: Date;
// The amount of time the call lasted, in milliseconds
callDuration?: number;
// The amount of time call was in queue in milliseconds
callWaitingTime?: number;
// The total of hold time for call (calculated at closing time) in seconds
callTotalHoldTime?: number;
// The pbx queue the call belongs to
queue: string;
// The ID assigned to the call (opaque ID)
callUniqueId?: string;
v: Pick<ILivechatVisitor, '_id' | 'username' | 'status' | 'name' | 'token'> & { lastMessageTs?: Date; phone?: string };
// Outbound means the call was initiated from Rocket.Chat and vise versa
direction: 'inbound' | 'outbound';
}
export interface IOmnichannelRoomFromAppSource extends IOmnichannelRoom {
source: {
type: OmnichannelSourceType.APP;
id: string;
alias?: string;
sidebarIcon?: string;
defaultIcon?: string;
};
}
export type IVoipRoomClosingInfo = Pick<IOmnichannelGenericRoom, 'closer' | 'closedBy' | 'closedAt' | 'tags'> &
Pick<IVoipRoom, 'callDuration' | 'callTotalHoldTime'> & {
serviceTimeDuration?: number;
};
export type IOmnichannelRoomClosingInfo = Pick<IOmnichannelGenericRoom, 'closer' | 'closedBy' | 'closedAt' | 'tags'> & {
serviceTimeDuration?: number;
chatDuration: number;
};
export const isOmnichannelRoom = (room: Pick<IRoom, 't'>): room is IOmnichannelRoom & IRoom => room.t === 'l';
export const isVoipRoom = (room: IRoom): room is IVoipRoom & IRoom => room.t === 'v';
export const isOmnichannelRoomFromAppSource = (room: IRoom): room is IOmnichannelRoomFromAppSource => {
if (!isOmnichannelRoom(room)) {
return false;
}
return room.source?.type === OmnichannelSourceType.APP;
};
export type RoomAdminFieldsType =
| '_id'
| 'prid'
| 'fname'
| 'name'
| 't'
| 'cl'
| 'u'
| 'usernames'
| 'usersCount'
| 'muted'
| 'unmuted'
| 'ro'
| 'default'
| 'favorite'
| 'featured'
| 'reactWhenReadOnly'
| 'topic'
| 'msgs'
| 'archived'
| 'teamId'
| 'teamMain'
| 'announcement'
| 'description'
| 'broadcast'
| 'uids'
| 'avatarETag';
export interface IRoomWithRetentionPolicy extends IRoom {
retention: {
enabled?: boolean;
maxAge: number;
filesOnly: boolean;
excludePinned: boolean;
ignoreThreads: boolean;
overrideGlobal?: boolean;
};
}