@zohoim/client-sdk 0.0.1 → 0.0.2
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/bots/BotService.js +6 -1
- package/es/core/utils/ResponseUtils.js +5 -5
- package/es/core/utils/validateSchema.js +9 -11
- package/es/domain/dto/bots/getBotRequest.js +9 -0
- package/es/domain/dto/bots/index.js +2 -1
- package/es/domain/entities/Actor/Actor.js +2 -1
- package/es/domain/entities/Attachment/Attachment.js +2 -1
- package/es/domain/entities/IntegrationService/IntegrationService.js +33 -0
- package/es/domain/entities/IntegrationService/index.js +2 -0
- package/es/domain/entities/Message/Message.js +25 -0
- package/es/domain/entities/Session/Session.js +17 -0
- package/es/domain/entities/index.js +2 -1
- package/es/domain/enum/attachment/AttachmentStatus.js +5 -0
- package/es/domain/enum/attachment/index.js +2 -0
- package/es/domain/enum/index.js +2 -1
- package/es/domain/enum/message/ExternalInfoAction.js +6 -6
- package/es/domain/enum/message/InfoAction.js +14 -14
- package/es/domain/enum/message/InfoSessionStatus.js +7 -7
- package/es/domain/enum/session/SessionReplyStatus.js +2 -1
- package/es/domain/enum/session/SessionStatus.js +2 -1
- package/es/domain/interfaces/repositories/bots/IBotRepository.js +7 -1
- package/es/domain/schema/actor/ActorSchema.js +4 -0
- package/es/domain/schema/attachment/AttachmentSchema.js +6 -0
- package/es/domain/schema/message/LocationSchema.js +2 -2
- package/es/infrastructure/adapters/attachments/AttachmentAdapter.js +2 -1
- package/es/infrastructure/api/bots/BotAPI.js +11 -1
- package/es/infrastructure/api/registry/bots/botAPIRegistry.js +7 -2
- package/es/infrastructure/repositories/bots/BotRepository.js +10 -1
- 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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
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];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default as getBotsRequest } from "./getBotsRequest";
|
|
1
|
+
export { default as getBotsRequest } from "./getBotsRequest";
|
|
2
|
+
export { default as getBotRequest } from "./getBotRequest";
|
|
@@ -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
|
+
}
|
|
@@ -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
|
};
|
package/es/domain/enum/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const ExternalInfoAction = {
|
|
2
|
-
UN_IDENTIFIED:
|
|
3
|
-
GC_CONVERSATION_ENDED:
|
|
4
|
-
ZIA_CONVERSATION_ENDED:
|
|
5
|
-
NEW_FOLLOWER:
|
|
6
|
-
CHAT_BLOCKED:
|
|
7
|
-
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:
|
|
3
|
-
END_SESSION:
|
|
4
|
-
BLOCK_SESSION:
|
|
5
|
-
UNBLOCK_SESSION:
|
|
6
|
-
CHAT_AUTO_ASSIGN:
|
|
7
|
-
CHAT_ACCEPT:
|
|
8
|
-
CHAT_REOPEN:
|
|
9
|
-
CHAT_TRANSFER:
|
|
10
|
-
ADD_PARTICIPANT:
|
|
11
|
-
REMOVE_PARTICIPANT:
|
|
12
|
-
CHAT_REOPENED_ON_TRANSFER:
|
|
13
|
-
CHAT_INITIATION:
|
|
14
|
-
USER_LEFT:
|
|
15
|
-
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:
|
|
3
|
-
OPEN:
|
|
4
|
-
ON_PROGRESS:
|
|
5
|
-
ON_HOLD:
|
|
6
|
-
ENDED:
|
|
7
|
-
BLOCKED:
|
|
8
|
-
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;
|
|
@@ -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
|
}
|
|
@@ -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;
|
|
@@ -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,11 @@ function getBots() {
|
|
|
7
7
|
return createAPIRegistry(constructBotEndPoint(), HTTP_METHODS.GET, getBotsRequest());
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
function getBot() {
|
|
11
|
+
return createAPIRegistry(constructBotEndPoint('/:botId'), HTTP_METHODS.GET, getBotRequest());
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
export default {
|
|
11
|
-
getBots
|
|
15
|
+
getBots,
|
|
16
|
+
getBot
|
|
12
17
|
};
|
|
@@ -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
|
|