@zohoim/client-sdk 0.0.1 → 0.0.2-wecomfix

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.
Files changed (30) hide show
  1. package/es/application/services/bots/BotService.js +6 -1
  2. package/es/core/utils/ResponseUtils.js +5 -5
  3. package/es/core/utils/validateSchema.js +9 -11
  4. package/es/domain/dto/bots/getBotRequest.js +9 -0
  5. package/es/domain/dto/bots/index.js +2 -1
  6. package/es/domain/entities/Actor/Actor.js +2 -1
  7. package/es/domain/entities/Attachment/Attachment.js +2 -1
  8. package/es/domain/entities/IntegrationService/IntegrationService.js +33 -0
  9. package/es/domain/entities/IntegrationService/index.js +2 -0
  10. package/es/domain/entities/Message/Message.js +25 -0
  11. package/es/domain/entities/Session/Session.js +17 -0
  12. package/es/domain/entities/index.js +2 -1
  13. package/es/domain/enum/attachment/AttachmentStatus.js +7 -0
  14. package/es/domain/enum/attachment/index.js +2 -0
  15. package/es/domain/enum/index.js +2 -1
  16. package/es/domain/enum/integrationServices/IntegrationServices.js +2 -1
  17. package/es/domain/enum/message/ExternalInfoAction.js +6 -6
  18. package/es/domain/enum/message/InfoAction.js +14 -14
  19. package/es/domain/enum/message/InfoSessionStatus.js +7 -7
  20. package/es/domain/enum/session/SessionReplyStatus.js +2 -1
  21. package/es/domain/enum/session/SessionStatus.js +2 -1
  22. package/es/domain/interfaces/repositories/bots/IBotRepository.js +7 -1
  23. package/es/domain/schema/actor/ActorSchema.js +4 -0
  24. package/es/domain/schema/attachment/AttachmentSchema.js +6 -0
  25. package/es/domain/schema/message/LocationSchema.js +2 -2
  26. package/es/infrastructure/adapters/attachments/AttachmentAdapter.js +2 -1
  27. package/es/infrastructure/api/bots/BotAPI.js +11 -1
  28. package/es/infrastructure/api/registry/bots/botAPIRegistry.js +8 -2
  29. package/es/infrastructure/repositories/bots/BotRepository.js +10 -1
  30. package/package.json +1 -1
@@ -12,9 +12,14 @@ export default class BotService extends IBotRepository {
12
12
  return this.botRepository.getBots(request);
13
13
  }
14
14
 
15
+ async getBot(request) {
16
+ return this.botRepository.getBot(request);
17
+ }
18
+
15
19
  toJSON() {
16
20
  return {
17
- getBots: this.getBots.bind(this)
21
+ getBots: this.getBots.bind(this),
22
+ getBot: this.getBot.bind(this)
18
23
  };
19
24
  }
20
25
 
@@ -1,20 +1,20 @@
1
1
  export default class ResponseUtils {
2
- static adaptListResponse(response, adapter) {
3
- if (!response) {
2
+ static async adaptListResponse(response, adapter) {
3
+ if (!response || !adapter) {
4
4
  return response;
5
5
  }
6
6
 
7
- if (!response.data) {
7
+ if (!response.data || !adapter) {
8
8
  return response;
9
9
  }
10
10
 
11
11
  return { ...response,
12
- data: response.data.map(item => adapter(item))
12
+ data: await Promise.all(response.data.map(item => adapter(item)))
13
13
  };
14
14
  }
15
15
 
16
16
  static adaptSingleResponse(response, adapter) {
17
- if (!response) {
17
+ if (!response || !adapter) {
18
18
  return response;
19
19
  }
20
20
 
@@ -1,12 +1,10 @@
1
- import { ValidationError } from "../errors";
2
-
3
- function validateSchemaKeys(schema, data) {
4
- Object.keys(schema).forEach(key => {
5
- if (!(key in data)) {
6
- throw new ValidationError(`Key '${key}' is missing in the data`);
7
- }
8
- });
9
- }
1
+ import { ValidationError } from "../errors"; // function validateSchemaKeys(schema, data) {
2
+ // Object.keys(schema).forEach((key) => {
3
+ // if (!(key in data)) {
4
+ // throw new ValidationError(`Key '${key}' is missing in the data`);
5
+ // }
6
+ // });
7
+ // }
10
8
 
11
9
  function isEmpty(value) {
12
10
  if (value === null || value === undefined || value === '') {
@@ -44,8 +42,8 @@ export const validateSchema = (schema, data) => {
44
42
  const validate = function (schemaObj, dataObj) {
45
43
  let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
46
44
  // Check if all schema keys exist in data
47
- validateSchemaKeys(schemaObj, dataObj); // Validate each field
48
-
45
+ // validateSchemaKeys(schemaObj, dataObj);
46
+ // Validate each field
49
47
  Object.entries(schemaObj).forEach(_ref3 => {
50
48
  let [field, rules] = _ref3;
51
49
  const value = dataObj[field];
@@ -0,0 +1,9 @@
1
+ import RequestBuilder from "../RequestBuilder";
2
+
3
+ function getBotRequest() {
4
+ return new RequestBuilder().withParams({
5
+ botId: null
6
+ }).build();
7
+ }
8
+
9
+ export default getBotRequest;
@@ -1 +1,2 @@
1
- export { default as getBotsRequest } from "./getBotsRequest";
1
+ export { default as getBotsRequest } from "./getBotsRequest";
2
+ export { default as getBotRequest } from "./getBotRequest";
@@ -12,7 +12,8 @@ export default class Actor {
12
12
  extId: validatedData.extId,
13
13
  id: validatedData.id,
14
14
  email: validatedData.email,
15
- botType: validatedData.botType
15
+ botType: validatedData.botType,
16
+ service: validatedData.service
16
17
  };
17
18
  }
18
19
 
@@ -10,7 +10,8 @@ export default class Attachment {
10
10
  type: validatedData.type,
11
11
  createdTime: validatedData.createdTime,
12
12
  size: validatedData.size,
13
- url: validatedData.url
13
+ url: validatedData.url,
14
+ status: validatedData.status
14
15
  };
15
16
  }
16
17
 
@@ -0,0 +1,33 @@
1
+ import { validateSchema } from "../../../core/utils";
2
+ import { IntegrationServices } from "../../enum";
3
+ import { IntegrationServiceSchema } from "../../schema";
4
+ export default class IntegrationService {
5
+ constructor() {
6
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ const validatedData = validateSchema(IntegrationServiceSchema, data);
8
+ this.data = {
9
+ label: validatedData.label || '',
10
+ id: validatedData.id || '',
11
+ provider: validatedData.provider || {},
12
+ logoURL: validatedData.logoURL || null
13
+ };
14
+ }
15
+
16
+ static isWhatsApp(integrationServiceId) {
17
+ return integrationServiceId === IntegrationServices.WHATSAPP;
18
+ }
19
+
20
+ static isTwilio(integrationServiceId) {
21
+ return integrationServiceId === IntegrationServices.TWILIO;
22
+ }
23
+
24
+ static isBusinessMessaging(integrationServiceId) {
25
+ return integrationServiceId === IntegrationServices.IM_TALK;
26
+ }
27
+
28
+ toJSON() {
29
+ return { ...this.data
30
+ };
31
+ }
32
+
33
+ }
@@ -0,0 +1,2 @@
1
+ import IntegrationService from "./IntegrationService";
2
+ export { IntegrationService };
@@ -1,4 +1,5 @@
1
1
  import { validateSchema } from "../../../core/utils";
2
+ import { MessageDirection, MessageStatus, MessageTypes } from "../../enum";
2
3
  import { MessageSchema } from "../../schema";
3
4
  import { Actor } from "../Actor";
4
5
  import { Attachment } from "../Attachment";
@@ -37,6 +38,30 @@ export default class Message {
37
38
  };
38
39
  }
39
40
 
41
+ static isLocation(type) {
42
+ return type === MessageTypes.LOCATION;
43
+ }
44
+
45
+ static isDeleted(status) {
46
+ return status === MessageStatus.DELETED;
47
+ }
48
+
49
+ static isOutgoing(direction) {
50
+ return direction === MessageDirection.OUT;
51
+ }
52
+
53
+ static isInfo(type) {
54
+ return type === MessageTypes.INFO;
55
+ }
56
+
57
+ static isAttachment(type) {
58
+ return type === MessageTypes.ATTACHMENT;
59
+ }
60
+
61
+ static isAutoSent(systemMsgType) {
62
+ return !!systemMsgType;
63
+ }
64
+
40
65
  toJSON() {
41
66
  return { ...this.data
42
67
  };
@@ -1,6 +1,7 @@
1
1
  import { validateSchema } from "../../../core/utils";
2
2
  import { SessionSchema } from "../../schema";
3
3
  import { Actor } from "../Actor";
4
+ import { SessionReplyStatus, SessionStatus } from "../../enum";
4
5
  export default class Session {
5
6
  constructor() {
6
7
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -27,6 +28,22 @@ export default class Session {
27
28
  };
28
29
  }
29
30
 
31
+ static isEnded(sessionStatus) {
32
+ return sessionStatus === SessionStatus.ENDED;
33
+ }
34
+
35
+ static isBlocked(sessionStatus) {
36
+ return sessionStatus === SessionStatus.BLOCKED;
37
+ }
38
+
39
+ static isInactiveChannel(replyStatus) {
40
+ return replyStatus === SessionReplyStatus.CHANNEL_INACTIVE;
41
+ }
42
+
43
+ static isAssignedToOtherService(replyStatus) {
44
+ return replyStatus === SessionReplyStatus.ASSIGNED_TO_OTHER_SERVICE;
45
+ }
46
+
30
47
  toJSON() {
31
48
  return { ...this.data
32
49
  };
@@ -5,4 +5,5 @@ export * from "./Bot";
5
5
  export * from "./Attachment";
6
6
  export * from "./Message";
7
7
  export * from "./Channel";
8
- export * from "./Contact";
8
+ export * from "./Contact";
9
+ export * from "./IntegrationService";
@@ -0,0 +1,7 @@
1
+ const AttachmentStatus = {
2
+ VALID: 'VALID',
3
+ // NO I18N
4
+ INVALID: 'INVALID' // NO I18N
5
+
6
+ };
7
+ export default AttachmentStatus;
@@ -0,0 +1,2 @@
1
+ import AttachmentStatus from "./AttachmentStatus";
2
+ export { AttachmentStatus };
@@ -2,4 +2,5 @@ export * from "./integrationServices";
2
2
  export * from "./session";
3
3
  export * from "./actor";
4
4
  export * from "./bot";
5
- export * from "./message";
5
+ export * from "./message";
6
+ export * from "./attachment";
@@ -6,6 +6,7 @@ const IntegrationServices = {
6
6
  LINE: 'LINE',
7
7
  IM_TALK: 'IM_TALK',
8
8
  FACEBOOKMESSENGER: 'FACEBOOKMESSENGER',
9
- INSTAGRAM: 'INSTAGRAM'
9
+ INSTAGRAM: 'INSTAGRAM',
10
+ WECOM: 'WECOM'
10
11
  };
11
12
  export default IntegrationServices;
@@ -1,9 +1,9 @@
1
1
  const ExternalInfoAction = {
2
- UN_IDENTIFIED: "UN_IDENTIFIED",
3
- GC_CONVERSATION_ENDED: "GC_CONVERSATION_ENDED",
4
- ZIA_CONVERSATION_ENDED: "ZIA_CONVERSATION_ENDED",
5
- NEW_FOLLOWER: "NEW_FOLLOWER",
6
- CHAT_BLOCKED: "CHAT_BLOCKED",
7
- CHAT_UNBLOCKED: "CHAT_UNBLOCKED"
2
+ UN_IDENTIFIED: 'UN_IDENTIFIED',
3
+ GC_CONVERSATION_ENDED: 'GC_CONVERSATION_ENDED',
4
+ ZIA_CONVERSATION_ENDED: 'ZIA_CONVERSATION_ENDED',
5
+ NEW_FOLLOWER: 'NEW_FOLLOWER',
6
+ CHAT_BLOCKED: 'CHAT_BLOCKED',
7
+ CHAT_UNBLOCKED: 'CHAT_UNBLOCKED'
8
8
  };
9
9
  export default ExternalInfoAction;
@@ -1,17 +1,17 @@
1
1
  const InfoAction = {
2
- UN_IDENTIFIED: "UN_IDENTIFIED",
3
- END_SESSION: "END_SESSION",
4
- BLOCK_SESSION: "BLOCK_SESSION",
5
- UNBLOCK_SESSION: "UNBLOCK_SESSION",
6
- CHAT_AUTO_ASSIGN: "CHAT_AUTO_ASSIGN",
7
- CHAT_ACCEPT: "CHAT_ACCEPT",
8
- CHAT_REOPEN: "CHAT_REOPEN",
9
- CHAT_TRANSFER: "CHAT_TRANSFER",
10
- ADD_PARTICIPANT: "ADD_PARTICIPANT",
11
- REMOVE_PARTICIPANT: "REMOVE_PARTICIPANT",
12
- CHAT_REOPENED_ON_TRANSFER: "CHAT_REOPENED_ON_TRANSFER",
13
- CHAT_INITIATION: "CHAT_INITIATION",
14
- USER_LEFT: "USER_LEFT",
15
- USER_JOINED: "USER_JOINED"
2
+ UN_IDENTIFIED: 'UN_IDENTIFIED',
3
+ END_SESSION: 'END_SESSION',
4
+ BLOCK_SESSION: 'BLOCK_SESSION',
5
+ UNBLOCK_SESSION: 'UNBLOCK_SESSION',
6
+ CHAT_AUTO_ASSIGN: 'CHAT_AUTO_ASSIGN',
7
+ CHAT_ACCEPT: 'CHAT_ACCEPT',
8
+ CHAT_REOPEN: 'CHAT_REOPEN',
9
+ CHAT_TRANSFER: 'CHAT_TRANSFER',
10
+ ADD_PARTICIPANT: 'ADD_PARTICIPANT',
11
+ REMOVE_PARTICIPANT: 'REMOVE_PARTICIPANT',
12
+ CHAT_REOPENED_ON_TRANSFER: 'CHAT_REOPENED_ON_TRANSFER',
13
+ CHAT_INITIATION: 'CHAT_INITIATION',
14
+ USER_LEFT: 'USER_LEFT',
15
+ USER_JOINED: 'USER_JOINED'
16
16
  };
17
17
  export default InfoAction;
@@ -1,10 +1,10 @@
1
1
  const InfoSessionStatus = {
2
- CREATED: "CREATED",
3
- OPEN: "OPEN",
4
- ON_PROGRESS: "ON_PROGRESS",
5
- ON_HOLD: "ON_HOLD",
6
- ENDED: "ENDED",
7
- BLOCKED: "BLOCKED",
8
- MISSED: "MISSED"
2
+ CREATED: 'CREATED',
3
+ OPEN: 'OPEN',
4
+ ON_PROGRESS: 'ON_PROGRESS',
5
+ ON_HOLD: 'ON_HOLD',
6
+ ENDED: 'ENDED',
7
+ BLOCKED: 'BLOCKED',
8
+ MISSED: 'MISSED'
9
9
  };
10
10
  export default InfoSessionStatus;
@@ -15,6 +15,7 @@ const SessionReplyStatus = {
15
15
  SANDBOX_LIMIT_REACHED: 'SANDBOX_LIMIT_REACHED',
16
16
  CHANNEL_DELETED: 'CHANNEL_DELETED',
17
17
  ENDUSER_OFFLINE: 'ENDUSER_OFFLINE',
18
- CONFIG_SKIPPED_CHANNEL: 'CONFIG_SKIPPED_CHANNEL'
18
+ CONFIG_SKIPPED_CHANNEL: 'CONFIG_SKIPPED_CHANNEL',
19
+ ASSIGNED_TO_OTHER_SERVICE: 'ASSIGNED_TO_OTHER_SERVICE'
19
20
  };
20
21
  export default SessionReplyStatus;
@@ -4,6 +4,7 @@ const SessionStatus = {
4
4
  ON_PROGRESS: 'ON_PROGRESS',
5
5
  ON_HOLD: 'ON_HOLD',
6
6
  ENDED: 'ENDED',
7
- BLOCKED: 'BLOCKED'
7
+ BLOCKED: 'BLOCKED',
8
+ UNASSIGNED: 'UNASSIGNED'
8
9
  };
9
10
  export default SessionStatus;
@@ -1,6 +1,6 @@
1
1
  import { ModuleNames } from "../../../../core/constants";
2
2
  import BaseAPI from "../../../../infrastructure/api/BaseAPI";
3
- import { getBotsRequest } from "../../../dto";
3
+ import { getBotsRequest, getBotRequest } from "../../../dto";
4
4
  export default class IBotRepository extends BaseAPI {
5
5
  constructor() {
6
6
  super({
@@ -12,6 +12,12 @@ export default class IBotRepository extends BaseAPI {
12
12
  async getBots() {
13
13
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getBotsRequest();
14
14
  throw new Error('Method not implemented');
15
+ } // eslint-disable-next-line no-unused-vars
16
+
17
+
18
+ async getBot() {
19
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getBotRequest();
20
+ throw new Error('Method not implemented');
15
21
  }
16
22
 
17
23
  }
@@ -28,6 +28,10 @@ const ActorSchema = {
28
28
  botType: {
29
29
  type: 'string',
30
30
  required: false
31
+ },
32
+ service: {
33
+ type: 'string',
34
+ required: false
31
35
  }
32
36
  };
33
37
  export default ActorSchema;
@@ -1,3 +1,4 @@
1
+ import { AttachmentStatus } from "../../enum";
1
2
  const AttachmentSchema = {
2
3
  id: {
3
4
  type: 'string',
@@ -22,6 +23,11 @@ const AttachmentSchema = {
22
23
  url: {
23
24
  type: 'string',
24
25
  required: false
26
+ },
27
+ status: {
28
+ type: 'string',
29
+ required: false,
30
+ enum: Object.values(AttachmentStatus)
25
31
  }
26
32
  };
27
33
  export default AttachmentSchema;
@@ -1,11 +1,11 @@
1
1
  const LocationSchema = {
2
2
  latitude: {
3
3
  type: 'string',
4
- required: true
4
+ required: false
5
5
  },
6
6
  longitude: {
7
7
  type: 'string',
8
- required: true
8
+ required: false
9
9
  }
10
10
  };
11
11
  export default LocationSchema;
@@ -14,7 +14,8 @@ export default class AttachmentAdapter extends IAdapter {
14
14
  type: attachmentData.type,
15
15
  createdTime: attachmentData.createdTime,
16
16
  size: attachmentData.size,
17
- url: attachmentData.url
17
+ url: attachmentData.url,
18
+ status: attachmentData.status
18
19
  }).toJSON();
19
20
  } catch (error) {
20
21
  throw new AdapterError(`Failed to adapt attachment: ${error.message}`);
@@ -1,4 +1,4 @@
1
- import { getBotsRequest } from "../../../domain/dto";
1
+ import { getBotsRequest, getBotRequest } from "../../../domain/dto";
2
2
  import { IBotRepository } from "../../../domain/interfaces/repositories";
3
3
  export default class BotAPI extends IBotRepository {
4
4
  async getBots() {
@@ -11,4 +11,14 @@ export default class BotAPI extends IBotRepository {
11
11
  return httpRequest;
12
12
  }
13
13
 
14
+ async getBot() {
15
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getBotRequest();
16
+ const operation = 'getBot';
17
+ const httpRequest = await this.request({
18
+ request,
19
+ operation
20
+ });
21
+ return httpRequest;
22
+ }
23
+
14
24
  }
@@ -1,5 +1,5 @@
1
1
  import { HTTP_METHODS } from "../../../../core/constants";
2
- import { getBotsRequest } from "../../../../domain/dto";
2
+ import { getBotsRequest, getBotRequest } from "../../../../domain/dto";
3
3
  import createAPIRegistry from "../createAPIRegistry";
4
4
  import constructBotEndPoint from "./constructBotEndPoint";
5
5
 
@@ -7,6 +7,12 @@ function getBots() {
7
7
  return createAPIRegistry(constructBotEndPoint(), HTTP_METHODS.GET, getBotsRequest());
8
8
  }
9
9
 
10
+ function getBot() {
11
+ return createAPIRegistry(constructBotEndPoint('/:botId'), // NO I18N
12
+ HTTP_METHODS.GET, getBotRequest());
13
+ }
14
+
10
15
  export default {
11
- getBots
16
+ getBots,
17
+ getBot
12
18
  };
@@ -40,9 +40,18 @@ export default class BotRepository extends IBotRepository {
40
40
  });
41
41
  }
42
42
 
43
+ async getBot(request) {
44
+ return this.invokeAPI({
45
+ operation: 'getBot',
46
+ request,
47
+ responseType: ResponseTypes.LIST
48
+ });
49
+ }
50
+
43
51
  toJSON() {
44
52
  return {
45
- getBots: this.getBots.bind(this)
53
+ getBots: this.getBots.bind(this),
54
+ getBot: this.getBot.bind(this)
46
55
  };
47
56
  }
48
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-wecomfix",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",