@zohoim/client-sdk 1.0.0-poc91 → 1.0.0-poc92

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.
@@ -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";
@@ -0,0 +1,9 @@
1
+ import RequestBuilder from "../RequestBuilder";
2
+
3
+ function pickupSessionRequest() {
4
+ return new RequestBuilder().withParams({
5
+ sessionId: null
6
+ }).build();
7
+ }
8
+
9
+ export default pickupSessionRequest;
@@ -10,6 +10,7 @@ function updateSessionStatusRequest() {
10
10
  ...params
11
11
  }).withBody({
12
12
  status: null,
13
+ agentId: null,
13
14
  ...body
14
15
  }).build();
15
16
  }
@@ -21,14 +21,14 @@ export default class Actor {
21
21
  return type === ActorType.BOT;
22
22
  }
23
23
 
24
- static isEnduser(type) {
25
- return type === ActorType.ENDUSER;
26
- }
27
-
28
24
  static isSystemMessage(type) {
29
25
  return type === ActorType.SYSTEM;
30
26
  }
31
27
 
28
+ static isEndUser(type) {
29
+ return type === ActorType.ENDUSER;
30
+ }
31
+
32
32
  toJSON() {
33
33
  return { ...this.data
34
34
  };
@@ -1,6 +1,6 @@
1
1
  import { validateSchema } from "../../../core/utils";
2
- import { ActionSchema } from "../../schema";
3
2
  import { ActionType } from "../../enum";
3
+ import { ActionSchema } from "../../schema";
4
4
  export default class Action {
5
5
  constructor() {
6
6
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -12,8 +12,9 @@ export default class Action {
12
12
  };
13
13
  }
14
14
 
15
- static isTransferAction(action) {
16
- return action === ActionType.TRANSFER;
15
+ static isTransferAction() {
16
+ let action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
+ return action && action.type === ActionType.TRANSFER;
17
18
  }
18
19
 
19
20
  toJSON() {
@@ -2,6 +2,13 @@ import { validateSchema } from "../../../core/utils";
2
2
  import { Actor } from "../Actor";
3
3
  import { InfoSchema } from "../../schema/message";
4
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
+
5
12
  export default class Info {
6
13
  constructor() {
7
14
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -10,20 +17,23 @@ export default class Info {
10
17
  actor: new Actor(validatedData.actor).toJSON(),
11
18
  action: validatedData.action,
12
19
  sessionStatus: validatedData.sessionStatus,
13
- targets: validatedData.targets
20
+ targets: adaptTargets(validatedData.targets)
14
21
  };
15
22
  }
16
23
 
17
- static isChatTransfer(action) {
18
- return action === InfoAction.CHAT_TRANSFER;
24
+ static isEndSessionMessage() {
25
+ let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26
+ return info && info.action === InfoAction.END_SESSION;
19
27
  }
20
28
 
21
- static isAutoAssign(action) {
22
- return action === InfoAction.CHAT_AUTO_ASSIGN;
29
+ static isAutoAssignMessage() {
30
+ let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
31
+ return info && info.action === InfoAction.CHAT_AUTO_ASSIGN;
23
32
  }
24
33
 
25
- static isEndSession(action) {
26
- return action === InfoAction.END_SESSION;
34
+ static isTransferMessage() {
35
+ let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
36
+ return info && info.action === InfoAction.CHAT_TRANSFER;
27
37
  }
28
38
 
29
39
  toJSON() {
@@ -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
+ }
@@ -99,6 +99,10 @@ export default class Message {
99
99
  return status === MessageStatus.FAILED;
100
100
  }
101
101
 
102
+ static isAutoSent(systemMsgType) {
103
+ return !!systemMsgType;
104
+ }
105
+
102
106
  static getMetaValue() {
103
107
  let meta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
104
108
  let key = arguments.length > 1 ? arguments[1] : undefined;
@@ -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";
@@ -64,6 +64,10 @@ export default class Session {
64
64
  return replyStatus === SessionReplyStatus.ENDUSER_OFFLINE;
65
65
  }
66
66
 
67
+ static isCreated(sessionStatus) {
68
+ return sessionStatus === SessionStatus.CREATED;
69
+ }
70
+
67
71
  static isAssignedToOtherService(replyStatus) {
68
72
  return replyStatus === SessionReplyStatus.ASSIGNED_TO_OTHER_SERVICE;
69
73
  }
@@ -1,5 +1,7 @@
1
1
  const AttachmentStatus = {
2
2
  VALID: 'VALID',
3
- INVALID: 'INVALID'
3
+ // NO I18N
4
+ INVALID: 'INVALID' // NO I18N
5
+
4
6
  };
5
7
  export default AttachmentStatus;
@@ -0,0 +1,11 @@
1
+ const InfoTargetType = {
2
+ AGENT: 'AGENT',
3
+ // NO I18N
4
+ BOT: 'BOT',
5
+ // NO I18N
6
+ END_USER: 'END_USER',
7
+ // NO I18N
8
+ SESSION: 'SESSION' // NO I18N
9
+
10
+ };
11
+ export default InfoTargetType;
@@ -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
- export { MessageTypes, MessageStatus, MessageDirection, MessageContentType, ActionType, ActionSubType, ExternalInfoAction, InfoSessionStatus, InfoAction };
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
- export { MessageSchema, ActionSchema, ExternalInfoSchema, InfoSchema, LocationSchema, MessageWithSessionSchema };
7
+ import InfoTargetSchema from "./InfoTargetSchema";
8
+ export { MessageSchema, ActionSchema, ExternalInfoSchema, InfoSchema, LocationSchema, MessageWithSessionSchema, InfoTargetSchema };
@@ -69,6 +69,10 @@ export default class BaseAPI {
69
69
  }
70
70
 
71
71
  isMethodOverridden(customAPI, methodName) {
72
+ if (!customAPI) {
73
+ return false;
74
+ }
75
+
72
76
  const customPrototype = Object.getPrototypeOf(customAPI);
73
77
  return typeof customAPI[methodName] === 'function' && // Method is defined directly on custom prototype
74
78
  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'), HTTP_METHODS.GET, getBotRequest());
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),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc91",
3
+ "version": "1.0.0-poc92",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",