@botonic/plugin-flow-builder 0.22.0-alpha.1 → 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/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 -1
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/handoff.js +8 -3
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/index.d.ts +5 -1
- package/lib/cjs/index.js +28 -15
- 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/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 -1
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/handoff.js +8 -3
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/index.d.ts +5 -1
- package/lib/esm/index.js +28 -13
- 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/functions/conditional-provider.ts +2 -2
- package/src/functions/conditional-queue-status.ts +24 -3
- package/src/handoff.ts +15 -5
- package/src/index.ts +34 -13
- 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,CAAA;QAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC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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 {};
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.conditionalQueueStatus = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const helpers_1 = require("../helpers");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
7
8
|
const _HUBTYPE_API_URL_ = (0, utils_1.getWebpackEnvVar)(
|
|
8
9
|
// @ts-ignore
|
|
9
10
|
typeof HUBTYPE_API_URL !== 'undefined' && HUBTYPE_API_URL, 'HUBTYPE_API_URL', 'https://api.hubtype.com');
|
|
10
|
-
async function conditionalQueueStatus({ queue_id, }) {
|
|
11
|
+
async function conditionalQueueStatus({ request, queue_id, queue_name, }) {
|
|
11
12
|
const response = await axios_1.default.get(`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
|
|
12
13
|
// TODO: Make it configurable in the future
|
|
13
14
|
{
|
|
@@ -18,6 +19,17 @@ async function conditionalQueueStatus({ queue_id, }) {
|
|
|
18
19
|
},
|
|
19
20
|
});
|
|
20
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
|
+
}
|
|
21
33
|
return isAvailable ? 'open' : 'closed';
|
|
22
34
|
}
|
|
23
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,13 +4,14 @@ 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
|
+
const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
|
|
7
8
|
// @ts-ignore
|
|
8
9
|
const handOffBuilder = new core_1.HandOffBuilder(request.session);
|
|
9
10
|
const handoffQueues = handoffNode.content.queue;
|
|
10
11
|
const queueFound = handoffQueues.find(q => q.locale === locale);
|
|
11
12
|
if (queueFound)
|
|
12
13
|
handOffBuilder.withQueue(queueFound.id);
|
|
13
|
-
const onFinishPayload = await getOnFinishPayload(handoffNode, locale
|
|
14
|
+
const onFinishPayload = await getOnFinishPayload(flowBuilderPlugin, handoffNode, locale);
|
|
14
15
|
if (onFinishPayload)
|
|
15
16
|
handOffBuilder.withOnFinishPayload(onFinishPayload);
|
|
16
17
|
// TODO: Retrieve params from FlowBuilder
|
|
@@ -25,11 +26,15 @@ async function doHandoff(request, locale, handoffNode) {
|
|
|
25
26
|
// handOffBuilder.withAgentEmail(handoffParams.agentEmail)
|
|
26
27
|
// }
|
|
27
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
|
+
}
|
|
28
34
|
}
|
|
29
35
|
exports.doHandoff = doHandoff;
|
|
30
|
-
async function getOnFinishPayload(handoffNode, locale
|
|
36
|
+
async function getOnFinishPayload(flowBuilderPlugin, handoffNode, locale) {
|
|
31
37
|
var _a, _b;
|
|
32
|
-
const flowBuilderPlugin = (0, helpers_1.getFlowBuilderPlugin)(request.plugins);
|
|
33
38
|
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
34
39
|
if (handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id)
|
|
35
40
|
return handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id;
|
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,CAA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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,11 +11,13 @@ 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>;
|
|
20
|
+
getContentByCode(code: string): Promise<NodeComponent>;
|
|
18
21
|
getHandoffContent(handoffTargetId: string | undefined): Promise<HandoffNode | undefined>;
|
|
19
22
|
getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
|
|
20
23
|
getStartId(): 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,6 +37,17 @@ class BotonicPluginFlowBuilder {
|
|
|
37
37
|
throw Error(`Node with id: '${id}' not found`);
|
|
38
38
|
return content;
|
|
39
39
|
}
|
|
40
|
+
async getContentByCode(code) {
|
|
41
|
+
const flow = await this.flow;
|
|
42
|
+
const content = flow.nodes.find(node => {
|
|
43
|
+
if ('code' in node)
|
|
44
|
+
return node.code === code;
|
|
45
|
+
return undefined;
|
|
46
|
+
});
|
|
47
|
+
if (!content)
|
|
48
|
+
throw Error(`Node with code: '${code}' not found`);
|
|
49
|
+
return content;
|
|
50
|
+
}
|
|
40
51
|
async getHandoffContent(handoffTargetId) {
|
|
41
52
|
if (!handoffTargetId)
|
|
42
53
|
return undefined;
|
|
@@ -81,17 +92,8 @@ class BotonicPluginFlowBuilder {
|
|
|
81
92
|
// TODO: Create function to populate these buttons
|
|
82
93
|
await (0, helpers_1.updateButtonUrls)(hubtypeContent, 'elements', this.getContent);
|
|
83
94
|
await (0, helpers_1.updateButtonUrls)(hubtypeContent, 'buttons', this.getContent);
|
|
84
|
-
const content =
|
|
85
|
-
|
|
86
|
-
content.buttons.forEach(async (button) => {
|
|
87
|
-
if (button.payload) {
|
|
88
|
-
const contentButton = await this.getContent(button.payload);
|
|
89
|
-
if ((contentButton === null || contentButton === void 0 ? void 0 : contentButton.type) === flow_builder_models_1.NodeType.PAYLOAD) {
|
|
90
|
-
button.payload = contentButton.content.payload;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
+
const content = this.getFlowContent(hubtypeContent, locale);
|
|
96
|
+
this.replaceButtonPayload(content);
|
|
95
97
|
if (hubtypeContent.type === flow_builder_models_1.NodeType.FUNCTION) {
|
|
96
98
|
const targetId = await this.callFunction(hubtypeContent, locale);
|
|
97
99
|
return this.getContents(targetId, locale, contents);
|
|
@@ -107,6 +109,18 @@ class BotonicPluginFlowBuilder {
|
|
|
107
109
|
// return this.getContents(function result_mapping target, locale, contents)
|
|
108
110
|
return { contents, handoffNode: isHandoff && hubtypeContent };
|
|
109
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
|
+
}
|
|
110
124
|
async getPayloadByIntent(input, locale) {
|
|
111
125
|
var _a;
|
|
112
126
|
try {
|
|
@@ -169,7 +183,7 @@ class BotonicPluginFlowBuilder {
|
|
|
169
183
|
const nameValues = ((_a = functionNode.content.arguments
|
|
170
184
|
.find(arg => arg.locale === locale)) === null || _a === void 0 ? void 0 : _a.values.map(value => ({ [value.name]: value.value }))) || [];
|
|
171
185
|
const args = Object.assign({
|
|
172
|
-
|
|
186
|
+
request: this.currentRequest,
|
|
173
187
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
174
188
|
}, ...nameValues);
|
|
175
189
|
const functionResult = await this.functions[functionNode.content.action](args);
|
|
@@ -182,6 +196,5 @@ class BotonicPluginFlowBuilder {
|
|
|
182
196
|
}
|
|
183
197
|
}
|
|
184
198
|
exports.default = BotonicPluginFlowBuilder;
|
|
185
|
-
|
|
186
|
-
Object.defineProperty(exports, "FlowBuilderAction", { enumerable: true, get: function () { return action_1.FlowBuilderAction; } });
|
|
199
|
+
tslib_1.__exportStar(require("./action"), exports);
|
|
187
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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Ed,MAAM,cAAc,GAAG,YAAY,CAAC,EAAE,CAAA;QACtC,MAAM,UAAU,GACd,CAAA,MAAA,YAAY,CAAC,OAAO,CAAC,SAAS;aAC3B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,0CACjC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,KAAI,EAAE,CAAA;QAEhE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CACxB;YACE,OAAO,EAAE,IAAI,CAAC,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,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAG5E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAsB;QAC7C,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3D,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;QACrC,IAAI,eAAe,GAAuB,OAAO,CAAA;QACjD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,oBAAoB,EAAE;YACpD,eAAe,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,CAAA;SACvD;QACD,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,kBAAkB,CAC9D,OAAO,CAAC,KAAK,EACb,MAAM,CACP,CAAA;YACD,IAAI,aAAa;gBAAE,eAAe,GAAG,aAAa,CAAA;YAClD,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,CAChE,OAAO,CAAC,KAAK,EACb,MAAM,CACP,CAAA;YACD,IAAI,cAAc;gBAAE,eAAe,GAAG,cAAc,CAAA;SACrD;QACD,IAAI,CA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({ 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,9 +1,10 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { getFlowBuilderPlugin } from '../helpers';
|
|
2
3
|
import { getWebpackEnvVar } from '../utils';
|
|
3
4
|
const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
4
5
|
// @ts-ignore
|
|
5
6
|
typeof HUBTYPE_API_URL !== 'undefined' && HUBTYPE_API_URL, 'HUBTYPE_API_URL', 'https://api.hubtype.com');
|
|
6
|
-
export async function conditionalQueueStatus({ queue_id, }) {
|
|
7
|
+
export async function conditionalQueueStatus({ request, queue_id, queue_name, }) {
|
|
7
8
|
const response = await axios.get(`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
|
|
8
9
|
// TODO: Make it configurable in the future
|
|
9
10
|
{
|
|
@@ -14,6 +15,17 @@ export async function conditionalQueueStatus({ queue_id, }) {
|
|
|
14
15
|
},
|
|
15
16
|
});
|
|
16
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
|
+
}
|
|
17
29
|
return isAvailable ? 'open' : 'closed';
|
|
18
30
|
}
|
|
19
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,13 +1,14 @@
|
|
|
1
1
|
import { HandOffBuilder } from '@botonic/core';
|
|
2
2
|
import { getFlowBuilderPlugin } from './helpers';
|
|
3
3
|
export async function doHandoff(request, locale, handoffNode) {
|
|
4
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
4
5
|
// @ts-ignore
|
|
5
6
|
const handOffBuilder = new HandOffBuilder(request.session);
|
|
6
7
|
const handoffQueues = handoffNode.content.queue;
|
|
7
8
|
const queueFound = handoffQueues.find(q => q.locale === locale);
|
|
8
9
|
if (queueFound)
|
|
9
10
|
handOffBuilder.withQueue(queueFound.id);
|
|
10
|
-
const onFinishPayload = await getOnFinishPayload(handoffNode, locale
|
|
11
|
+
const onFinishPayload = await getOnFinishPayload(flowBuilderPlugin, handoffNode, locale);
|
|
11
12
|
if (onFinishPayload)
|
|
12
13
|
handOffBuilder.withOnFinishPayload(onFinishPayload);
|
|
13
14
|
// TODO: Retrieve params from FlowBuilder
|
|
@@ -22,10 +23,14 @@ export async function doHandoff(request, locale, handoffNode) {
|
|
|
22
23
|
// handOffBuilder.withAgentEmail(handoffParams.agentEmail)
|
|
23
24
|
// }
|
|
24
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
|
+
}
|
|
25
31
|
}
|
|
26
|
-
async function getOnFinishPayload(handoffNode, locale
|
|
32
|
+
async function getOnFinishPayload(flowBuilderPlugin, handoffNode, locale) {
|
|
27
33
|
var _a, _b;
|
|
28
|
-
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
29
34
|
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
30
35
|
if (handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id)
|
|
31
36
|
return handoffTargetNode === null || handoffTargetNode === void 0 ? void 0 : handoffTargetNode.id;
|
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,EAAE,MAAM,eAAe,CAA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AE,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,11 +11,13 @@ 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>;
|
|
20
|
+
getContentByCode(code: string): Promise<NodeComponent>;
|
|
18
21
|
getHandoffContent(handoffTargetId: string | undefined): Promise<HandoffNode | undefined>;
|
|
19
22
|
getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
|
|
20
23
|
getStartId(): 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,6 +34,17 @@ export default class BotonicPluginFlowBuilder {
|
|
|
33
34
|
throw Error(`Node with id: '${id}' not found`);
|
|
34
35
|
return content;
|
|
35
36
|
}
|
|
37
|
+
async getContentByCode(code) {
|
|
38
|
+
const flow = await this.flow;
|
|
39
|
+
const content = flow.nodes.find(node => {
|
|
40
|
+
if ('code' in node)
|
|
41
|
+
return node.code === code;
|
|
42
|
+
return undefined;
|
|
43
|
+
});
|
|
44
|
+
if (!content)
|
|
45
|
+
throw Error(`Node with code: '${code}' not found`);
|
|
46
|
+
return content;
|
|
47
|
+
}
|
|
36
48
|
async getHandoffContent(handoffTargetId) {
|
|
37
49
|
if (!handoffTargetId)
|
|
38
50
|
return undefined;
|
|
@@ -77,17 +89,8 @@ export default class BotonicPluginFlowBuilder {
|
|
|
77
89
|
// TODO: Create function to populate these buttons
|
|
78
90
|
await updateButtonUrls(hubtypeContent, 'elements', this.getContent);
|
|
79
91
|
await updateButtonUrls(hubtypeContent, 'buttons', this.getContent);
|
|
80
|
-
const content =
|
|
81
|
-
|
|
82
|
-
content.buttons.forEach(async (button) => {
|
|
83
|
-
if (button.payload) {
|
|
84
|
-
const contentButton = await this.getContent(button.payload);
|
|
85
|
-
if ((contentButton === null || contentButton === void 0 ? void 0 : contentButton.type) === NodeType.PAYLOAD) {
|
|
86
|
-
button.payload = contentButton.content.payload;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
92
|
+
const content = this.getFlowContent(hubtypeContent, locale);
|
|
93
|
+
this.replaceButtonPayload(content);
|
|
91
94
|
if (hubtypeContent.type === NodeType.FUNCTION) {
|
|
92
95
|
const targetId = await this.callFunction(hubtypeContent, locale);
|
|
93
96
|
return this.getContents(targetId, locale, contents);
|
|
@@ -103,6 +106,18 @@ export default class BotonicPluginFlowBuilder {
|
|
|
103
106
|
// return this.getContents(function result_mapping target, locale, contents)
|
|
104
107
|
return { contents, handoffNode: isHandoff && hubtypeContent };
|
|
105
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
|
+
}
|
|
106
121
|
async getPayloadByIntent(input, locale) {
|
|
107
122
|
var _a;
|
|
108
123
|
try {
|
|
@@ -165,7 +180,7 @@ export default class BotonicPluginFlowBuilder {
|
|
|
165
180
|
const nameValues = ((_a = functionNode.content.arguments
|
|
166
181
|
.find(arg => arg.locale === locale)) === null || _a === void 0 ? void 0 : _a.values.map(value => ({ [value.name]: value.value }))) || [];
|
|
167
182
|
const args = Object.assign({
|
|
168
|
-
|
|
183
|
+
request: this.currentRequest,
|
|
169
184
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
170
185
|
}, ...nameValues);
|
|
171
186
|
const functionResult = await this.functions[functionNode.content.action](args);
|
|
@@ -177,5 +192,5 @@ export default class BotonicPluginFlowBuilder {
|
|
|
177
192
|
return result.target.id;
|
|
178
193
|
}
|
|
179
194
|
}
|
|
180
|
-
export
|
|
195
|
+
export * from './action';
|
|
181
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.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EACL,YAAY,EAEZ,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAQL,QAAQ,GAET,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,O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C,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,5 +1,7 @@
|
|
|
1
|
+
import { ActionRequest } from '@botonic/react'
|
|
1
2
|
import axios from 'axios'
|
|
2
3
|
|
|
4
|
+
import { getFlowBuilderPlugin } from '../helpers'
|
|
3
5
|
import { getWebpackEnvVar } from '../utils'
|
|
4
6
|
|
|
5
7
|
const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
@@ -9,11 +11,17 @@ const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
|
9
11
|
'https://api.hubtype.com'
|
|
10
12
|
)
|
|
11
13
|
|
|
14
|
+
type ConditionalQueueStatusArgs = {
|
|
15
|
+
request: ActionRequest
|
|
16
|
+
queue_id: string
|
|
17
|
+
queue_name: string
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
export async function conditionalQueueStatus({
|
|
21
|
+
request,
|
|
13
22
|
queue_id,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}): Promise<string> {
|
|
23
|
+
queue_name,
|
|
24
|
+
}: ConditionalQueueStatusArgs): Promise<string> {
|
|
17
25
|
const response = await axios.get(
|
|
18
26
|
`${_HUBTYPE_API_URL_}/v1/queues/${queue_id}/availability/`,
|
|
19
27
|
// TODO: Make it configurable in the future
|
|
@@ -26,5 +34,18 @@ export async function conditionalQueueStatus({
|
|
|
26
34
|
}
|
|
27
35
|
)
|
|
28
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
|
+
|
|
29
50
|
return isAvailable ? 'open' : 'closed'
|
|
30
51
|
}
|
package/src/handoff.ts
CHANGED
|
@@ -3,19 +3,25 @@ import { ActionRequest } from '@botonic/react'
|
|
|
3
3
|
|
|
4
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,
|
|
9
10
|
locale: string,
|
|
10
11
|
handoffNode: HandoffNode
|
|
11
12
|
): Promise<void> {
|
|
13
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
12
14
|
// @ts-ignore
|
|
13
15
|
const handOffBuilder = new HandOffBuilder(request.session)
|
|
14
16
|
const handoffQueues = handoffNode.content.queue
|
|
15
17
|
const queueFound = handoffQueues.find(q => q.locale === locale)
|
|
16
18
|
if (queueFound) handOffBuilder.withQueue(queueFound.id)
|
|
17
19
|
|
|
18
|
-
const onFinishPayload = await getOnFinishPayload(
|
|
20
|
+
const onFinishPayload = await getOnFinishPayload(
|
|
21
|
+
flowBuilderPlugin,
|
|
22
|
+
handoffNode,
|
|
23
|
+
locale
|
|
24
|
+
)
|
|
19
25
|
if (onFinishPayload) handOffBuilder.withOnFinishPayload(onFinishPayload)
|
|
20
26
|
|
|
21
27
|
// TODO: Retrieve params from FlowBuilder
|
|
@@ -33,15 +39,19 @@ export async function doHandoff(
|
|
|
33
39
|
// }
|
|
34
40
|
|
|
35
41
|
await handOffBuilder.handOff()
|
|
42
|
+
|
|
43
|
+
if (flowBuilderPlugin.trackEvent) {
|
|
44
|
+
await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
|
|
45
|
+
queueName: queueFound?.name,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
async function getOnFinishPayload(
|
|
51
|
+
flowBuilderPlugin: BotonicPluginFlowBuilder,
|
|
39
52
|
handoffNode: HandoffNode,
|
|
40
|
-
locale: string
|
|
41
|
-
request: ActionRequest
|
|
53
|
+
locale: string
|
|
42
54
|
): Promise<string | undefined> {
|
|
43
|
-
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
44
|
-
|
|
45
55
|
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent(
|
|
46
56
|
handoffNode.target?.id
|
|
47
57
|
)
|
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,6 +75,16 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
68
75
|
return content
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
async getContentByCode(code: string): Promise<NodeComponent> {
|
|
79
|
+
const flow = await this.flow
|
|
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`)
|
|
85
|
+
return content
|
|
86
|
+
}
|
|
87
|
+
|
|
71
88
|
async getHandoffContent(
|
|
72
89
|
handoffTargetId: string | undefined
|
|
73
90
|
): Promise<HandoffNode | undefined> {
|
|
@@ -124,18 +141,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
124
141
|
// TODO: Create function to populate these buttons
|
|
125
142
|
await updateButtonUrls(hubtypeContent, 'elements', this.getContent)
|
|
126
143
|
await updateButtonUrls(hubtypeContent, 'buttons', this.getContent)
|
|
127
|
-
const content =
|
|
144
|
+
const content = this.getFlowContent(hubtypeContent, locale)
|
|
128
145
|
|
|
129
|
-
|
|
130
|
-
content.buttons.forEach(async button => {
|
|
131
|
-
if (button.payload) {
|
|
132
|
-
const contentButton = await this.getContent(button.payload)
|
|
133
|
-
if (contentButton?.type === NodeType.PAYLOAD) {
|
|
134
|
-
button.payload = contentButton.content.payload
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
}
|
|
146
|
+
this.replaceButtonPayload(content)
|
|
139
147
|
|
|
140
148
|
if (hubtypeContent.type === NodeType.FUNCTION) {
|
|
141
149
|
const targetId = await this.callFunction(hubtypeContent, locale)
|
|
@@ -152,6 +160,19 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
152
160
|
return { contents, handoffNode: isHandoff && hubtypeContent }
|
|
153
161
|
}
|
|
154
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
|
+
|
|
155
176
|
async getPayloadByIntent(
|
|
156
177
|
input: Input,
|
|
157
178
|
locale: string
|
|
@@ -245,7 +266,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
245
266
|
|
|
246
267
|
const args = Object.assign(
|
|
247
268
|
{
|
|
248
|
-
|
|
269
|
+
request: this.currentRequest,
|
|
249
270
|
results: [functionNode.content.result_mapping.map(r => r.result)],
|
|
250
271
|
},
|
|
251
272
|
...nameValues
|
|
@@ -266,4 +287,4 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
289
|
|
|
269
|
-
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 {
|