@botonic/core 0.25.0-alpha.0 → 0.25.0-alpha.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/lib/cjs/core-bot.js +76 -99
- package/lib/cjs/core-bot.js.map +1 -1
- package/lib/cjs/data-provider/dynamodb-data-provider.js +69 -52
- package/lib/cjs/data-provider/dynamodb-data-provider.js.map +1 -1
- package/lib/cjs/data-provider/dynamodb-utils.js +2 -15
- package/lib/cjs/data-provider/dynamodb-utils.js.map +1 -1
- package/lib/cjs/data-provider/local-data-provider.js +7 -8
- package/lib/cjs/data-provider/local-data-provider.js.map +1 -1
- package/lib/cjs/debug/inspector.js +0 -3
- package/lib/cjs/debug/inspector.js.map +1 -1
- package/lib/cjs/handoff.js +124 -120
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/hubtype-service.js +37 -47
- package/lib/cjs/hubtype-service.js.map +1 -1
- package/lib/cjs/output-parser/botonic-output-parser.js +7 -8
- package/lib/cjs/output-parser/botonic-output-parser.js.map +1 -1
- package/lib/cjs/output-parser/parsers.js +17 -60
- package/lib/cjs/output-parser/parsers.js.map +1 -1
- package/lib/cjs/plugins.js +23 -20
- package/lib/cjs/plugins.js.map +1 -1
- package/lib/cjs/routing/router-utils.js +15 -13
- package/lib/cjs/routing/router-utils.js.map +1 -1
- package/lib/cjs/routing/router.js +16 -22
- package/lib/cjs/routing/router.js.map +1 -1
- package/lib/cjs/utils.js +3 -2
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/core-bot.js +75 -72
- package/lib/esm/core-bot.js.map +1 -1
- package/lib/esm/data-provider/dynamodb-data-provider.js +69 -44
- package/lib/esm/data-provider/dynamodb-data-provider.js.map +1 -1
- package/lib/esm/handoff.js +125 -108
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/hubtype-service.js +34 -25
- package/lib/esm/hubtype-service.js.map +1 -1
- package/lib/esm/plugins.js +23 -20
- package/lib/esm/plugins.js.map +1 -1
- package/lib/esm/routing/router-utils.js +14 -11
- package/lib/esm/routing/router-utils.js.map +1 -1
- package/package.json +3 -2
package/lib/esm/core-bot.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { ulid } from 'ulid';
|
|
2
3
|
import { Inspector } from './debug';
|
|
3
4
|
import { getString } from './i18n';
|
|
@@ -37,85 +38,87 @@ export class CoreBot {
|
|
|
37
38
|
setLocale(locale, session) {
|
|
38
39
|
session.__locale = locale;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
session.__locale
|
|
44
|
-
|
|
41
|
+
input({ input, session, lastRoutePath, dataProvider, }) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
session = session || {};
|
|
44
|
+
if (!session.__locale)
|
|
45
|
+
session.__locale = 'en';
|
|
46
|
+
if (input.type === INPUT.CHAT_EVENT) {
|
|
47
|
+
return {
|
|
48
|
+
input,
|
|
49
|
+
session,
|
|
50
|
+
lastRoutePath,
|
|
51
|
+
dataProvider,
|
|
52
|
+
response: [],
|
|
53
|
+
messageEvents: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
57
|
+
const userId = session.user.id;
|
|
58
|
+
if (dataProvider) {
|
|
59
|
+
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const userEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, parsedUserEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.USER, ack: MessageEventAck.RECEIVED }));
|
|
62
|
+
}
|
|
63
|
+
if (this.plugins) {
|
|
64
|
+
yield runPlugins(this.plugins, 'pre', input, session, lastRoutePath, undefined, undefined, dataProvider);
|
|
65
|
+
}
|
|
66
|
+
if (this.routes instanceof Function) {
|
|
67
|
+
this.router = new Router([
|
|
68
|
+
...(yield getComputedRoutes(this.routes, {
|
|
69
|
+
input,
|
|
70
|
+
session,
|
|
71
|
+
lastRoutePath,
|
|
72
|
+
})),
|
|
73
|
+
...this.defaultRoutes,
|
|
74
|
+
], this.inspector.routeInspector);
|
|
75
|
+
}
|
|
76
|
+
const output = this.router.processInput(input, session, lastRoutePath);
|
|
77
|
+
const request = {
|
|
78
|
+
getString: stringId => this.getString(stringId, session),
|
|
79
|
+
setLocale: locale => this.setLocale(locale, session),
|
|
80
|
+
session: session || {},
|
|
81
|
+
params: output.params || {},
|
|
82
|
+
input: input,
|
|
83
|
+
plugins: this.plugins,
|
|
84
|
+
defaultTyping: this.defaultTyping,
|
|
85
|
+
defaultDelay: this.defaultDelay,
|
|
86
|
+
lastRoutePath,
|
|
87
|
+
dataProvider,
|
|
88
|
+
};
|
|
89
|
+
const response = yield this.renderer({
|
|
90
|
+
request,
|
|
91
|
+
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
92
|
+
});
|
|
93
|
+
let messageEvents = [];
|
|
94
|
+
try {
|
|
95
|
+
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
// Disabling Botonic 1.0 error log for LTS version:
|
|
99
|
+
// console.error(e)
|
|
100
|
+
}
|
|
101
|
+
lastRoutePath = output.lastRoutePath;
|
|
102
|
+
if (this.plugins) {
|
|
103
|
+
yield runPlugins(this.plugins, 'post', input, session, lastRoutePath, response, messageEvents, dataProvider);
|
|
104
|
+
}
|
|
105
|
+
if (dataProvider) {
|
|
106
|
+
// TODO: save bot responses to db and update user with new session and new params
|
|
107
|
+
for (const messageEvent of messageEvents) {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
const botEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, messageEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.BOT, ack: MessageEventAck.SENT }));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
session.is_first_interaction = false;
|
|
45
113
|
return {
|
|
46
114
|
input,
|
|
115
|
+
response,
|
|
116
|
+
messageEvents,
|
|
47
117
|
session,
|
|
48
118
|
lastRoutePath,
|
|
49
119
|
dataProvider,
|
|
50
|
-
response: [],
|
|
51
|
-
messageEvents: null,
|
|
52
120
|
};
|
|
53
|
-
}
|
|
54
|
-
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
55
|
-
const userId = session.user.id;
|
|
56
|
-
if (dataProvider) {
|
|
57
|
-
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
const userEvent = await dataProvider.saveEvent(Object.assign(Object.assign({}, parsedUserEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.USER, ack: MessageEventAck.RECEIVED }));
|
|
60
|
-
}
|
|
61
|
-
if (this.plugins) {
|
|
62
|
-
await runPlugins(this.plugins, 'pre', input, session, lastRoutePath, undefined, undefined, dataProvider);
|
|
63
|
-
}
|
|
64
|
-
if (this.routes instanceof Function) {
|
|
65
|
-
this.router = new Router([
|
|
66
|
-
...(await getComputedRoutes(this.routes, {
|
|
67
|
-
input,
|
|
68
|
-
session,
|
|
69
|
-
lastRoutePath,
|
|
70
|
-
})),
|
|
71
|
-
...this.defaultRoutes,
|
|
72
|
-
], this.inspector.routeInspector);
|
|
73
|
-
}
|
|
74
|
-
const output = this.router.processInput(input, session, lastRoutePath);
|
|
75
|
-
const request = {
|
|
76
|
-
getString: stringId => this.getString(stringId, session),
|
|
77
|
-
setLocale: locale => this.setLocale(locale, session),
|
|
78
|
-
session: session || {},
|
|
79
|
-
params: output.params || {},
|
|
80
|
-
input: input,
|
|
81
|
-
plugins: this.plugins,
|
|
82
|
-
defaultTyping: this.defaultTyping,
|
|
83
|
-
defaultDelay: this.defaultDelay,
|
|
84
|
-
lastRoutePath,
|
|
85
|
-
dataProvider,
|
|
86
|
-
};
|
|
87
|
-
const response = await this.renderer({
|
|
88
|
-
request,
|
|
89
|
-
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
90
121
|
});
|
|
91
|
-
let messageEvents = [];
|
|
92
|
-
try {
|
|
93
|
-
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
// Disabling Botonic 1.0 error log for LTS version:
|
|
97
|
-
// console.error(e)
|
|
98
|
-
}
|
|
99
|
-
lastRoutePath = output.lastRoutePath;
|
|
100
|
-
if (this.plugins) {
|
|
101
|
-
await runPlugins(this.plugins, 'post', input, session, lastRoutePath, response, messageEvents, dataProvider);
|
|
102
|
-
}
|
|
103
|
-
if (dataProvider) {
|
|
104
|
-
// TODO: save bot responses to db and update user with new session and new params
|
|
105
|
-
for (const messageEvent of messageEvents) {
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
const botEvent = await dataProvider.saveEvent(Object.assign(Object.assign({}, messageEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.BOT, ack: MessageEventAck.SENT }));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
session.is_first_interaction = false;
|
|
111
|
-
return {
|
|
112
|
-
input,
|
|
113
|
-
response,
|
|
114
|
-
messageEvents,
|
|
115
|
-
session,
|
|
116
|
-
lastRoutePath,
|
|
117
|
-
dataProvider,
|
|
118
|
-
};
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
//# sourceMappingURL=core-bot.js.map
|
package/lib/esm/core-bot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AA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,iCACxC,YAAY,KACf,MAAM,EACN,OAAO,EAAE,IAAI,EAAE,EACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACnC,IAAI,EAAE,gBAAgB,CAAC,GAAG,EAC1B,GAAG,EAAE,eAAe,CAAC,IAAI,IACzB,CAAA;iBACH;aACF;YAED,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAA;YACpC,OAAO;gBACL,KAAK;gBACL,QAAQ;gBACR,aAAa;gBACb,OAAO;gBACP,aAAa;gBACb,YAAY;aACb,CAAA;QACH,CAAC;KAAA;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { EventTypes } from '../models';
|
|
2
3
|
import { getConnectionEventEntity, getMessageEventEntities, getUserEntity, getUserEventsTable, GLOBAL_SECONDARY_INDEX_NAME, SORT_KEY_NAME, USER_PREFIX, } from './dynamodb-utils';
|
|
3
4
|
export class DynamoDBDataProvider {
|
|
@@ -15,63 +16,87 @@ export class DynamoDBDataProvider {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
// @ts-ignore
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
getUsers(limit = 10, offset = 0) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
// TODO: finish to implement with offset
|
|
22
|
+
const result = yield this.userEventsTable.scan({
|
|
23
|
+
filters: { attr: SORT_KEY_NAME, beginsWith: USER_PREFIX },
|
|
24
|
+
limit,
|
|
25
|
+
});
|
|
26
|
+
return result.Items;
|
|
23
27
|
});
|
|
24
|
-
return result.Items;
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
getUser(id) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const userById = {
|
|
32
|
+
id: id,
|
|
33
|
+
SK: id,
|
|
34
|
+
};
|
|
35
|
+
const result = yield this.userEntity.get(userById);
|
|
36
|
+
if (Object.keys(result).length === 0)
|
|
37
|
+
return undefined;
|
|
38
|
+
return result.Item;
|
|
39
|
+
});
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
getUserByWebsocketId(websocketId) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const result = yield this.userEventsTable.query(websocketId, {
|
|
44
|
+
index: GLOBAL_SECONDARY_INDEX_NAME,
|
|
45
|
+
});
|
|
46
|
+
if (result.Count === 0)
|
|
47
|
+
return undefined;
|
|
48
|
+
return result.Items[0];
|
|
39
49
|
});
|
|
40
|
-
if (result.Count === 0)
|
|
41
|
-
return undefined;
|
|
42
|
-
return result.Items[0];
|
|
43
50
|
}
|
|
44
51
|
// @ts-ignore
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
52
|
+
getUserByField(field, value) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
54
|
+
} //TODO: Implement
|
|
55
|
+
saveUser(user) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const putUser = Object.assign(Object.assign({}, user), { id: user.id, userId: user.id });
|
|
58
|
+
yield this.userEntity.put(putUser);
|
|
59
|
+
return user;
|
|
60
|
+
});
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
updateUser(user) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const updateUser = Object.assign(Object.assign({}, user), { id: user.id, userId: user.id });
|
|
65
|
+
const res = yield this.userEntity.update(updateUser);
|
|
66
|
+
return user;
|
|
67
|
+
});
|
|
55
68
|
}
|
|
56
69
|
// @ts-ignore
|
|
57
|
-
|
|
70
|
+
deleteUser(id) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
72
|
+
} // TODO: Implement
|
|
58
73
|
// @ts-ignore
|
|
59
|
-
|
|
74
|
+
getEvents(limit = 10, offset = 0) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
76
|
+
} // TODO: Implement
|
|
60
77
|
// @ts-ignore
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
getEvent(id) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
80
|
+
} // TODO: Implement
|
|
81
|
+
saveEvent(event) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (event.eventType === EventTypes.CONNECTION) {
|
|
84
|
+
yield this.connectionEventEntity.put(event);
|
|
85
|
+
}
|
|
86
|
+
if (event.eventType === EventTypes.MESSAGE) {
|
|
87
|
+
yield this.messageEventEntities[event.type].put(event);
|
|
88
|
+
}
|
|
89
|
+
// TODO: Implementation of other event types
|
|
90
|
+
return event;
|
|
91
|
+
});
|
|
71
92
|
}
|
|
72
93
|
// @ts-ignore
|
|
73
|
-
|
|
94
|
+
updateEvent(event) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
96
|
+
} // TODO: Implement
|
|
74
97
|
// @ts-ignore
|
|
75
|
-
|
|
98
|
+
deleteEvent(id) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
100
|
+
} // TODO: Implement
|
|
76
101
|
}
|
|
77
102
|
//# sourceMappingURL=dynamodb-data-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamodb-data-provider.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-data-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,UAAU,EAAQ,MAAM,WAAW,CAAA;AAC1D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,kBAAkB,EAClB,2BAA2B,EAC3B,aAAa,EACb,WAAW,GACZ,MAAM,kBAAkB,CAAA;AAGzB,MAAM,OAAO,oBAAoB;IAS/B,YAAY,GAAW;QACrB,IAAI;YACF,CAAC;YAAA,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC/D,IAAI,CAAC,eAAe,GAAG,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;YACtE,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;YACrD,IAAI,CAAC,qBAAqB,GAAG,wBAAwB,CACnD,IAAI,CAAC,eAAe,CACrB,CAAA;YACD,IAAI,CAAC,oBAAoB,GAAG,uBAAuB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;SAC1E;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;SACnB;IACH,CAAC;IAED,aAAa;
|
|
1
|
+
{"version":3,"file":"dynamodb-data-provider.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-data-provider.ts"],"names":[],"mappings":";AAEA,OAAO,EAAgB,UAAU,EAAQ,MAAM,WAAW,CAAA;AAC1D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,kBAAkB,EAClB,2BAA2B,EAC3B,aAAa,EACb,WAAW,GACZ,MAAM,kBAAkB,CAAA;AAGzB,MAAM,OAAO,oBAAoB;IAS/B,YAAY,GAAW;QACrB,IAAI;YACF,CAAC;YAAA,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,K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aAC5C;YACD,IAAI,KAAK,CAAC,SAAS,KAAK,UAAU,CAAC,OAAO,EAAE;gBAC1C,MAAM,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;aACvD;YACD,4CAA4C;YAC5C,OAAO,KAAK,CAAA;QACd,CAAC;KAAA;IAED,aAAa;IACP,WAAW,CAAC,KAAmB;8DAA0B,CAAC;KAAA,CAAC,kBAAkB;IAEnF,aAAa;IACP,WAAW,CAAC,EAAU;8DAAsC,CAAC;KAAA,CAAC,kBAAkB;CACvF"}
|
package/lib/esm/handoff.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import axios from 'axios';
|
|
2
3
|
import { PATH_PAYLOAD_IDENTIFIER } from './constants';
|
|
3
4
|
const HUBTYPE_API_URL = 'https://api.hubtype.com';
|
|
@@ -6,21 +7,23 @@ function contextDefaults(context) {
|
|
|
6
7
|
timeoutMs: context.timeoutMs || 10000,
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
export function getOpenQueues(session, context = {}) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
//be aware of https://github.com/axios/axios/issues/1543
|
|
13
|
+
const baseUrl = session._hubtype_api || HUBTYPE_API_URL;
|
|
14
|
+
const endpointUrl = `${baseUrl}/v1/queues/get_open_queues/`;
|
|
15
|
+
context = contextDefaults(context);
|
|
16
|
+
const resp = yield axios({
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${session._access_token}`,
|
|
19
|
+
},
|
|
20
|
+
method: 'post',
|
|
21
|
+
url: endpointUrl,
|
|
22
|
+
data: { bot_id: session.bot.id },
|
|
23
|
+
timeout: context.timeoutMs,
|
|
24
|
+
});
|
|
25
|
+
return resp.data;
|
|
22
26
|
});
|
|
23
|
-
return resp.data;
|
|
24
27
|
}
|
|
25
28
|
export class HandOffBuilder {
|
|
26
29
|
constructor(session) {
|
|
@@ -74,116 +77,130 @@ export class HandOffBuilder {
|
|
|
74
77
|
this._extraData = extraData;
|
|
75
78
|
return this;
|
|
76
79
|
}
|
|
77
|
-
|
|
78
|
-
return
|
|
80
|
+
handOff() {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
return _humanHandOff(this._session, this._queue, this._onFinish, this._email, this._agentId, this._forceAssignIfNotAvailable, this._autoAssignOnWaiting, this._caseInfo, this._note, this._autoIdleMessage, this._shadowing, this._extraData);
|
|
83
|
+
});
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
/**
|
|
82
87
|
* @deprecated use {@link HandOffBuilder} class instead
|
|
83
88
|
*/
|
|
84
|
-
export
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (onFinish) {
|
|
90
|
-
if (onFinish.path) {
|
|
91
|
-
builder.withOnFinishPath(onFinish.path);
|
|
92
|
-
}
|
|
93
|
-
else if (onFinish.payload) {
|
|
94
|
-
builder.withOnFinishPayload(onFinish.payload);
|
|
89
|
+
export function humanHandOff(session, queueNameOrId = '', onFinish) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const builder = new HandOffBuilder(session);
|
|
92
|
+
if (queueNameOrId) {
|
|
93
|
+
builder.withQueue(queueNameOrId);
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
if (onFinish) {
|
|
96
|
+
if (onFinish.path) {
|
|
97
|
+
builder.withOnFinishPath(onFinish.path);
|
|
98
|
+
}
|
|
99
|
+
else if (onFinish.payload) {
|
|
100
|
+
builder.withOnFinishPayload(onFinish.payload);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new Error('onFinish requires payload or path field');
|
|
104
|
+
}
|
|
98
105
|
}
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
return builder.handOff();
|
|
107
|
+
});
|
|
101
108
|
}
|
|
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
|
-
|
|
109
|
+
function _humanHandOff(session, queueNameOrId = '', onFinish, agentEmail = '', agentId = '', forceAssignIfNotAvailable = true, autoAssignOnWaiting = false, caseInfo = '', note = '', autoIdleMessage = '', shadowing = false, extraData = undefined) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const params = {};
|
|
112
|
+
params.force_assign_if_not_available = forceAssignIfNotAvailable;
|
|
113
|
+
if (queueNameOrId) {
|
|
114
|
+
params.queue = queueNameOrId;
|
|
115
|
+
}
|
|
116
|
+
if (agentEmail) {
|
|
117
|
+
params.agent_email = agentEmail;
|
|
118
|
+
}
|
|
119
|
+
if (agentId) {
|
|
120
|
+
params.agent_id = agentId;
|
|
121
|
+
}
|
|
122
|
+
if (autoAssignOnWaiting) {
|
|
123
|
+
params.auto_assign_on_waiting = autoAssignOnWaiting;
|
|
124
|
+
}
|
|
125
|
+
if (caseInfo) {
|
|
126
|
+
params.case_info = caseInfo;
|
|
127
|
+
}
|
|
128
|
+
if (note) {
|
|
129
|
+
params.note = note;
|
|
130
|
+
}
|
|
131
|
+
if (autoIdleMessage) {
|
|
132
|
+
params.auto_idle_message = autoIdleMessage;
|
|
133
|
+
}
|
|
134
|
+
if (shadowing) {
|
|
135
|
+
params.shadowing = shadowing;
|
|
136
|
+
}
|
|
137
|
+
if (onFinish) {
|
|
138
|
+
params.on_finish = onFinish;
|
|
139
|
+
}
|
|
140
|
+
if (extraData) {
|
|
141
|
+
params.case_extra_data = extraData;
|
|
142
|
+
}
|
|
143
|
+
session._botonic_action = `create_case:${JSON.stringify(params)}`;
|
|
144
|
+
});
|
|
136
145
|
}
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
export function storeCaseRating(session, rating, context = {}) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const baseUrl = session._hubtype_api || HUBTYPE_API_URL;
|
|
149
|
+
const chatId = session.user.id;
|
|
150
|
+
context = contextDefaults(context);
|
|
151
|
+
const resp = yield axios({
|
|
152
|
+
headers: {
|
|
153
|
+
Authorization: `Bearer ${session._access_token}`,
|
|
154
|
+
},
|
|
155
|
+
method: 'post',
|
|
156
|
+
url: `${baseUrl}/v1/chats/${chatId}/store_case_rating/`,
|
|
157
|
+
data: { chat_id: chatId, rating },
|
|
158
|
+
timeout: context.timeoutMs,
|
|
159
|
+
});
|
|
160
|
+
return resp.data;
|
|
149
161
|
});
|
|
150
|
-
return resp.data;
|
|
151
162
|
}
|
|
152
|
-
export
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
export function getAvailableAgentsByQueue(session, queueId) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const baseUrl = session._hubtype_api || HUBTYPE_API_URL;
|
|
166
|
+
const resp = yield axios({
|
|
167
|
+
headers: {
|
|
168
|
+
Authorization: `Bearer ${session._access_token}`,
|
|
169
|
+
},
|
|
170
|
+
method: 'post',
|
|
171
|
+
url: `${baseUrl}/v1/queues/${queueId}/get_available_agents/`,
|
|
172
|
+
});
|
|
173
|
+
return resp.data;
|
|
160
174
|
});
|
|
161
|
-
return resp.data;
|
|
162
175
|
}
|
|
163
|
-
export
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
176
|
+
export function getAvailableAgents(session) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const baseUrl = session._hubtype_api || HUBTYPE_API_URL;
|
|
179
|
+
const botId = session.bot.id;
|
|
180
|
+
const resp = yield axios({
|
|
181
|
+
headers: {
|
|
182
|
+
Authorization: `Bearer ${session._access_token}`,
|
|
183
|
+
},
|
|
184
|
+
method: 'post',
|
|
185
|
+
url: `${baseUrl}/v1/bots/${botId}/get_agents/`,
|
|
186
|
+
});
|
|
187
|
+
return resp.data;
|
|
172
188
|
});
|
|
173
|
-
return resp.data;
|
|
174
189
|
}
|
|
175
|
-
export
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
190
|
+
export function getAgentVacationRanges(session, { agentId, agentEmail }) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const baseUrl = session._hubtype_api || HUBTYPE_API_URL;
|
|
193
|
+
const botId = session.bot.id;
|
|
194
|
+
const resp = yield axios({
|
|
195
|
+
headers: {
|
|
196
|
+
Authorization: `Bearer ${session._access_token}`,
|
|
197
|
+
},
|
|
198
|
+
method: 'get',
|
|
199
|
+
url: `${baseUrl}/v1/bots/${botId}/get_agent_vacation_ranges/`,
|
|
200
|
+
params: { agent_id: agentId, agent_email: agentEmail },
|
|
201
|
+
});
|
|
202
|
+
return resp.data;
|
|
185
203
|
});
|
|
186
|
-
return resp.data;
|
|
187
204
|
}
|
|
188
205
|
export function cancelHandoff(session, typification = null) {
|
|
189
206
|
let action = 'discard_case';
|