@botonic/plugin-flow-builder 0.22.0-alpha.0 → 0.22.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/action.d.ts +13 -2
- package/lib/cjs/action.js +13 -3
- package/lib/cjs/action.js.map +1 -1
- package/lib/cjs/flow-builder-models.d.ts +1 -0
- package/lib/cjs/functions/conditional-provider.d.ts +2 -2
- package/lib/cjs/functions/conditional-provider.js +2 -2
- package/lib/cjs/functions/conditional-provider.js.map +1 -1
- package/lib/cjs/functions/conditional-queue-status.d.ts +7 -2
- package/lib/cjs/functions/conditional-queue-status.js +13 -2
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/handoff.js +20 -4
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/index.d.ts +6 -2
- package/lib/cjs/index.js +29 -18
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -0
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/action.d.ts +13 -2
- package/lib/esm/action.js +12 -3
- package/lib/esm/action.js.map +1 -1
- package/lib/esm/flow-builder-models.d.ts +1 -0
- package/lib/esm/functions/conditional-provider.d.ts +2 -2
- package/lib/esm/functions/conditional-provider.js +2 -2
- package/lib/esm/functions/conditional-provider.js.map +1 -1
- package/lib/esm/functions/conditional-queue-status.d.ts +7 -2
- package/lib/esm/functions/conditional-queue-status.js +13 -2
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/handoff.js +20 -4
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/index.d.ts +6 -2
- package/lib/esm/index.js +29 -16
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +2 -0
- package/lib/esm/types.js.map +1 -1
- package/package.json +2 -2
- package/src/action.tsx +20 -5
- package/src/flow-builder-models.ts +1 -0
- package/src/functions/conditional-provider.ts +2 -2
- package/src/functions/conditional-queue-status.ts +24 -4
- package/src/handoff.ts +38 -6
- package/src/index.ts +37 -20
- package/src/types.ts +6 -0
package/lib/cjs/action.d.ts
CHANGED
|
@@ -2,12 +2,23 @@ import { ActionRequest } from '@botonic/react';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { FlowContent } from './content-fields';
|
|
4
4
|
type FlowBuilderActionProps = {
|
|
5
|
-
|
|
5
|
+
contents: FlowContent[];
|
|
6
6
|
isHandoff?: boolean;
|
|
7
7
|
};
|
|
8
8
|
export declare class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
9
|
-
static contextType: React.Context<
|
|
9
|
+
static contextType: React.Context<{
|
|
10
|
+
getString: () => "";
|
|
11
|
+
setLocale: () => "";
|
|
12
|
+
session: {};
|
|
13
|
+
params: {};
|
|
14
|
+
input: {};
|
|
15
|
+
defaultDelay: number;
|
|
16
|
+
defaultTyping: number;
|
|
17
|
+
}>;
|
|
10
18
|
static botonicInit(request: ActionRequest): Promise<any>;
|
|
11
19
|
render(): JSX.Element | JSX.Element[];
|
|
12
20
|
}
|
|
21
|
+
export declare class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
22
|
+
render(): JSX.Element | JSX.Element[];
|
|
23
|
+
}
|
|
13
24
|
export {};
|
package/lib/cjs/action.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlowBuilderAction = void 0;
|
|
3
|
+
exports.FlowBuilderMultichannelAction = exports.FlowBuilderAction = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = require("@botonic/react");
|
|
6
6
|
const react_2 = tslib_1.__importDefault(require("react"));
|
|
@@ -29,16 +29,26 @@ class FlowBuilderAction extends react_2.default.Component {
|
|
|
29
29
|
alternateFallbackMessage = !alternateFallbackMessage;
|
|
30
30
|
}
|
|
31
31
|
const { contents, handoffNode } = await flowBuilderPlugin.getContents(targetContentId, locale);
|
|
32
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
33
|
+
// TODO: track all targets nodes?
|
|
34
|
+
await flowBuilderPlugin.trackEvent(request, contents[0].code);
|
|
35
|
+
}
|
|
32
36
|
if (handoffNode)
|
|
33
37
|
await (0, handoff_1.doHandoff)(request, locale, handoffNode);
|
|
34
38
|
return { contents, handoffNode };
|
|
35
39
|
}
|
|
36
40
|
render() {
|
|
37
|
-
|
|
38
|
-
const { contents, handoffNode } = this.props;
|
|
41
|
+
const { contents } = this.props;
|
|
39
42
|
return contents.map(content => content.toBotonic(content.id));
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
exports.FlowBuilderAction = FlowBuilderAction;
|
|
43
46
|
FlowBuilderAction.contextType = react_1.RequestContext;
|
|
47
|
+
class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
48
|
+
render() {
|
|
49
|
+
const { contents } = this.props;
|
|
50
|
+
return (react_2.default.createElement(react_1.Multichannel, { text: { buttonsAsText: false } }, contents.map(content => content.toBotonic(content.id))));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.FlowBuilderMultichannelAction = FlowBuilderMultichannelAction;
|
|
44
54
|
//# sourceMappingURL=action.js.map
|
package/lib/cjs/action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":";;;;AAAA,0CAA4E;AAC5E,0DAAyB;AAGzB,uCAAqC;AACrC,uCAAgD;AAOhD,IAAI,wBAAwB,GAAG,KAAK,CAAA;AACpC,MAAa,iBAAkB,SAAQ,eAAK,CAAC,SAAiC;IAG5E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAsB;QAC7C,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,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AM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC/B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/D,CAAC;;AAhDH,8CAiDC;AAhDQ,6BAAW,GAAG,sBAAc,CAAA;AAkDrC,MAAa,6BAA8B,SAAQ,iBAAiB;IAClE,MAAM;QACJ,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC/B,OAAO,CACL,8BAAC,oBAAY,IAAC,IAAI,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,IACzC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAC1C,CAChB,CAAA;IACH,CAAC;CACF;AATD,sEASC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.conditionalProvider = void 0;
|
|
4
|
-
function conditionalProvider({
|
|
5
|
-
const provider = session.user.provider;
|
|
4
|
+
function conditionalProvider({ request, results }) {
|
|
5
|
+
const provider = request.session.user.provider;
|
|
6
6
|
if (results.includes(provider))
|
|
7
7
|
return provider;
|
|
8
8
|
return 'default';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../../src/functions/conditional-provider.ts"],"names":[],"mappings":";;;AAAA,SAAgB,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../../src/functions/conditional-provider.ts"],"names":[],"mappings":";;;AAAA,SAAgB,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;IAC9C,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAA;IAC/C,OAAO,SAAS,CAAA;AAClB,CAAC;AAJD,kDAIC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
|
+
type ConditionalQueueStatusArgs = {
|
|
3
|
+
request: ActionRequest;
|
|
2
4
|
queue_id: string;
|
|
3
|
-
|
|
5
|
+
queue_name: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function conditionalQueueStatus({ request, queue_id, queue_name, }: ConditionalQueueStatusArgs): Promise<string>;
|
|
8
|
+
export {};
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.conditionalQueueStatus = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
6
5
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const helpers_1 = require("../helpers");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const _HUBTYPE_API_URL_ = (0, utils_1.getWebpackEnvVar)(
|
|
9
9
|
// @ts-ignore
|
|
10
10
|
typeof HUBTYPE_API_URL !== 'undefined' && HUBTYPE_API_URL, 'HUBTYPE_API_URL', 'https://api.hubtype.com');
|
|
11
|
-
async function conditionalQueueStatus({ queue_id, }) {
|
|
11
|
+
async function conditionalQueueStatus({ request, queue_id, queue_name, }) {
|
|
12
12
|
const response = await axios_1.default.get(`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
|
|
13
13
|
// TODO: Make it configurable in the future
|
|
14
14
|
{
|
|
@@ -19,6 +19,17 @@ async function conditionalQueueStatus({ queue_id, }) {
|
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
const isAvailable = response.data.available;
|
|
22
|
+
console.log('conditionalQueueStatus', { data: response.data });
|
|
23
|
+
const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
|
|
24
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
25
|
+
const eventName = 'QUEUE_STATUS';
|
|
26
|
+
const args = {
|
|
27
|
+
queue_id,
|
|
28
|
+
queue_name,
|
|
29
|
+
status: isAvailable ? 'open' : 'closed',
|
|
30
|
+
};
|
|
31
|
+
await flowBuilderPlugin.trackEvent(request, eventName, args);
|
|
32
|
+
}
|
|
22
33
|
return isAvailable ? 'open' : 'closed';
|
|
23
34
|
}
|
|
24
35
|
exports.conditionalQueueStatus = conditionalQueueStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";;;;AACA,0DAAyB;AAEzB,wCAAiD;AACjD,oCAA2C;AAE3C,MAAM,iBAAiB,GAAG,IAAA,wBAAgB;AACxC,aAAa;AACb,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EACzD,iBAAiB,EACjB,yBAAyB,CAC1B,CAAA;AAQM,KAAK,UAAU,sBAAsB,CAAC,EAC3C,OAAO,EACP,QAAQ,EACR,UAAU,GACiB;IAC3B,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAC9B,GAAG,iBAAiB,cAAc,QAAQ,gBAAgB;IAC1D,2CAA2C;IAC3C;QACE,MAAM,EAAE;YACN,oBAAoB,EAAE,IAAI;YAC1B,mBAAmB,EAAE,KAAK;YAC1B,sBAAsB,EAAE,KAAK;SAC9B;KACF,CACF,CAAA;IACD,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAA;IAE3C,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9D,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;QAChC,MAAM,SAAS,GAAG,cAAc,CAAA;QAChC,MAAM,IAAI,GAAG;YACX,QAAQ;YACR,UAAU;YACV,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;SACxC,CAAA;QACD,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;KAC7D;IAED,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC;AA/BD,wDA+BC"}
|
package/lib/cjs/handoff.js
CHANGED
|
@@ -4,15 +4,16 @@ exports.doHandoff = void 0;
|
|
|
4
4
|
const core_1 = require("@botonic/core");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
6
|
async function doHandoff(request, locale, handoffNode) {
|
|
7
|
-
var _a;
|
|
8
7
|
const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
|
|
9
|
-
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
10
8
|
// @ts-ignore
|
|
11
|
-
const handOffBuilder = new core_1.HandOffBuilder(request.session);
|
|
9
|
+
const handOffBuilder = new core_1.HandOffBuilder(request.session);
|
|
12
10
|
const handoffQueues = handoffNode.content.queue;
|
|
13
11
|
const queueFound = handoffQueues.find(q => q.locale === locale);
|
|
14
12
|
if (queueFound)
|
|
15
13
|
handOffBuilder.withQueue(queueFound.id);
|
|
14
|
+
const onFinishPayload = await getOnFinishPayload(flowBuilderPlugin, handoffNode, locale);
|
|
15
|
+
if (onFinishPayload)
|
|
16
|
+
handOffBuilder.withOnFinishPayload(onFinishPayload);
|
|
16
17
|
// TODO: Retrieve params from FlowBuilder
|
|
17
18
|
// const handoffParams = {
|
|
18
19
|
// agentEmail: 'test@gmail.com',
|
|
@@ -24,8 +25,23 @@ async function doHandoff(request, locale, handoffNode) {
|
|
|
24
25
|
// if (handoffParams.agentEmail) {
|
|
25
26
|
// handOffBuilder.withAgentEmail(handoffParams.agentEmail)
|
|
26
27
|
// }
|
|
27
|
-
handOffBuilder.withOnFinishPayload(handoffTargetNode.id);
|
|
28
28
|
await handOffBuilder.handOff();
|
|
29
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
30
|
+
await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
|
|
31
|
+
queueName: queueFound === null || queueFound === void 0 ? void 0 : queueFound.name,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
exports.doHandoff = doHandoff;
|
|
36
|
+
async function getOnFinishPayload(flowBuilderPlugin, handoffNode, locale) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
39
|
+
if (handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id)
|
|
40
|
+
return handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id;
|
|
41
|
+
const payloadId = (_b = handoffNode.content.payload.find(payload => payload.locale === locale)) === null || _b === void 0 ? void 0 : _b.id;
|
|
42
|
+
if (!payloadId)
|
|
43
|
+
return undefined;
|
|
44
|
+
const actionPayload = await flowBuilderPlugin.getContent(payloadId);
|
|
45
|
+
return actionPayload.content.payload;
|
|
46
|
+
}
|
|
31
47
|
//# sourceMappingURL=handoff.js.map
|
package/lib/cjs/handoff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAI9C,uCAAgD;
|
|
1
|
+
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAI9C,uCAAgD;AAGzC,KAAK,UAAU,SAAS,CAC7B,OAAsB,EACtB,MAAc,EACd,WAAwB;IAExB,MAAM,iBAAiB,GAAG,IAAA,8BAAoB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,aAAa;IACb,MAAM,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1D,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;IAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;IAC/D,IAAI,UAAU;QAAE,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAEvD,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAC9C,iBAAiB,EACjB,WAAW,EACX,MAAM,CACP,CAAA;IACD,IAAI,eAAe;QAAE,cAAc,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAA;IAExE,yCAAyC;IACzC,0BAA0B;IAC1B,kCAAkC;IAClC,4EAA4E;IAC5E,IAAI;IAEJ,4BAA4B;IAC5B,gDAAgD;IAChD,IAAI;IAEJ,kCAAkC;IAClC,4DAA4D;IAC5D,IAAI;IAEJ,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;IAE9B,IAAI,iBAAiB,CAAC,UAAU,EAAE;QAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,qBAAqB,EAAE;YACjE,SAAS,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI;SAC5B,CAAC,CAAA;KACH;AACH,CAAC;AAxCD,8BAwCC;AAED,KAAK,UAAU,kBAAkB,CAC/B,iBAA2C,EAC3C,WAAwB,EACxB,MAAc;;IAEd,MAAM,iBAAiB,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,CACjE,MAAA,WAAW,CAAC,MAAM,0CAAE,EAAE,CACvB,CAAA;IACD,IAAI,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,EAAE;QAAE,OAAO,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,EAAE,CAAA;IAEvD,MAAM,SAAS,GAAG,MAAA,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAChD,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CACrC,0CAAE,EAAE,CAAA;IAEL,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAEhC,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAEnE,OAAQ,aAA6B,CAAC,OAAO,CAAC,OAAO,CAAA;AACvD,CAAC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Input, Plugin, PluginPostRequest, PluginPreRequest, Session } from '@botonic/core';
|
|
2
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
3
|
import { FlowContent } from './content-fields';
|
|
3
4
|
import { FlowBuilderData, FunctionNode, HandoffNode, IntentNode, KeywordNode, NodeComponent } from './flow-builder-models';
|
|
4
5
|
import { BotonicPluginFlowBuilderOptions } from './types';
|
|
@@ -10,12 +11,14 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
10
11
|
private currentRequest;
|
|
11
12
|
private getAccessToken;
|
|
12
13
|
getLocale: (session: Session) => string;
|
|
14
|
+
trackEvent?: (request: ActionRequest, eventName: string, args?: Record<string, any>) => Promise<void>;
|
|
13
15
|
constructor(options: BotonicPluginFlowBuilderOptions);
|
|
14
16
|
readFlowContent(session: Session): Promise<FlowBuilderData>;
|
|
15
17
|
pre(request: PluginPreRequest): Promise<void>;
|
|
16
18
|
post(_request: PluginPostRequest): Promise<void>;
|
|
17
19
|
getContent(id: string): Promise<NodeComponent>;
|
|
18
|
-
|
|
20
|
+
getContentByCode(code: string): Promise<NodeComponent>;
|
|
21
|
+
getHandoffContent(handoffTargetId: string | undefined): Promise<HandoffNode | undefined>;
|
|
19
22
|
getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
|
|
20
23
|
getStartId(): Promise<string>;
|
|
21
24
|
getFallbackId(alternate: boolean): Promise<string>;
|
|
@@ -23,6 +26,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
23
26
|
contents: FlowContent[];
|
|
24
27
|
handoffNode: HandoffNode;
|
|
25
28
|
}>;
|
|
29
|
+
private replaceButtonPayload;
|
|
26
30
|
getPayloadByIntent(input: Input, locale: string): Promise<string | undefined>;
|
|
27
31
|
hasIntent(node: IntentNode, intent: string, locale: string): boolean;
|
|
28
32
|
hasMetConfidenceThreshold(node: IntentNode, predictedConfidence: number): boolean;
|
|
@@ -31,4 +35,4 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
31
35
|
containsAnyKeywords(input: string, keywords: string[]): boolean;
|
|
32
36
|
callFunction(functionNode: FunctionNode, locale: string): Promise<string>;
|
|
33
37
|
}
|
|
34
|
-
export
|
|
38
|
+
export * from './action';
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlowBuilderAction = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
5
|
const content_fields_1 = require("./content-fields");
|
|
@@ -13,6 +12,7 @@ class BotonicPluginFlowBuilder {
|
|
|
13
12
|
this.options = options;
|
|
14
13
|
this.getLocale = options.getLocale;
|
|
15
14
|
this.getAccessToken = (0, utils_1.resolveGetAccessToken)(options);
|
|
15
|
+
this.trackEvent = options.trackEvent;
|
|
16
16
|
this.flowUrl = options.flowUrl;
|
|
17
17
|
if (options.flow)
|
|
18
18
|
this.flow = options.flow;
|
|
@@ -37,13 +37,22 @@ class BotonicPluginFlowBuilder {
|
|
|
37
37
|
throw Error(`Node with id: '${id}' not found`);
|
|
38
38
|
return content;
|
|
39
39
|
}
|
|
40
|
-
async
|
|
40
|
+
async getContentByCode(code) {
|
|
41
41
|
const flow = await this.flow;
|
|
42
|
-
const content = flow.nodes.find(node =>
|
|
42
|
+
const content = flow.nodes.find(node => {
|
|
43
|
+
if ('code' in node)
|
|
44
|
+
return node.code === code;
|
|
45
|
+
return undefined;
|
|
46
|
+
});
|
|
43
47
|
if (!content)
|
|
44
|
-
throw Error(`
|
|
48
|
+
throw Error(`Node with code: '${code}' not found`);
|
|
45
49
|
return content;
|
|
46
50
|
}
|
|
51
|
+
async getHandoffContent(handoffTargetId) {
|
|
52
|
+
if (!handoffTargetId)
|
|
53
|
+
return undefined;
|
|
54
|
+
return (await this.getContent(handoffTargetId));
|
|
55
|
+
}
|
|
47
56
|
getFlowContent(hubtypeContent, locale) {
|
|
48
57
|
switch (hubtypeContent.type) {
|
|
49
58
|
case flow_builder_models_1.NodeType.TEXT:
|
|
@@ -83,17 +92,8 @@ class BotonicPluginFlowBuilder {
|
|
|
83
92
|
// TODO: Create function to populate these buttons
|
|
84
93
|
await (0, helpers_1.updateButtonUrls)(hubtypeContent, 'elements', this.getContent);
|
|
85
94
|
await (0, helpers_1.updateButtonUrls)(hubtypeContent, 'buttons', this.getContent);
|
|
86
|
-
const content =
|
|
87
|
-
|
|
88
|
-
content.buttons.forEach(async (button) => {
|
|
89
|
-
if (button.payload) {
|
|
90
|
-
const contentButton = await this.getContent(button.payload);
|
|
91
|
-
if ((contentButton === null || contentButton === void 0 ? void 0 : contentButton.type) === flow_builder_models_1.NodeType.PAYLOAD) {
|
|
92
|
-
button.payload = contentButton.content.payload;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
95
|
+
const content = this.getFlowContent(hubtypeContent, locale);
|
|
96
|
+
this.replaceButtonPayload(content);
|
|
97
97
|
if (hubtypeContent.type === flow_builder_models_1.NodeType.FUNCTION) {
|
|
98
98
|
const targetId = await this.callFunction(hubtypeContent, locale);
|
|
99
99
|
return this.getContents(targetId, locale, contents);
|
|
@@ -109,6 +109,18 @@ class BotonicPluginFlowBuilder {
|
|
|
109
109
|
// return this.getContents(function result_mapping target, locale, contents)
|
|
110
110
|
return { contents, handoffNode: isHandoff && hubtypeContent };
|
|
111
111
|
}
|
|
112
|
+
async replaceButtonPayload(content) {
|
|
113
|
+
if (content && 'buttons' in content) {
|
|
114
|
+
for (const button of content.buttons) {
|
|
115
|
+
if (button.payload) {
|
|
116
|
+
const contentButton = await this.getContent(button.payload);
|
|
117
|
+
if ((contentButton === null || contentButton === void 0 ? void 0 : contentButton.type) === flow_builder_models_1.NodeType.PAYLOAD) {
|
|
118
|
+
button.payload = contentButton.content.payload;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
112
124
|
async getPayloadByIntent(input, locale) {
|
|
113
125
|
var _a;
|
|
114
126
|
try {
|
|
@@ -171,7 +183,7 @@ class BotonicPluginFlowBuilder {
|
|
|
171
183
|
const nameValues = ((_a = functionNode.content.arguments
|
|
172
184
|
.find(arg => arg.locale === locale)) === null || _a === void 0 ? void 0 : _a.values.map(value => ({ [value.name]: value.value }))) || [];
|
|
173
185
|
const args = Object.assign({
|
|
174
|
-
|
|
186
|
+
request: this.currentRequest,
|
|
175
187
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
176
188
|
}, ...nameValues);
|
|
177
189
|
const functionResult = await this.functions[functionNode.content.action](args);
|
|
@@ -184,6 +196,5 @@ class BotonicPluginFlowBuilder {
|
|
|
184
196
|
}
|
|
185
197
|
}
|
|
186
198
|
exports.default = BotonicPluginFlowBuilder;
|
|
187
|
-
|
|
188
|
-
Object.defineProperty(exports, "FlowBuilderAction", { enumerable: true, get: function () { return action_1.FlowBuilderAction; } });
|
|
199
|
+
tslib_1.__exportStar(require("./action"), exports);
|
|
189
200
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAQA,0DAAyB;AAEzB,qDAMyB;AACzB,+DAU8B;AAC9B,2CAA+C;AAC/C,uCAA4C;AAE5C,mCAA+C;AAE/C,MAAqB,wBAAwB;IAa3C,YAAqB,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;QAC3D,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QAC1C,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAA;QACrD,IAAI,CAAC,SAAS,mCAAQ,6BAAiB,GAAK,eAAe,CAAE,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAAgB;QACpC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE;YAC7C,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,IAA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C,cAAc;YAC5B,OAAO,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;SAClE,EACD,GAAG,UAAU,CACd,CAAA;QACD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CACtE,IAAI,CACL,CAAA;QACD,0CAA0C;QAC1C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,cAAc,CACjC,CAAA;QACD,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CACb,wDAAwD,cAAc,EAAE,CACzE,CAAA;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAA;IACzB,CAAC;CACF;AA9PD,2CA8PC;AAED,mDAAwB"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Session } from '@botonic/core';
|
|
2
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
3
|
import { FlowBuilderData } from './flow-builder-models';
|
|
3
4
|
export interface BotonicPluginFlowBuilderOptions {
|
|
4
5
|
flowUrl: string;
|
|
@@ -6,6 +7,7 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
6
7
|
customFunctions?: Record<any, any>;
|
|
7
8
|
getLocale: (session: Session) => string;
|
|
8
9
|
getAccessToken: () => string;
|
|
10
|
+
trackEvent?: (request: ActionRequest, eventName: string, args?: Record<string, any>) => Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
export declare enum ProcessEnvNodeEnvs {
|
|
11
13
|
PRODUCTION = "production",
|
package/lib/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAkBA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAG7B"}
|
package/lib/esm/action.d.ts
CHANGED
|
@@ -2,12 +2,23 @@ import { ActionRequest } from '@botonic/react';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { FlowContent } from './content-fields';
|
|
4
4
|
type FlowBuilderActionProps = {
|
|
5
|
-
|
|
5
|
+
contents: FlowContent[];
|
|
6
6
|
isHandoff?: boolean;
|
|
7
7
|
};
|
|
8
8
|
export declare class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
9
|
-
static contextType: React.Context<
|
|
9
|
+
static contextType: React.Context<{
|
|
10
|
+
getString: () => "";
|
|
11
|
+
setLocale: () => "";
|
|
12
|
+
session: {};
|
|
13
|
+
params: {};
|
|
14
|
+
input: {};
|
|
15
|
+
defaultDelay: number;
|
|
16
|
+
defaultTyping: number;
|
|
17
|
+
}>;
|
|
10
18
|
static botonicInit(request: ActionRequest): Promise<any>;
|
|
11
19
|
render(): JSX.Element | JSX.Element[];
|
|
12
20
|
}
|
|
21
|
+
export declare class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
22
|
+
render(): JSX.Element | JSX.Element[];
|
|
23
|
+
}
|
|
13
24
|
export {};
|
package/lib/esm/action.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestContext } from '@botonic/react';
|
|
1
|
+
import { Multichannel, RequestContext } from '@botonic/react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { doHandoff } from './handoff';
|
|
4
4
|
import { getFlowBuilderPlugin } from './helpers';
|
|
@@ -25,15 +25,24 @@ export class FlowBuilderAction extends React.Component {
|
|
|
25
25
|
alternateFallbackMessage = !alternateFallbackMessage;
|
|
26
26
|
}
|
|
27
27
|
const { contents, handoffNode } = await flowBuilderPlugin.getContents(targetContentId, locale);
|
|
28
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
29
|
+
// TODO: track all targets nodes?
|
|
30
|
+
await flowBuilderPlugin.trackEvent(request, contents[0].code);
|
|
31
|
+
}
|
|
28
32
|
if (handoffNode)
|
|
29
33
|
await doHandoff(request, locale, handoffNode);
|
|
30
34
|
return { contents, handoffNode };
|
|
31
35
|
}
|
|
32
36
|
render() {
|
|
33
|
-
|
|
34
|
-
const { contents, handoffNode } = this.props;
|
|
37
|
+
const { contents } = this.props;
|
|
35
38
|
return contents.map(content => content.toBotonic(content.id));
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
FlowBuilderAction.contextType = RequestContext;
|
|
42
|
+
export class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
43
|
+
render() {
|
|
44
|
+
const { contents } = this.props;
|
|
45
|
+
return (React.createElement(Multichannel, { text: { buttonsAsText: false } }, contents.map(content => content.toBotonic(content.id))));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
39
48
|
//# sourceMappingURL=action.js.map
|
package/lib/esm/action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAOhD,IAAI,wBAAwB,GAAG,KAAK,CAAA;AACpC,MAAM,OAAO,iBA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AAM,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;QAE9D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAA;IAClC,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC/B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/D,CAAC;;AA/CM,6BAAW,GAAG,cAAc,CAAA;AAkDrC,MAAM,OAAO,6BAA8B,SAAQ,iBAAiB;IAClE,MAAM;QACJ,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC/B,OAAO,CACL,oBAAC,YAAY,IAAC,IAAI,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,IACzC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAC1C,CAChB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function conditionalProvider({
|
|
2
|
-
const provider = session.user.provider;
|
|
1
|
+
export function conditionalProvider({ request, results }) {
|
|
2
|
+
const provider = request.session.user.provider;
|
|
3
3
|
if (results.includes(provider))
|
|
4
4
|
return provider;
|
|
5
5
|
return 'default';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../../src/functions/conditional-provider.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../../src/functions/conditional-provider.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;IAC9C,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAA;IAC/C,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
|
+
type ConditionalQueueStatusArgs = {
|
|
3
|
+
request: ActionRequest;
|
|
2
4
|
queue_id: string;
|
|
3
|
-
|
|
5
|
+
queue_name: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function conditionalQueueStatus({ request, queue_id, queue_name, }: ConditionalQueueStatusArgs): Promise<string>;
|
|
8
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
1
|
import axios from 'axios';
|
|
2
|
+
import { getFlowBuilderPlugin } from '../helpers';
|
|
3
3
|
import { getWebpackEnvVar } from '../utils';
|
|
4
4
|
const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
typeof HUBTYPE_API_URL !== 'undefined' && HUBTYPE_API_URL, 'HUBTYPE_API_URL', 'https://api.hubtype.com');
|
|
7
|
-
export async function conditionalQueueStatus({ queue_id, }) {
|
|
7
|
+
export async function conditionalQueueStatus({ request, queue_id, queue_name, }) {
|
|
8
8
|
const response = await axios.get(`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
|
|
9
9
|
// TODO: Make it configurable in the future
|
|
10
10
|
{
|
|
@@ -15,6 +15,17 @@ export async function conditionalQueueStatus({ queue_id, }) {
|
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
const isAvailable = response.data.available;
|
|
18
|
+
console.log('conditionalQueueStatus', { data: response.data });
|
|
19
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
20
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
21
|
+
const eventName = 'QUEUE_STATUS';
|
|
22
|
+
const args = {
|
|
23
|
+
queue_id,
|
|
24
|
+
queue_name,
|
|
25
|
+
status: isAvailable ? 'open' : 'closed',
|
|
26
|
+
};
|
|
27
|
+
await flowBuilderPlugin.trackEvent(request, eventName, args);
|
|
28
|
+
}
|
|
18
29
|
return isAvailable ? 'open' : 'closed';
|
|
19
30
|
}
|
|
20
31
|
//# sourceMappingURL=conditional-queue-status.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE3C,MAAM,iBAAiB,GAAG,gBAAgB;AACxC,aAAa;AACb,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EACzD,iBAAiB,EACjB,yBAAyB,CAC1B,CAAA;AAQD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,OAAO,EACP,QAAQ,EACR,UAAU,GACiB;IAC3B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,iBAAiB,cAAc,QAAQ,gBAAgB;IAC1D,2CAA2C;IAC3C;QACE,MAAM,EAAE;YACN,oBAAoB,EAAE,IAAI;YAC1B,mBAAmB,EAAE,KAAK;YAC1B,sBAAsB,EAAE,KAAK;SAC9B;KACF,CACF,CAAA;IACD,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAA;IAE3C,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9D,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;QAChC,MAAM,SAAS,GAAG,cAAc,CAAA;QAChC,MAAM,IAAI,GAAG;YACX,QAAQ;YACR,UAAU;YACV,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;SACxC,CAAA;QACD,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;KAC7D;IAED,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxC,CAAC"}
|
package/lib/esm/handoff.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { HandOffBuilder } from '@botonic/core';
|
|
2
2
|
import { getFlowBuilderPlugin } from './helpers';
|
|
3
3
|
export async function doHandoff(request, locale, handoffNode) {
|
|
4
|
-
var _a;
|
|
5
4
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
6
|
-
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
7
5
|
// @ts-ignore
|
|
8
|
-
const handOffBuilder = new HandOffBuilder(request.session);
|
|
6
|
+
const handOffBuilder = new HandOffBuilder(request.session);
|
|
9
7
|
const handoffQueues = handoffNode.content.queue;
|
|
10
8
|
const queueFound = handoffQueues.find(q => q.locale === locale);
|
|
11
9
|
if (queueFound)
|
|
12
10
|
handOffBuilder.withQueue(queueFound.id);
|
|
11
|
+
const onFinishPayload = await getOnFinishPayload(flowBuilderPlugin, handoffNode, locale);
|
|
12
|
+
if (onFinishPayload)
|
|
13
|
+
handOffBuilder.withOnFinishPayload(onFinishPayload);
|
|
13
14
|
// TODO: Retrieve params from FlowBuilder
|
|
14
15
|
// const handoffParams = {
|
|
15
16
|
// agentEmail: 'test@gmail.com',
|
|
@@ -21,7 +22,22 @@ export async function doHandoff(request, locale, handoffNode) {
|
|
|
21
22
|
// if (handoffParams.agentEmail) {
|
|
22
23
|
// handOffBuilder.withAgentEmail(handoffParams.agentEmail)
|
|
23
24
|
// }
|
|
24
|
-
handOffBuilder.withOnFinishPayload(handoffTargetNode.id);
|
|
25
25
|
await handOffBuilder.handOff();
|
|
26
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
27
|
+
await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
|
|
28
|
+
queueName: queueFound === null || queueFound === void 0 ? void 0 : queueFound.name,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function getOnFinishPayload(flowBuilderPlugin, handoffNode, locale) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
35
|
+
if (handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id)
|
|
36
|
+
return handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id;
|
|
37
|
+
const payloadId = (_b = handoffNode.content.payload.find(payload => payload.locale === locale)) === null || _b === void 0 ? void 0 : _b.id;
|
|
38
|
+
if (!payloadId)
|
|
39
|
+
return undefined;
|
|
40
|
+
const actionPayload = await flowBuilderPlugin.getContent(payloadId);
|
|
41
|
+
return actionPayload.content.payload;
|
|
26
42
|
}
|
|
27
43
|
//# sourceMappingURL=handoff.js.map
|
package/lib/esm/handoff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA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U,uBAAV,UAAU,CAAE,IAAI;SAC5B,CAAC,CAAA;KACH;AACH,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,iBAA2C,EAC3C,WAAwB,EACxB,MAAc;;IAEd,MAAM,iBAAiB,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,CACjE,MAAA,WAAW,CAAC,MAAM,0CAAE,EAAE,CACvB,CAAA;IACD,IAAI,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,EAAE;QAAE,OAAO,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,EAAE,CAAA;IAEvD,MAAM,SAAS,GAAG,MAAA,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAChD,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CACrC,0CAAE,EAAE,CAAA;IAEL,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAEhC,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAEnE,OAAQ,aAA6B,CAAC,OAAO,CAAC,OAAO,CAAA;AACvD,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Input, Plugin, PluginPostRequest, PluginPreRequest, Session } from '@botonic/core';
|
|
2
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
3
|
import { FlowContent } from './content-fields';
|
|
3
4
|
import { FlowBuilderData, FunctionNode, HandoffNode, IntentNode, KeywordNode, NodeComponent } from './flow-builder-models';
|
|
4
5
|
import { BotonicPluginFlowBuilderOptions } from './types';
|
|
@@ -10,12 +11,14 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
10
11
|
private currentRequest;
|
|
11
12
|
private getAccessToken;
|
|
12
13
|
getLocale: (session: Session) => string;
|
|
14
|
+
trackEvent?: (request: ActionRequest, eventName: string, args?: Record<string, any>) => Promise<void>;
|
|
13
15
|
constructor(options: BotonicPluginFlowBuilderOptions);
|
|
14
16
|
readFlowContent(session: Session): Promise<FlowBuilderData>;
|
|
15
17
|
pre(request: PluginPreRequest): Promise<void>;
|
|
16
18
|
post(_request: PluginPostRequest): Promise<void>;
|
|
17
19
|
getContent(id: string): Promise<NodeComponent>;
|
|
18
|
-
|
|
20
|
+
getContentByCode(code: string): Promise<NodeComponent>;
|
|
21
|
+
getHandoffContent(handoffTargetId: string | undefined): Promise<HandoffNode | undefined>;
|
|
19
22
|
getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
|
|
20
23
|
getStartId(): Promise<string>;
|
|
21
24
|
getFallbackId(alternate: boolean): Promise<string>;
|
|
@@ -23,6 +26,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
23
26
|
contents: FlowContent[];
|
|
24
27
|
handoffNode: HandoffNode;
|
|
25
28
|
}>;
|
|
29
|
+
private replaceButtonPayload;
|
|
26
30
|
getPayloadByIntent(input: Input, locale: string): Promise<string | undefined>;
|
|
27
31
|
hasIntent(node: IntentNode, intent: string, locale: string): boolean;
|
|
28
32
|
hasMetConfidenceThreshold(node: IntentNode, predictedConfidence: number): boolean;
|
|
@@ -31,4 +35,4 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
31
35
|
containsAnyKeywords(input: string, keywords: string[]): boolean;
|
|
32
36
|
callFunction(functionNode: FunctionNode, locale: string): Promise<string>;
|
|
33
37
|
}
|
|
34
|
-
export
|
|
38
|
+
export * from './action';
|
package/lib/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export default class BotonicPluginFlowBuilder {
|
|
|
9
9
|
this.options = options;
|
|
10
10
|
this.getLocale = options.getLocale;
|
|
11
11
|
this.getAccessToken = resolveGetAccessToken(options);
|
|
12
|
+
this.trackEvent = options.trackEvent;
|
|
12
13
|
this.flowUrl = options.flowUrl;
|
|
13
14
|
if (options.flow)
|
|
14
15
|
this.flow = options.flow;
|
|
@@ -33,13 +34,22 @@ export default class BotonicPluginFlowBuilder {
|
|
|
33
34
|
throw Error(`Node with id: '${id}' not found`);
|
|
34
35
|
return content;
|
|
35
36
|
}
|
|
36
|
-
async
|
|
37
|
+
async getContentByCode(code) {
|
|
37
38
|
const flow = await this.flow;
|
|
38
|
-
const content = flow.nodes.find(node =>
|
|
39
|
+
const content = flow.nodes.find(node => {
|
|
40
|
+
if ('code' in node)
|
|
41
|
+
return node.code === code;
|
|
42
|
+
return undefined;
|
|
43
|
+
});
|
|
39
44
|
if (!content)
|
|
40
|
-
throw Error(`
|
|
45
|
+
throw Error(`Node with code: '${code}' not found`);
|
|
41
46
|
return content;
|
|
42
47
|
}
|
|
48
|
+
async getHandoffContent(handoffTargetId) {
|
|
49
|
+
if (!handoffTargetId)
|
|
50
|
+
return undefined;
|
|
51
|
+
return (await this.getContent(handoffTargetId));
|
|
52
|
+
}
|
|
43
53
|
getFlowContent(hubtypeContent, locale) {
|
|
44
54
|
switch (hubtypeContent.type) {
|
|
45
55
|
case NodeType.TEXT:
|
|
@@ -79,17 +89,8 @@ export default class BotonicPluginFlowBuilder {
|
|
|
79
89
|
// TODO: Create function to populate these buttons
|
|
80
90
|
await updateButtonUrls(hubtypeContent, 'elements', this.getContent);
|
|
81
91
|
await updateButtonUrls(hubtypeContent, 'buttons', this.getContent);
|
|
82
|
-
const content =
|
|
83
|
-
|
|
84
|
-
content.buttons.forEach(async (button) => {
|
|
85
|
-
if (button.payload) {
|
|
86
|
-
const contentButton = await this.getContent(button.payload);
|
|
87
|
-
if ((contentButton === null || contentButton === void 0 ? void 0 : contentButton.type) === NodeType.PAYLOAD) {
|
|
88
|
-
button.payload = contentButton.content.payload;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
92
|
+
const content = this.getFlowContent(hubtypeContent, locale);
|
|
93
|
+
this.replaceButtonPayload(content);
|
|
93
94
|
if (hubtypeContent.type === NodeType.FUNCTION) {
|
|
94
95
|
const targetId = await this.callFunction(hubtypeContent, locale);
|
|
95
96
|
return this.getContents(targetId, locale, contents);
|
|
@@ -105,6 +106,18 @@ export default class BotonicPluginFlowBuilder {
|
|
|
105
106
|
// return this.getContents(function result_mapping target, locale, contents)
|
|
106
107
|
return { contents, handoffNode: isHandoff && hubtypeContent };
|
|
107
108
|
}
|
|
109
|
+
async replaceButtonPayload(content) {
|
|
110
|
+
if (content && 'buttons' in content) {
|
|
111
|
+
for (const button of content.buttons) {
|
|
112
|
+
if (button.payload) {
|
|
113
|
+
const contentButton = await this.getContent(button.payload);
|
|
114
|
+
if ((contentButton === null || contentButton === void 0 ? void 0 : contentButton.type) === NodeType.PAYLOAD) {
|
|
115
|
+
button.payload = contentButton.content.payload;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
108
121
|
async getPayloadByIntent(input, locale) {
|
|
109
122
|
var _a;
|
|
110
123
|
try {
|
|
@@ -167,7 +180,7 @@ export default class BotonicPluginFlowBuilder {
|
|
|
167
180
|
const nameValues = ((_a = functionNode.content.arguments
|
|
168
181
|
.find(arg => arg.locale === locale)) === null || _a === void 0 ? void 0 : _a.values.map(value => ({ [value.name]: value.value }))) || [];
|
|
169
182
|
const args = Object.assign({
|
|
170
|
-
|
|
183
|
+
request: this.currentRequest,
|
|
171
184
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
172
185
|
}, ...nameValues);
|
|
173
186
|
const functionResult = await this.functions[functionNode.content.action](args);
|
|
@@ -179,5 +192,5 @@ export default class BotonicPluginFlowBuilder {
|
|
|
179
192
|
return result.target.id;
|
|
180
193
|
}
|
|
181
194
|
}
|
|
182
|
-
export
|
|
195
|
+
export * from './action';
|
|
183
196
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index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D,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CACtE,IAAI,CACL,CAAA;QACD,0CAA0C;QAC1C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CACrD,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,cAAc,CACjC,CAAA;QACD,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CACb,wDAAwD,cAAc,EAAE,CACzE,CAAA;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAA;IACzB,CAAC;CACF;AAED,cAAc,UAAU,CAAA"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Session } from '@botonic/core';
|
|
2
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
3
|
import { FlowBuilderData } from './flow-builder-models';
|
|
3
4
|
export interface BotonicPluginFlowBuilderOptions {
|
|
4
5
|
flowUrl: string;
|
|
@@ -6,6 +7,7 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
6
7
|
customFunctions?: Record<any, any>;
|
|
7
8
|
getLocale: (session: Session) => string;
|
|
8
9
|
getAccessToken: () => string;
|
|
10
|
+
trackEvent?: (request: ActionRequest, eventName: string, args?: Record<string, any>) => Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
export declare enum ProcessEnvNodeEnvs {
|
|
11
13
|
PRODUCTION = "production",
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.22.0-alpha.
|
|
3
|
+
"version": "0.22.0-alpha.2",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/runtime": "^7.21.0",
|
|
51
51
|
"axios": "^1.3.6",
|
|
52
|
-
"@botonic/react": "
|
|
52
|
+
"@botonic/react": "0.22.0-beta.2"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/action.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionRequest, RequestContext } from '@botonic/react'
|
|
1
|
+
import { ActionRequest, Multichannel, RequestContext } from '@botonic/react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { FlowContent } from './content-fields'
|
|
@@ -6,7 +6,7 @@ import { doHandoff } from './handoff'
|
|
|
6
6
|
import { getFlowBuilderPlugin } from './helpers'
|
|
7
7
|
|
|
8
8
|
type FlowBuilderActionProps = {
|
|
9
|
-
|
|
9
|
+
contents: FlowContent[]
|
|
10
10
|
isHandoff?: boolean
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -46,14 +46,29 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
46
46
|
locale
|
|
47
47
|
)
|
|
48
48
|
|
|
49
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
50
|
+
// TODO: track all targets nodes?
|
|
51
|
+
await flowBuilderPlugin.trackEvent(request, contents[0].code)
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
if (handoffNode) await doHandoff(request, locale, handoffNode)
|
|
50
55
|
|
|
51
56
|
return { contents, handoffNode }
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
render(): JSX.Element | JSX.Element[] {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const { contents } = this.props
|
|
61
|
+
return contents.map(content => content.toBotonic(content.id))
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
66
|
+
render(): JSX.Element | JSX.Element[] {
|
|
67
|
+
const { contents } = this.props
|
|
68
|
+
return (
|
|
69
|
+
<Multichannel text={{ buttonsAsText: false }}>
|
|
70
|
+
{contents.map(content => content.toBotonic(content.id))}
|
|
71
|
+
</Multichannel>
|
|
72
|
+
)
|
|
58
73
|
}
|
|
59
74
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function conditionalProvider({
|
|
2
|
-
const provider = session.user.provider
|
|
1
|
+
export function conditionalProvider({ request, results }): string {
|
|
2
|
+
const provider = request.session.user.provider
|
|
3
3
|
if (results.includes(provider)) return provider
|
|
4
4
|
return 'default'
|
|
5
5
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { ActionRequest } from '@botonic/react'
|
|
2
2
|
import axios from 'axios'
|
|
3
3
|
|
|
4
|
+
import { getFlowBuilderPlugin } from '../helpers'
|
|
4
5
|
import { getWebpackEnvVar } from '../utils'
|
|
5
6
|
|
|
6
7
|
const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
@@ -10,11 +11,17 @@ const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
|
10
11
|
'https://api.hubtype.com'
|
|
11
12
|
)
|
|
12
13
|
|
|
14
|
+
type ConditionalQueueStatusArgs = {
|
|
15
|
+
request: ActionRequest
|
|
16
|
+
queue_id: string
|
|
17
|
+
queue_name: string
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
export async function conditionalQueueStatus({
|
|
21
|
+
request,
|
|
14
22
|
queue_id,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}): Promise<string> {
|
|
23
|
+
queue_name,
|
|
24
|
+
}: ConditionalQueueStatusArgs): Promise<string> {
|
|
18
25
|
const response = await axios.get(
|
|
19
26
|
`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
|
|
20
27
|
// TODO: Make it configurable in the future
|
|
@@ -27,5 +34,18 @@ export async function conditionalQueueStatus({
|
|
|
27
34
|
}
|
|
28
35
|
)
|
|
29
36
|
const isAvailable = response.data.available
|
|
37
|
+
|
|
38
|
+
console.log('conditionalQueueStatus', { data: response.data })
|
|
39
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
40
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
41
|
+
const eventName = 'QUEUE_STATUS'
|
|
42
|
+
const args = {
|
|
43
|
+
queue_id,
|
|
44
|
+
queue_name,
|
|
45
|
+
status: isAvailable ? 'open' : 'closed',
|
|
46
|
+
}
|
|
47
|
+
await flowBuilderPlugin.trackEvent(request, eventName, args)
|
|
48
|
+
}
|
|
49
|
+
|
|
30
50
|
return isAvailable ? 'open' : 'closed'
|
|
31
51
|
}
|
package/src/handoff.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { HandOffBuilder } from '@botonic/core'
|
|
2
2
|
import { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
|
-
import { HandoffNode } from './flow-builder-models'
|
|
4
|
+
import { HandoffNode, PayloadNode } from './flow-builder-models'
|
|
5
5
|
import { getFlowBuilderPlugin } from './helpers'
|
|
6
|
+
import BotonicPluginFlowBuilder from './index'
|
|
6
7
|
|
|
7
8
|
export async function doHandoff(
|
|
8
9
|
request: ActionRequest,
|
|
@@ -10,14 +11,19 @@ export async function doHandoff(
|
|
|
10
11
|
handoffNode: HandoffNode
|
|
11
12
|
): Promise<void> {
|
|
12
13
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
13
|
-
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent(
|
|
14
|
-
handoffNode.target?.id
|
|
15
|
-
)
|
|
16
14
|
// @ts-ignore
|
|
17
|
-
const handOffBuilder = new HandOffBuilder(request.session)
|
|
15
|
+
const handOffBuilder = new HandOffBuilder(request.session)
|
|
18
16
|
const handoffQueues = handoffNode.content.queue
|
|
19
17
|
const queueFound = handoffQueues.find(q => q.locale === locale)
|
|
20
18
|
if (queueFound) handOffBuilder.withQueue(queueFound.id)
|
|
19
|
+
|
|
20
|
+
const onFinishPayload = await getOnFinishPayload(
|
|
21
|
+
flowBuilderPlugin,
|
|
22
|
+
handoffNode,
|
|
23
|
+
locale
|
|
24
|
+
)
|
|
25
|
+
if (onFinishPayload) handOffBuilder.withOnFinishPayload(onFinishPayload)
|
|
26
|
+
|
|
21
27
|
// TODO: Retrieve params from FlowBuilder
|
|
22
28
|
// const handoffParams = {
|
|
23
29
|
// agentEmail: 'test@gmail.com',
|
|
@@ -32,6 +38,32 @@ export async function doHandoff(
|
|
|
32
38
|
// handOffBuilder.withAgentEmail(handoffParams.agentEmail)
|
|
33
39
|
// }
|
|
34
40
|
|
|
35
|
-
handOffBuilder.withOnFinishPayload(handoffTargetNode.id)
|
|
36
41
|
await handOffBuilder.handOff()
|
|
42
|
+
|
|
43
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
44
|
+
await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
|
|
45
|
+
queueName: queueFound?.name,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function getOnFinishPayload(
|
|
51
|
+
flowBuilderPlugin: BotonicPluginFlowBuilder,
|
|
52
|
+
handoffNode: HandoffNode,
|
|
53
|
+
locale: string
|
|
54
|
+
): Promise<string | undefined> {
|
|
55
|
+
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent(
|
|
56
|
+
handoffNode.target?.id
|
|
57
|
+
)
|
|
58
|
+
if (handoffTargetNode?.id) return handoffTargetNode?.id
|
|
59
|
+
|
|
60
|
+
const payloadId = handoffNode.content.payload.find(
|
|
61
|
+
payload => payload.locale === locale
|
|
62
|
+
)?.id
|
|
63
|
+
|
|
64
|
+
if (!payloadId) return undefined
|
|
65
|
+
|
|
66
|
+
const actionPayload = await flowBuilderPlugin.getContent(payloadId)
|
|
67
|
+
|
|
68
|
+
return (actionPayload as PayloadNode).content.payload
|
|
37
69
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
PluginPreRequest,
|
|
6
6
|
Session,
|
|
7
7
|
} from '@botonic/core'
|
|
8
|
+
import { ActionRequest } from '@botonic/react'
|
|
8
9
|
import axios from 'axios'
|
|
9
10
|
|
|
10
11
|
import {
|
|
@@ -37,10 +38,16 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
37
38
|
private currentRequest: PluginPreRequest
|
|
38
39
|
private getAccessToken: (session: Session) => string
|
|
39
40
|
public getLocale: (session: Session) => string
|
|
41
|
+
public trackEvent?: (
|
|
42
|
+
request: ActionRequest,
|
|
43
|
+
eventName: string,
|
|
44
|
+
args?: Record<string, any>
|
|
45
|
+
) => Promise<void>
|
|
40
46
|
|
|
41
47
|
constructor(readonly options: BotonicPluginFlowBuilderOptions) {
|
|
42
48
|
this.getLocale = options.getLocale
|
|
43
49
|
this.getAccessToken = resolveGetAccessToken(options)
|
|
50
|
+
this.trackEvent = options.trackEvent
|
|
44
51
|
this.flowUrl = options.flowUrl
|
|
45
52
|
if (options.flow) this.flow = options.flow
|
|
46
53
|
const customFunctions = options.customFunctions || {}
|
|
@@ -68,17 +75,23 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
68
75
|
return content
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
async
|
|
72
|
-
handoffTargetId: string | undefined
|
|
73
|
-
): Promise<HandoffNode> {
|
|
78
|
+
async getContentByCode(code: string): Promise<NodeComponent> {
|
|
74
79
|
const flow = await this.flow
|
|
75
|
-
const content = flow.nodes.find(
|
|
76
|
-
node
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
const content = flow.nodes.find(node => {
|
|
81
|
+
if ('code' in node) return node.code === code
|
|
82
|
+
return undefined
|
|
83
|
+
})
|
|
84
|
+
if (!content) throw Error(`Node with code: '${code}' not found`)
|
|
79
85
|
return content
|
|
80
86
|
}
|
|
81
87
|
|
|
88
|
+
async getHandoffContent(
|
|
89
|
+
handoffTargetId: string | undefined
|
|
90
|
+
): Promise<HandoffNode | undefined> {
|
|
91
|
+
if (!handoffTargetId) return undefined
|
|
92
|
+
return (await this.getContent(handoffTargetId)) as HandoffNode
|
|
93
|
+
}
|
|
94
|
+
|
|
82
95
|
getFlowContent(
|
|
83
96
|
hubtypeContent: NodeComponent,
|
|
84
97
|
locale: string
|
|
@@ -128,18 +141,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
128
141
|
// TODO: Create function to populate these buttons
|
|
129
142
|
await updateButtonUrls(hubtypeContent, 'elements', this.getContent)
|
|
130
143
|
await updateButtonUrls(hubtypeContent, 'buttons', this.getContent)
|
|
131
|
-
const content =
|
|
144
|
+
const content = this.getFlowContent(hubtypeContent, locale)
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
content.buttons.forEach(async button => {
|
|
135
|
-
if (button.payload) {
|
|
136
|
-
const contentButton = await this.getContent(button.payload)
|
|
137
|
-
if (contentButton?.type === NodeType.PAYLOAD) {
|
|
138
|
-
button.payload = contentButton.content.payload
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
}
|
|
146
|
+
this.replaceButtonPayload(content)
|
|
143
147
|
|
|
144
148
|
if (hubtypeContent.type === NodeType.FUNCTION) {
|
|
145
149
|
const targetId = await this.callFunction(hubtypeContent, locale)
|
|
@@ -156,6 +160,19 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
156
160
|
return { contents, handoffNode: isHandoff && hubtypeContent }
|
|
157
161
|
}
|
|
158
162
|
|
|
163
|
+
private async replaceButtonPayload(content: FlowContent | undefined) {
|
|
164
|
+
if (content && 'buttons' in content) {
|
|
165
|
+
for (const button of content.buttons) {
|
|
166
|
+
if (button.payload) {
|
|
167
|
+
const contentButton = await this.getContent(button.payload)
|
|
168
|
+
if (contentButton?.type === NodeType.PAYLOAD) {
|
|
169
|
+
button.payload = contentButton.content.payload
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
159
176
|
async getPayloadByIntent(
|
|
160
177
|
input: Input,
|
|
161
178
|
locale: string
|
|
@@ -249,7 +266,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
249
266
|
|
|
250
267
|
const args = Object.assign(
|
|
251
268
|
{
|
|
252
|
-
|
|
269
|
+
request: this.currentRequest,
|
|
253
270
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
254
271
|
},
|
|
255
272
|
...nameValues
|
|
@@ -270,4 +287,4 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
270
287
|
}
|
|
271
288
|
}
|
|
272
289
|
|
|
273
|
-
export
|
|
290
|
+
export * from './action'
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Session } from '@botonic/core'
|
|
2
|
+
import { ActionRequest } from '@botonic/react'
|
|
2
3
|
|
|
3
4
|
import { FlowBuilderData } from './flow-builder-models'
|
|
4
5
|
|
|
@@ -8,6 +9,11 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
8
9
|
customFunctions?: Record<any, any>
|
|
9
10
|
getLocale: (session: Session) => string
|
|
10
11
|
getAccessToken: () => string
|
|
12
|
+
trackEvent?: (
|
|
13
|
+
request: ActionRequest,
|
|
14
|
+
eventName: string,
|
|
15
|
+
args?: Record<string, any>
|
|
16
|
+
) => Promise<void>
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
export enum ProcessEnvNodeEnvs {
|