@zohoim/client-sdk 0.0.2 → 0.0.4
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.
- package/es/application/services/sessions/SessionService.js +5 -0
- package/es/domain/dto/sessions/index.js +2 -1
- package/es/domain/dto/sessions/pickupSessionRequest.js +9 -0
- package/es/domain/dto/sessions/updateSessionStatusRequest.js +1 -0
- package/es/domain/entities/Actor/Actor.js +4 -0
- package/es/domain/entities/Message/Action.js +6 -0
- package/es/domain/entities/Message/Info.js +19 -1
- package/es/domain/entities/Message/InfoTarget.js +22 -0
- package/es/domain/entities/Message/Message.js +8 -0
- package/es/domain/entities/Message/index.js +2 -1
- package/es/domain/entities/Session/Session.js +8 -0
- package/es/domain/enum/attachment/AttachmentStatus.js +3 -1
- package/es/domain/enum/integrationServices/IntegrationServices.js +2 -1
- package/es/domain/enum/message/InfoTargetType.js +11 -0
- package/es/domain/enum/message/index.js +2 -1
- package/es/domain/interfaces/repositories/sessions/ISessionRepository.js +6 -1
- package/es/domain/schema/message/InfoTargetSchema.js +35 -0
- package/es/domain/schema/message/index.js +2 -1
- package/es/infrastructure/api/BaseAPI.js +4 -0
- package/es/infrastructure/api/registry/bots/botAPIRegistry.js +2 -1
- package/es/infrastructure/api/registry/sessions/sessionAPIRegistry.js +8 -2
- package/es/infrastructure/api/sessions/SessionAPI.js +11 -1
- package/es/infrastructure/repositories/sessions/SessionRepository.js +8 -0
- package/package.json +1 -1
|
@@ -8,6 +8,10 @@ export default class SessionService extends ISessionRepository {
|
|
|
8
8
|
this.sessionRepository = sessionRepository;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
async pickupSession(request) {
|
|
12
|
+
return this.sessionRepository.pickupSession(request);
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
async updateAssignee(request) {
|
|
12
16
|
return this.sessionRepository.updateAssignee(request);
|
|
13
17
|
}
|
|
@@ -38,6 +42,7 @@ export default class SessionService extends ISessionRepository {
|
|
|
38
42
|
|
|
39
43
|
toJSON() {
|
|
40
44
|
return {
|
|
45
|
+
pickupSession: this.pickupSession.bind(this),
|
|
41
46
|
updateAssignee: this.updateAssignee.bind(this),
|
|
42
47
|
getSessions: this.getSessions.bind(this),
|
|
43
48
|
getSession: this.getSession.bind(this),
|
|
@@ -4,4 +4,5 @@ export { default as getSessionRequest } from "./getSessionRequest";
|
|
|
4
4
|
export { default as getSessionAttachmentsRequest } from "./getSessionAttachmentsRequest";
|
|
5
5
|
export { default as getSessionLastMessagesRequest } from "./getSessionLastMessagesRequest";
|
|
6
6
|
export { default as markSessionAsReadRequest } from "./markSessionAsReadRequest";
|
|
7
|
-
export { default as updateSessionStatusRequest } from "./updateSessionStatusRequest";
|
|
7
|
+
export { default as updateSessionStatusRequest } from "./updateSessionStatusRequest";
|
|
8
|
+
export { default as pickupSessionRequest } from "./pickupSessionRequest";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validateSchema } from "../../../core/utils";
|
|
2
|
+
import { ActionType } from "../../enum";
|
|
2
3
|
import { ActionSchema } from "../../schema";
|
|
3
4
|
export default class Action {
|
|
4
5
|
constructor() {
|
|
@@ -11,6 +12,11 @@ export default class Action {
|
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
static isTransferAction() {
|
|
16
|
+
let action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
17
|
+
return action && action.type === ActionType.TRANSFER;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
toJSON() {
|
|
15
21
|
return { ...this.data
|
|
16
22
|
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { validateSchema } from "../../../core/utils";
|
|
2
2
|
import { Actor } from "../Actor";
|
|
3
3
|
import { InfoSchema } from "../../schema/message";
|
|
4
|
+
import { InfoAction } from "../../enum";
|
|
5
|
+
import InfoTarget from "./InfoTarget";
|
|
6
|
+
|
|
7
|
+
function adaptTargets() {
|
|
8
|
+
let targets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
9
|
+
return targets.map(target => new InfoTarget(target).toJSON());
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
export default class Info {
|
|
5
13
|
constructor() {
|
|
6
14
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -9,10 +17,20 @@ export default class Info {
|
|
|
9
17
|
actor: new Actor(validatedData.actor).toJSON(),
|
|
10
18
|
action: validatedData.action,
|
|
11
19
|
sessionStatus: validatedData.sessionStatus,
|
|
12
|
-
targets: validatedData.targets
|
|
20
|
+
targets: adaptTargets(validatedData.targets)
|
|
13
21
|
};
|
|
14
22
|
}
|
|
15
23
|
|
|
24
|
+
static isAutoAssignMessage() {
|
|
25
|
+
let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
|
+
return info && info.action === InfoAction.CHAT_AUTO_ASSIGN;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static isTransferMessage() {
|
|
30
|
+
let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
+
return info && info.action === InfoAction.CHAT_TRANSFER;
|
|
32
|
+
}
|
|
33
|
+
|
|
16
34
|
toJSON() {
|
|
17
35
|
return { ...this.data
|
|
18
36
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { validateSchema } from "../../../core/utils";
|
|
2
|
+
import { InfoTargetSchema } from "../../schema/message";
|
|
3
|
+
export default class InfoTarget {
|
|
4
|
+
constructor() {
|
|
5
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
+
const validatedData = validateSchema(InfoTargetSchema, data);
|
|
7
|
+
this.data = {
|
|
8
|
+
id: validatedData.id,
|
|
9
|
+
name: validatedData.name || null,
|
|
10
|
+
photoURL: validatedData.photoURL || null,
|
|
11
|
+
email: validatedData.email || null,
|
|
12
|
+
isReplyAllowed: validatedData.isReplyAllowed,
|
|
13
|
+
type: validatedData.type
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toJSON() {
|
|
18
|
+
return { ...this.data
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -50,6 +50,10 @@ export default class Message {
|
|
|
50
50
|
return direction === MessageDirection.OUT;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
static isIncoming(direction) {
|
|
54
|
+
return direction === MessageDirection.IN;
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
static isInfo(type) {
|
|
54
58
|
return type === MessageTypes.INFO;
|
|
55
59
|
}
|
|
@@ -58,6 +62,10 @@ export default class Message {
|
|
|
58
62
|
return type === MessageTypes.ATTACHMENT;
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
static isActionMessage(type) {
|
|
66
|
+
return type === MessageTypes.ACTION;
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
static isAutoSent(systemMsgType) {
|
|
62
70
|
return !!systemMsgType;
|
|
63
71
|
}
|
|
@@ -3,4 +3,5 @@ export { default as Info } from "./Info";
|
|
|
3
3
|
export { default as Action } from "./Action";
|
|
4
4
|
export { default as ExternalInfo } from "./ExternalInfo";
|
|
5
5
|
export { default as Location } from "./Location";
|
|
6
|
-
export { default as MessageWithSession } from "./MessageWithSession";
|
|
6
|
+
export { default as MessageWithSession } from "./MessageWithSession";
|
|
7
|
+
export { default as InfoTarget } from "./InfoTarget";
|
|
@@ -40,6 +40,14 @@ export default class Session {
|
|
|
40
40
|
return replyStatus === SessionReplyStatus.CHANNEL_INACTIVE;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
static isOpen(sessionStatus) {
|
|
44
|
+
return sessionStatus === SessionStatus.OPEN;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static isCreated(sessionStatus) {
|
|
48
|
+
return sessionStatus === SessionStatus.CREATED;
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
static isAssignedToOtherService(replyStatus) {
|
|
44
52
|
return replyStatus === SessionReplyStatus.ASSIGNED_TO_OTHER_SERVICE;
|
|
45
53
|
}
|
|
@@ -7,4 +7,5 @@ import ExternalInfoAction from "./ExternalInfoAction";
|
|
|
7
7
|
import InfoSessionStatus from "./InfoSessionStatus";
|
|
8
8
|
import InfoAction from "./InfoAction";
|
|
9
9
|
import ActionSubType from "./ActionSubType";
|
|
10
|
-
|
|
10
|
+
import InfoTargetType from "./InfoTargetType";
|
|
11
|
+
export { MessageTypes, MessageStatus, MessageDirection, MessageContentType, ActionType, ActionSubType, ExternalInfoAction, InfoSessionStatus, InfoAction, InfoTargetType };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
2
|
import { ModuleNames } from "../../../../core/constants";
|
|
3
3
|
import BaseAPI from "../../../../infrastructure/api/BaseAPI";
|
|
4
|
-
import { updateSessionAssigneeRequest, getSessionsRequest, getSessionRequest, getSessionAttachmentsRequest, getSessionLastMessagesRequest, markSessionAsReadRequest, updateSessionStatusRequest } from "../../../dto";
|
|
4
|
+
import { updateSessionAssigneeRequest, getSessionsRequest, getSessionRequest, getSessionAttachmentsRequest, getSessionLastMessagesRequest, markSessionAsReadRequest, updateSessionStatusRequest, pickupSessionRequest } from "../../../dto";
|
|
5
5
|
export default class ISessionRepository extends BaseAPI {
|
|
6
6
|
constructor() {
|
|
7
7
|
super({
|
|
@@ -9,6 +9,11 @@ export default class ISessionRepository extends BaseAPI {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
pickupSession() {
|
|
13
|
+
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : pickupSessionRequest();
|
|
14
|
+
throw new Error('Method not implemented.');
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
updateAssignee() {
|
|
13
18
|
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : updateSessionAssigneeRequest();
|
|
14
19
|
throw new Error('Method not implemented.');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InfoTargetType } from "../../enum";
|
|
2
|
+
const InfoTargetSchema = {
|
|
3
|
+
id: {
|
|
4
|
+
type: 'string',
|
|
5
|
+
// NO I18N
|
|
6
|
+
required: true
|
|
7
|
+
},
|
|
8
|
+
email: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
// NO I18N
|
|
11
|
+
required: false
|
|
12
|
+
},
|
|
13
|
+
photoURL: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
// NO I18N
|
|
16
|
+
required: false
|
|
17
|
+
},
|
|
18
|
+
name: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
// NO I18N
|
|
21
|
+
required: false
|
|
22
|
+
},
|
|
23
|
+
isReplyAllowed: {
|
|
24
|
+
type: 'boolean',
|
|
25
|
+
// NO I18N
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
type: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
// NO I18N
|
|
31
|
+
required: true,
|
|
32
|
+
enum: Object.values(InfoTargetType)
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export default InfoTargetSchema;
|
|
@@ -4,4 +4,5 @@ import ExternalInfoSchema from "./ExternalInfoSchema";
|
|
|
4
4
|
import InfoSchema from "./InfoSchema";
|
|
5
5
|
import LocationSchema from "./LocationSchema";
|
|
6
6
|
import MessageWithSessionSchema from "./MessageWithSessionSchema";
|
|
7
|
-
|
|
7
|
+
import InfoTargetSchema from "./InfoTargetSchema";
|
|
8
|
+
export { MessageSchema, ActionSchema, ExternalInfoSchema, InfoSchema, LocationSchema, MessageWithSessionSchema, InfoTargetSchema };
|
|
@@ -116,6 +116,10 @@ export default class BaseAPI {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
isMethodOverridden(customAPI, methodName) {
|
|
119
|
+
if (!customAPI) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
119
123
|
const customPrototype = Object.getPrototypeOf(customAPI);
|
|
120
124
|
return typeof customAPI[methodName] === 'function' && // Method is defined directly on custom prototype
|
|
121
125
|
Object.prototype.hasOwnProperty.call(customPrototype, methodName);
|
|
@@ -8,7 +8,8 @@ function getBots() {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
function getBot() {
|
|
11
|
-
return createAPIRegistry(constructBotEndPoint('/:botId'),
|
|
11
|
+
return createAPIRegistry(constructBotEndPoint('/:botId'), // NO I18N
|
|
12
|
+
HTTP_METHODS.GET, getBotRequest());
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export default {
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { HTTP_METHODS } from "../../../../core/constants";
|
|
2
|
-
import { updateSessionAssigneeRequest, getSessionAttachmentsRequest, getSessionLastMessagesRequest, getSessionRequest, getSessionsRequest, markSessionAsReadRequest, updateSessionStatusRequest } from "../../../../domain/dto";
|
|
2
|
+
import { updateSessionAssigneeRequest, getSessionAttachmentsRequest, getSessionLastMessagesRequest, getSessionRequest, getSessionsRequest, markSessionAsReadRequest, updateSessionStatusRequest, pickupSessionRequest } from "../../../../domain/dto";
|
|
3
3
|
import createAPIRegistry from "../createAPIRegistry";
|
|
4
4
|
import constructSessionEndPoint from "./constructSessionEndPoint";
|
|
5
5
|
const SINGLE_SESSION_URL = '/:sessionId';
|
|
6
6
|
const SESSION_ATTACHMENTS_URL = `${SINGLE_SESSION_URL}/attachments`;
|
|
7
7
|
const SESSION_LAST_MESSAGE = '/lastMessages';
|
|
8
8
|
const MARK_AS_READ = `${SINGLE_SESSION_URL}/markAsRead`;
|
|
9
|
+
const PICKUP_SESSION = `${SINGLE_SESSION_URL}/pickup`;
|
|
10
|
+
|
|
11
|
+
function pickupSession() {
|
|
12
|
+
return createAPIRegistry(constructSessionEndPoint(PICKUP_SESSION), HTTP_METHODS.POST, pickupSessionRequest());
|
|
13
|
+
}
|
|
9
14
|
|
|
10
15
|
function updateAssignee() {
|
|
11
16
|
return createAPIRegistry(constructSessionEndPoint(SINGLE_SESSION_URL), HTTP_METHODS.PATCH, updateSessionAssigneeRequest());
|
|
@@ -42,5 +47,6 @@ export default {
|
|
|
42
47
|
getSessionAttachments,
|
|
43
48
|
getSessionLastMessages,
|
|
44
49
|
markSessionAsRead,
|
|
45
|
-
updateSessionStatus
|
|
50
|
+
updateSessionStatus,
|
|
51
|
+
pickupSession
|
|
46
52
|
};
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { updateSessionAssigneeRequest, getSessionsRequest, getSessionRequest, getSessionAttachmentsRequest, getSessionLastMessagesRequest, markSessionAsReadRequest, updateSessionStatusRequest } from "../../../domain/dto";
|
|
1
|
+
import { updateSessionAssigneeRequest, getSessionsRequest, getSessionRequest, getSessionAttachmentsRequest, getSessionLastMessagesRequest, markSessionAsReadRequest, updateSessionStatusRequest, pickupSessionRequest } from "../../../domain/dto";
|
|
2
2
|
import { ISessionRepository } from "../../../domain/interfaces/repositories";
|
|
3
3
|
export default class SessionAPI extends ISessionRepository {
|
|
4
|
+
async pickupSession() {
|
|
5
|
+
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : pickupSessionRequest();
|
|
6
|
+
const operation = 'pickupSession';
|
|
7
|
+
const httpRequest = await this.request({
|
|
8
|
+
request,
|
|
9
|
+
operation
|
|
10
|
+
});
|
|
11
|
+
return httpRequest;
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
async updateAssignee() {
|
|
5
15
|
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : updateSessionAssigneeRequest();
|
|
6
16
|
const operation = 'updateAssignee';
|
|
@@ -36,6 +36,13 @@ export default class SessionRepository extends ISessionRepository {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
async pickupSession(request) {
|
|
40
|
+
return this.invokeAPI({
|
|
41
|
+
operation: 'pickupSession',
|
|
42
|
+
request
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
async updateAssignee(request) {
|
|
40
47
|
return this.invokeAPI({
|
|
41
48
|
operation: 'updateAssignee',
|
|
@@ -92,6 +99,7 @@ export default class SessionRepository extends ISessionRepository {
|
|
|
92
99
|
|
|
93
100
|
toJSON() {
|
|
94
101
|
return {
|
|
102
|
+
pickupSession: this.pickupSession.bind(this),
|
|
95
103
|
updateAssignee: this.updateAssignee.bind(this),
|
|
96
104
|
getSessions: this.getSessions.bind(this),
|
|
97
105
|
getSession: this.getSession.bind(this),
|