@botonic/plugin-flow-builder 0.41.1-alpha.4 → 0.42.0-alpha.0
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/index.d.ts +1 -0
- package/lib/cjs/action/index.js +9 -3
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/api.js +1 -10
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/content-fields/content-fields-base.d.ts +5 -1
- package/lib/cjs/content-fields/content-fields-base.js.map +1 -1
- package/lib/cjs/content-fields/flow-ai-agent.d.ts +2 -2
- package/lib/cjs/content-fields/flow-ai-agent.js +23 -7
- package/lib/cjs/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/cjs/content-fields/flow-bot-action.d.ts +2 -1
- package/lib/cjs/content-fields/flow-bot-action.js +20 -1
- package/lib/cjs/content-fields/flow-bot-action.js.map +1 -1
- package/lib/cjs/content-fields/flow-button.d.ts +2 -1
- package/lib/cjs/content-fields/flow-button.js +7 -0
- package/lib/cjs/content-fields/flow-button.js.map +1 -1
- package/lib/cjs/content-fields/flow-carousel.d.ts +2 -4
- package/lib/cjs/content-fields/flow-carousel.js +8 -50
- package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
- package/lib/cjs/content-fields/flow-channel-conditional.d.ts +14 -0
- package/lib/cjs/content-fields/flow-channel-conditional.js +55 -0
- package/lib/cjs/content-fields/flow-channel-conditional.js.map +1 -0
- package/lib/cjs/content-fields/flow-country-conditional.d.ts +13 -0
- package/lib/cjs/content-fields/flow-country-conditional.js +57 -0
- package/lib/cjs/content-fields/flow-country-conditional.js.map +1 -0
- package/lib/cjs/content-fields/flow-custom-conditional.d.ts +15 -0
- package/lib/cjs/content-fields/flow-custom-conditional.js +77 -0
- package/lib/cjs/content-fields/flow-custom-conditional.js.map +1 -0
- package/lib/cjs/content-fields/flow-element.d.ts +2 -0
- package/lib/cjs/content-fields/flow-element.js +8 -1
- package/lib/cjs/content-fields/flow-element.js.map +1 -1
- package/lib/cjs/content-fields/flow-go-to-flow.d.ts +13 -0
- package/lib/cjs/content-fields/flow-go-to-flow.js +47 -0
- package/lib/cjs/content-fields/flow-go-to-flow.js.map +1 -0
- package/lib/cjs/content-fields/flow-handoff.d.ts +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +7 -0
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/flow-image.d.ts +2 -1
- package/lib/cjs/content-fields/flow-image.js +8 -1
- package/lib/cjs/content-fields/flow-image.js.map +1 -1
- package/lib/cjs/content-fields/flow-knowledge-base.d.ts +1 -1
- package/lib/cjs/content-fields/flow-knowledge-base.js +10 -1
- package/lib/cjs/content-fields/flow-knowledge-base.js.map +1 -1
- package/lib/cjs/content-fields/flow-queue-status-conditional.d.ts +30 -0
- package/lib/cjs/content-fields/flow-queue-status-conditional.js +99 -0
- package/lib/cjs/content-fields/flow-queue-status-conditional.js.map +1 -0
- package/lib/cjs/content-fields/flow-rating.d.ts +1 -1
- package/lib/cjs/content-fields/flow-rating.js +8 -1
- package/lib/cjs/content-fields/flow-rating.js.map +1 -1
- package/lib/cjs/content-fields/flow-text.d.ts +1 -3
- package/lib/cjs/content-fields/flow-text.js +7 -16
- package/lib/cjs/content-fields/flow-text.js.map +1 -1
- package/lib/cjs/content-fields/flow-video.d.ts +2 -1
- package/lib/cjs/content-fields/flow-video.js +8 -1
- package/lib/cjs/content-fields/flow-video.js.map +1 -1
- package/lib/cjs/content-fields/flow-webview.d.ts +2 -1
- package/lib/cjs/content-fields/flow-webview.js +8 -1
- package/lib/cjs/content-fields/flow-webview.js.map +1 -1
- package/lib/cjs/content-fields/flow-whatsapp-cta-url-button.d.ts +1 -1
- package/lib/cjs/content-fields/flow-whatsapp-cta-url-button.js +8 -1
- package/lib/cjs/content-fields/flow-whatsapp-cta-url-button.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/channel-conditional.d.ts +10 -0
- package/lib/cjs/content-fields/hubtype-fields/channel-conditional.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/channel-conditional.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/country-conditional.d.ts +10 -0
- package/lib/cjs/content-fields/hubtype-fields/country-conditional.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/country-conditional.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/custom-conditional.d.ts +11 -0
- package/lib/cjs/content-fields/hubtype-fields/custom-conditional.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/custom-conditional.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/go-to-flow.d.ts +4 -3
- package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +3 -3
- package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -1
- package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -2
- package/lib/cjs/content-fields/hubtype-fields/queue-status-conditional.d.ts +25 -0
- package/lib/cjs/content-fields/hubtype-fields/queue-status-conditional.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/queue-status-conditional.js.map +1 -0
- package/lib/cjs/content-fields/index.d.ts +7 -2
- package/lib/cjs/content-fields/index.js +11 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +2 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +7 -0
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +2 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +7 -0
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +8 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -1
- package/lib/cjs/flow-factory.d.ts +12 -0
- package/lib/cjs/flow-factory.js +65 -0
- package/lib/cjs/flow-factory.js.map +1 -0
- package/lib/cjs/functions/index.d.ts +11 -10
- package/lib/cjs/functions/index.js +49 -12
- package/lib/cjs/functions/index.js.map +1 -1
- package/lib/cjs/index.d.ts +0 -3
- package/lib/cjs/index.js +13 -66
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/services/hubtype-queues-api.d.ts +14 -0
- package/lib/cjs/services/hubtype-queues-api.js +28 -0
- package/lib/cjs/services/hubtype-queues-api.js.map +1 -0
- package/lib/cjs/tracking.d.ts +3 -0
- package/lib/cjs/tracking.js +29 -15
- package/lib/cjs/tracking.js.map +1 -1
- package/lib/esm/action/index.d.ts +1 -0
- package/lib/esm/action/index.js +9 -3
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/api.js +2 -11
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/content-fields/content-fields-base.d.ts +5 -1
- package/lib/esm/content-fields/content-fields-base.js.map +1 -1
- package/lib/esm/content-fields/flow-ai-agent.d.ts +2 -2
- package/lib/esm/content-fields/flow-ai-agent.js +24 -8
- package/lib/esm/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/esm/content-fields/flow-bot-action.d.ts +2 -1
- package/lib/esm/content-fields/flow-bot-action.js +21 -2
- package/lib/esm/content-fields/flow-bot-action.js.map +1 -1
- package/lib/esm/content-fields/flow-button.d.ts +2 -1
- package/lib/esm/content-fields/flow-button.js +7 -0
- package/lib/esm/content-fields/flow-button.js.map +1 -1
- package/lib/esm/content-fields/flow-carousel.d.ts +2 -4
- package/lib/esm/content-fields/flow-carousel.js +9 -51
- package/lib/esm/content-fields/flow-carousel.js.map +1 -1
- package/lib/esm/content-fields/flow-channel-conditional.d.ts +14 -0
- package/lib/esm/content-fields/flow-channel-conditional.js +51 -0
- package/lib/esm/content-fields/flow-channel-conditional.js.map +1 -0
- package/lib/esm/content-fields/flow-country-conditional.d.ts +13 -0
- package/lib/esm/content-fields/flow-country-conditional.js +53 -0
- package/lib/esm/content-fields/flow-country-conditional.js.map +1 -0
- package/lib/esm/content-fields/flow-custom-conditional.d.ts +15 -0
- package/lib/esm/content-fields/flow-custom-conditional.js +73 -0
- package/lib/esm/content-fields/flow-custom-conditional.js.map +1 -0
- package/lib/esm/content-fields/flow-element.d.ts +2 -0
- package/lib/esm/content-fields/flow-element.js +8 -1
- package/lib/esm/content-fields/flow-element.js.map +1 -1
- package/lib/esm/content-fields/flow-go-to-flow.d.ts +13 -0
- package/lib/esm/content-fields/flow-go-to-flow.js +43 -0
- package/lib/esm/content-fields/flow-go-to-flow.js.map +1 -0
- package/lib/esm/content-fields/flow-handoff.d.ts +1 -1
- package/lib/esm/content-fields/flow-handoff.js +7 -0
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/flow-image.d.ts +2 -1
- package/lib/esm/content-fields/flow-image.js +8 -1
- package/lib/esm/content-fields/flow-image.js.map +1 -1
- package/lib/esm/content-fields/flow-knowledge-base.d.ts +1 -1
- package/lib/esm/content-fields/flow-knowledge-base.js +10 -1
- package/lib/esm/content-fields/flow-knowledge-base.js.map +1 -1
- package/lib/esm/content-fields/flow-queue-status-conditional.d.ts +30 -0
- package/lib/esm/content-fields/flow-queue-status-conditional.js +95 -0
- package/lib/esm/content-fields/flow-queue-status-conditional.js.map +1 -0
- package/lib/esm/content-fields/flow-rating.d.ts +1 -1
- package/lib/esm/content-fields/flow-rating.js +8 -1
- package/lib/esm/content-fields/flow-rating.js.map +1 -1
- package/lib/esm/content-fields/flow-text.d.ts +1 -3
- package/lib/esm/content-fields/flow-text.js +9 -18
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/lib/esm/content-fields/flow-video.d.ts +2 -1
- package/lib/esm/content-fields/flow-video.js +8 -1
- package/lib/esm/content-fields/flow-video.js.map +1 -1
- package/lib/esm/content-fields/flow-webview.d.ts +2 -1
- package/lib/esm/content-fields/flow-webview.js +8 -1
- package/lib/esm/content-fields/flow-webview.js.map +1 -1
- package/lib/esm/content-fields/flow-whatsapp-cta-url-button.d.ts +1 -1
- package/lib/esm/content-fields/flow-whatsapp-cta-url-button.js +8 -1
- package/lib/esm/content-fields/flow-whatsapp-cta-url-button.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/channel-conditional.d.ts +10 -0
- package/lib/esm/content-fields/hubtype-fields/channel-conditional.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/channel-conditional.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/country-conditional.d.ts +10 -0
- package/lib/esm/content-fields/hubtype-fields/country-conditional.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/country-conditional.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/custom-conditional.d.ts +11 -0
- package/lib/esm/content-fields/hubtype-fields/custom-conditional.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/custom-conditional.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/go-to-flow.d.ts +4 -3
- package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +3 -3
- package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -1
- package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -2
- package/lib/esm/content-fields/hubtype-fields/queue-status-conditional.d.ts +25 -0
- package/lib/esm/content-fields/hubtype-fields/queue-status-conditional.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/queue-status-conditional.js.map +1 -0
- package/lib/esm/content-fields/index.d.ts +7 -2
- package/lib/esm/content-fields/index.js +6 -1
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +2 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +7 -0
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +2 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +7 -0
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +8 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -1
- package/lib/esm/flow-factory.d.ts +12 -0
- package/lib/esm/flow-factory.js +61 -0
- package/lib/esm/flow-factory.js.map +1 -0
- package/lib/esm/functions/index.d.ts +11 -10
- package/lib/esm/functions/index.js +46 -11
- package/lib/esm/functions/index.js.map +1 -1
- package/lib/esm/index.d.ts +0 -3
- package/lib/esm/index.js +14 -67
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/services/hubtype-queues-api.d.ts +14 -0
- package/lib/esm/services/hubtype-queues-api.js +24 -0
- package/lib/esm/services/hubtype-queues-api.js.map +1 -0
- package/lib/esm/tracking.d.ts +3 -0
- package/lib/esm/tracking.js +27 -14
- package/lib/esm/tracking.js.map +1 -1
- package/package.json +2 -2
- package/src/action/index.tsx +11 -3
- package/src/api.ts +3 -11
- package/src/content-fields/content-fields-base.ts +8 -0
- package/src/content-fields/flow-ai-agent.tsx +41 -8
- package/src/content-fields/flow-bot-action.tsx +22 -2
- package/src/content-fields/flow-button.tsx +6 -1
- package/src/content-fields/flow-carousel.tsx +7 -109
- package/src/content-fields/flow-channel-conditional.tsx +65 -0
- package/src/content-fields/flow-country-conditional.tsx +67 -0
- package/src/content-fields/flow-custom-conditional.tsx +98 -0
- package/src/content-fields/flow-element.tsx +7 -2
- package/src/content-fields/flow-go-to-flow.tsx +51 -0
- package/src/content-fields/flow-handoff.tsx +7 -1
- package/src/content-fields/flow-image.tsx +8 -2
- package/src/content-fields/flow-knowledge-base.tsx +9 -1
- package/src/content-fields/flow-queue-status-conditional.tsx +130 -0
- package/src/content-fields/flow-rating.tsx +6 -1
- package/src/content-fields/flow-text.tsx +6 -32
- package/src/content-fields/flow-video.tsx +8 -2
- package/src/content-fields/flow-webview.tsx +9 -1
- package/src/content-fields/flow-whatsapp-cta-url-button.tsx +7 -1
- package/src/content-fields/hubtype-fields/channel-conditional.ts +11 -0
- package/src/content-fields/hubtype-fields/country-conditional.ts +11 -0
- package/src/content-fields/hubtype-fields/custom-conditional.ts +12 -0
- package/src/content-fields/hubtype-fields/go-to-flow.ts +4 -3
- package/src/content-fields/hubtype-fields/node-types.ts +1 -1
- package/src/content-fields/hubtype-fields/nodes.ts +10 -1
- package/src/content-fields/hubtype-fields/queue-status-conditional.ts +53 -0
- package/src/content-fields/index.ts +15 -0
- package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.tsx +7 -1
- package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.tsx +6 -0
- package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list.tsx +7 -1
- package/src/flow-factory.ts +126 -0
- package/src/functions/index.ts +77 -11
- package/src/index.ts +24 -120
- package/src/{functions/conditional-queue-status.ts → services/hubtype-queues-api.ts} +7 -41
- package/src/tracking.ts +35 -12
- package/lib/cjs/functions/conditional-bot-variable.d.ts +0 -8
- package/lib/cjs/functions/conditional-bot-variable.js +0 -11
- package/lib/cjs/functions/conditional-bot-variable.js.map +0 -1
- package/lib/cjs/functions/conditional-country.d.ts +0 -7
- package/lib/cjs/functions/conditional-country.js +0 -9
- package/lib/cjs/functions/conditional-country.js.map +0 -1
- package/lib/cjs/functions/conditional-provider.d.ts +0 -7
- package/lib/cjs/functions/conditional-provider.js +0 -9
- package/lib/cjs/functions/conditional-provider.js.map +0 -1
- package/lib/cjs/functions/conditional-queue-status.d.ts +0 -29
- package/lib/cjs/functions/conditional-queue-status.js +0 -51
- package/lib/cjs/functions/conditional-queue-status.js.map +0 -1
- package/lib/esm/functions/conditional-bot-variable.d.ts +0 -8
- package/lib/esm/functions/conditional-bot-variable.js +0 -7
- package/lib/esm/functions/conditional-bot-variable.js.map +0 -1
- package/lib/esm/functions/conditional-country.d.ts +0 -7
- package/lib/esm/functions/conditional-country.js +0 -5
- package/lib/esm/functions/conditional-country.js.map +0 -1
- package/lib/esm/functions/conditional-provider.d.ts +0 -7
- package/lib/esm/functions/conditional-provider.js +0 -5
- package/lib/esm/functions/conditional-provider.js.map +0 -1
- package/lib/esm/functions/conditional-queue-status.d.ts +0 -29
- package/lib/esm/functions/conditional-queue-status.js +0 -45
- package/lib/esm/functions/conditional-queue-status.js.map +0 -1
- package/src/functions/conditional-bot-variable.ts +0 -18
- package/src/functions/conditional-country.ts +0 -14
- package/src/functions/conditional-provider.ts +0 -14
|
@@ -1,12 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
export const DEFAULT_FUNCTION_NAMES = [
|
|
3
|
+
'check-queue-status',
|
|
4
|
+
'get-channel-type',
|
|
5
|
+
'check-country',
|
|
6
|
+
'check-bot-variable',
|
|
7
|
+
];
|
|
8
|
+
export class CustomFunction {
|
|
9
|
+
constructor(functions, currentRequest, locale) {
|
|
10
|
+
this.functions = functions;
|
|
11
|
+
this.currentRequest = currentRequest;
|
|
12
|
+
this.locale = locale;
|
|
13
|
+
}
|
|
14
|
+
call(functionNode) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const functionNodeId = functionNode.id;
|
|
17
|
+
const functionArguments = getArgumentsByLocale(functionNode.content.arguments, this.locale);
|
|
18
|
+
const nameValues = functionArguments.map(arg => {
|
|
19
|
+
return { [arg.name]: arg.value };
|
|
20
|
+
});
|
|
21
|
+
const args = Object.assign({
|
|
22
|
+
request: this.currentRequest,
|
|
23
|
+
results: functionNode.content.result_mapping.map(r => r.result),
|
|
24
|
+
}, ...nameValues);
|
|
25
|
+
const functionResult = yield this.functions[functionNode.content.action](args);
|
|
26
|
+
// TODO define result_mapping per locale??
|
|
27
|
+
const result = functionNode.content.result_mapping.find(r => r.result === functionResult);
|
|
28
|
+
if (!(result === null || result === void 0 ? void 0 : result.target)) {
|
|
29
|
+
throw new Error(`No result found for result_mapping for node with id: ${functionNodeId}`);
|
|
30
|
+
}
|
|
31
|
+
return result.target.id;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function getArgumentsByLocale(args, locale) {
|
|
36
|
+
let resultArguments = [];
|
|
37
|
+
for (const arg of args) {
|
|
38
|
+
if ('locale' in arg && arg.locale === locale) {
|
|
39
|
+
resultArguments = [...resultArguments, ...arg.values];
|
|
40
|
+
}
|
|
41
|
+
if ('type' in arg) {
|
|
42
|
+
resultArguments = [...resultArguments, arg];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return resultArguments;
|
|
46
|
+
}
|
|
12
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";AAQA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,oBAAoB;IACpB,kBAAkB;IAClB,eAAe;IACf,oBAAoB;CACrB,CAAA;AAED,MAAM,OAAO,cAAc;IAKzB,YACE,SAA2B,EAC3B,cAA6B,EAC7B,MAAc;QAEd,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA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AAI,QAAQ,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;YAC5C,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;SACtD;QACD,IAAI,MAAM,IAAI,GAAG,EAAE;YACjB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,CAAC,CAAA;SAC5C;KACF;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -31,9 +31,6 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
31
31
|
private getContentsById;
|
|
32
32
|
getStartContents(): Promise<FlowContent[]>;
|
|
33
33
|
getContentsByNode(node: HtNodeWithContent, prevContents?: FlowContent[]): Promise<FlowContent[]>;
|
|
34
|
-
private getFlowContent;
|
|
35
|
-
private callFunction;
|
|
36
|
-
private getArgumentsByLocale;
|
|
37
34
|
getPayloadParams<T extends PayloadParamsBase>(payload: string): T;
|
|
38
35
|
getFlowName(flowId: string): string;
|
|
39
36
|
getRatingSubmittedInfo(payload: string): RatingSubmittedInfo;
|
package/lib/esm/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import { INPUT, PROVIDER, } from '@botonic/core';
|
|
|
3
3
|
import { v7 as uuidv7 } from 'uuid';
|
|
4
4
|
import { FlowBuilderApi } from './api';
|
|
5
5
|
import { EMPTY_PAYLOAD, FLOW_BUILDER_API_URL_PROD, SEPARATOR, SOURCE_INFO_SEPARATOR, } from './constants';
|
|
6
|
-
import { FlowAiAgent, FlowBotAction, FlowCarousel, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, } from './content-fields';
|
|
7
6
|
import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
|
|
8
|
-
import {
|
|
7
|
+
import { FlowFactory } from './flow-factory';
|
|
8
|
+
import { CustomFunction, DEFAULT_FUNCTION_NAMES } from './functions';
|
|
9
9
|
import { FlowBuilderJSONVersion, } from './types';
|
|
10
10
|
import { getNodeByUserInput } from './user-input';
|
|
11
11
|
import { inputHasTextData, resolveGetAccessToken } from './utils';
|
|
@@ -22,7 +22,7 @@ export default class BotonicPluginFlowBuilder {
|
|
|
22
22
|
this.getAiAgentResponse = options.getAiAgentResponse;
|
|
23
23
|
this.smartIntentsConfig = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.smartIntentsConfig), { useLatest: this.jsonVersion === FlowBuilderJSONVersion.LATEST });
|
|
24
24
|
const customFunctions = options.customFunctions || {};
|
|
25
|
-
this.functions =
|
|
25
|
+
this.functions = customFunctions;
|
|
26
26
|
this.inShadowing = {
|
|
27
27
|
allowKeywords: ((_a = options.inShadowing) === null || _a === void 0 ? void 0 : _a.allowKeywords) || false,
|
|
28
28
|
allowSmartIntents: ((_b = options.inShadowing) === null || _b === void 0 ? void 0 : _b.allowSmartIntents) || false,
|
|
@@ -113,11 +113,14 @@ export default class BotonicPluginFlowBuilder {
|
|
|
113
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
114
|
const contents = prevContents || [];
|
|
115
115
|
const resolvedLocale = this.cmsApi.getResolvedLocale();
|
|
116
|
-
if (node.type === HtNodeWithContentType.FUNCTION
|
|
117
|
-
|
|
116
|
+
if (node.type === HtNodeWithContentType.FUNCTION &&
|
|
117
|
+
!DEFAULT_FUNCTION_NAMES.includes(node.content.action)) {
|
|
118
|
+
const customFunctionResolver = new CustomFunction(this.functions, this.currentRequest, resolvedLocale);
|
|
119
|
+
const targetId = yield customFunctionResolver.call(node);
|
|
118
120
|
return this.getContentsById(targetId, contents);
|
|
119
121
|
}
|
|
120
|
-
const
|
|
122
|
+
const flowFactory = new FlowFactory(this.currentRequest, this.cmsApi, resolvedLocale);
|
|
123
|
+
const content = yield flowFactory.getFlowContent(node);
|
|
121
124
|
if (content) {
|
|
122
125
|
contents.push(content);
|
|
123
126
|
}
|
|
@@ -126,72 +129,16 @@ export default class BotonicPluginFlowBuilder {
|
|
|
126
129
|
return contents;
|
|
127
130
|
}
|
|
128
131
|
// TODO: prevent infinite recursive calls
|
|
129
|
-
if (
|
|
132
|
+
if (content && content.followUp) {
|
|
133
|
+
return this.getContentsById(content.followUp.id, contents);
|
|
134
|
+
}
|
|
135
|
+
else if (node.follow_up) {
|
|
136
|
+
console.log('FOLLOWUP FROM NODE-------> OLD SYSTEM');
|
|
130
137
|
return this.getContentsById(node.follow_up.id, contents);
|
|
131
138
|
}
|
|
132
139
|
return contents;
|
|
133
140
|
});
|
|
134
141
|
}
|
|
135
|
-
getFlowContent(hubtypeContent, locale) {
|
|
136
|
-
switch (hubtypeContent.type) {
|
|
137
|
-
case HtNodeWithContentType.TEXT:
|
|
138
|
-
return FlowText.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
139
|
-
case HtNodeWithContentType.IMAGE:
|
|
140
|
-
return FlowImage.fromHubtypeCMS(hubtypeContent, locale);
|
|
141
|
-
case HtNodeWithContentType.CAROUSEL:
|
|
142
|
-
return FlowCarousel.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
143
|
-
case HtNodeWithContentType.VIDEO:
|
|
144
|
-
return FlowVideo.fromHubtypeCMS(hubtypeContent, locale);
|
|
145
|
-
case HtNodeWithContentType.WHATSAPP_BUTTON_LIST:
|
|
146
|
-
return FlowWhatsappButtonList.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
147
|
-
case HtNodeWithContentType.WHATSAPP_CTA_URL_BUTTON:
|
|
148
|
-
return FlowWhatsappCtaUrlButtonNode.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
149
|
-
case HtNodeWithContentType.HANDOFF:
|
|
150
|
-
return FlowHandoff.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
151
|
-
case HtNodeWithContentType.KNOWLEDGE_BASE:
|
|
152
|
-
return FlowKnowledgeBase.fromHubtypeCMS(hubtypeContent);
|
|
153
|
-
case HtNodeWithContentType.AI_AGENT:
|
|
154
|
-
return FlowAiAgent.fromHubtypeCMS(hubtypeContent);
|
|
155
|
-
case HtNodeWithContentType.RATING:
|
|
156
|
-
return FlowRating.fromHubtypeCMS(hubtypeContent, locale);
|
|
157
|
-
case HtNodeWithContentType.BOT_ACTION:
|
|
158
|
-
return FlowBotAction.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
159
|
-
default:
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
callFunction(functionNode, locale) {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const functionNodeId = functionNode.id;
|
|
166
|
-
const functionArguments = this.getArgumentsByLocale(functionNode.content.arguments, locale);
|
|
167
|
-
const nameValues = functionArguments.map(arg => {
|
|
168
|
-
return { [arg.name]: arg.value };
|
|
169
|
-
});
|
|
170
|
-
const args = Object.assign({
|
|
171
|
-
request: this.currentRequest,
|
|
172
|
-
results: functionNode.content.result_mapping.map(r => r.result),
|
|
173
|
-
}, ...nameValues);
|
|
174
|
-
const functionResult = yield this.functions[functionNode.content.action](args);
|
|
175
|
-
// TODO define result_mapping per locale??
|
|
176
|
-
const result = functionNode.content.result_mapping.find(r => r.result === functionResult);
|
|
177
|
-
if (!(result === null || result === void 0 ? void 0 : result.target)) {
|
|
178
|
-
throw new Error(`No result found for result_mapping for node with id: ${functionNodeId}`);
|
|
179
|
-
}
|
|
180
|
-
return result.target.id;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
getArgumentsByLocale(args, locale) {
|
|
184
|
-
let resultArguments = [];
|
|
185
|
-
for (const arg of args) {
|
|
186
|
-
if ('locale' in arg && arg.locale === locale) {
|
|
187
|
-
resultArguments = [...resultArguments, ...arg.values];
|
|
188
|
-
}
|
|
189
|
-
if ('type' in arg) {
|
|
190
|
-
resultArguments = [...resultArguments, arg];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return resultArguments;
|
|
194
|
-
}
|
|
195
142
|
getPayloadParams(payload) {
|
|
196
143
|
const payloadParams = JSON.parse(payload.split(SEPARATOR)[1] || '{}');
|
|
197
144
|
return payloadParams;
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,KAAK,EAGL,QAAQ,GAGT,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,SAAS,EACT,qBAAqB,GACtB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,KAAK,EAGL,QAAQ,GAGT,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,SAAS,EACT,qBAAqB,GACtB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAIL,qBAAqB,GACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,EAIL,sBAAsB,GAMvB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEjE,2EAA2E;AAE3E,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAkB3C,YAAY,OAA8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AuB,CAAC,QAAQ,CAAC,CAAA;QAEhE,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAC1E,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CACpD,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CACtB,CAAA;QACD,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CACnD,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CACvB,CAAA;QAED,uCACK,YAAY,KACf,eAAe;YACf,cAAc,IACf;IACH,CAAC;CACF;AAED,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,cAAc,kBAAkB,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAGL,sBAAsB,GAGvB,MAAM,SAAS,CAAA;AAChB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AvailabilityData {
|
|
2
|
+
available: boolean;
|
|
3
|
+
waiting_cases: number;
|
|
4
|
+
availability_threshold_waiting_cases: number;
|
|
5
|
+
open: boolean;
|
|
6
|
+
name: string;
|
|
7
|
+
available_agents: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class HubtypeQueuesApi {
|
|
10
|
+
queueId: string;
|
|
11
|
+
checkAvailableAgents: boolean;
|
|
12
|
+
constructor(queueId: string, checkAvailableAgents?: boolean);
|
|
13
|
+
getAvailability(): Promise<AvailabilityData>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
4
|
+
export class HubtypeQueuesApi {
|
|
5
|
+
constructor(queueId, checkAvailableAgents) {
|
|
6
|
+
this.queueId = queueId;
|
|
7
|
+
this.checkAvailableAgents = checkAvailableAgents || false;
|
|
8
|
+
}
|
|
9
|
+
getAvailability() {
|
|
10
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const response = yield axios.get(`${HUBTYPE_API_URL}/external/v1/queues/${this.queueId}/availability/`,
|
|
12
|
+
// TODO: Make it configurable in the future
|
|
13
|
+
{
|
|
14
|
+
params: {
|
|
15
|
+
check_queue_schedule: true,
|
|
16
|
+
check_waiting_cases: false,
|
|
17
|
+
check_available_agents: this.checkAvailableAgents,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
return response.data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=hubtype-queues-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hubtype-queues-api.js","sourceRoot":"","sources":["../../../src/services/hubtype-queues-api.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAUhF,MAAM,OAAO,gBAAgB;IAI3B,YAAY,OAAe,EAAE,oBAA8B;QACzD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,IAAI,KAAK,CAAA;IAC3D,CAAC;IAEK,eAAe;;YACnB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,eAAe,uBAAuB,IAAI,CAAC,OAAO,gBAAgB;YACrE,2CAA2C;YAC3C;gBACE,MAAM,EAAE;oBACN,oBAAoB,EAAE,IAAI;oBAC1B,mBAAmB,EAAE,KAAK;oBAC1B,sBAAsB,EAAE,IAAI,CAAC,oBAAoB;iBAClD;aACF,CACF,CAAA;YACD,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;KAAA;CACF"}
|
package/lib/esm/tracking.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { EventAction } from '@botonic/core';
|
|
2
2
|
import { ActionRequest } from '@botonic/react';
|
|
3
|
+
import { FlowBuilderApi } from './api';
|
|
3
4
|
import { FlowContent } from './content-fields';
|
|
4
5
|
export declare function trackEvent(request: ActionRequest, eventAction: EventAction, args?: Record<string, any>): Promise<void>;
|
|
5
6
|
export declare function trackFlowContent(request: ActionRequest, contents: FlowContent[]): Promise<void>;
|
|
7
|
+
export declare function trackOneContent(request: ActionRequest, content: FlowContent, cmsApi?: FlowBuilderApi): Promise<void>;
|
|
6
8
|
type CommonFlowContentEventArgs = {
|
|
9
|
+
flowThreadId: string;
|
|
7
10
|
flowId: string;
|
|
8
11
|
flowName: string;
|
|
9
12
|
flowNodeId: string;
|
package/lib/esm/tracking.js
CHANGED
|
@@ -17,21 +17,32 @@ export function trackFlowContent(request, contents) {
|
|
|
17
17
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
18
18
|
const cmsApi = flowBuilderPlugin.cmsApi;
|
|
19
19
|
for (const content of contents) {
|
|
20
|
-
|
|
21
|
-
if (nodeContent.type !== HtNodeWithContentType.KNOWLEDGE_BASE &&
|
|
22
|
-
nodeContent.type !== HtNodeWithContentType.AI_AGENT) {
|
|
23
|
-
const event = getContentEventArgs(request, nodeContent);
|
|
24
|
-
const { action } = event, eventArgs = __rest(event, ["action"]);
|
|
25
|
-
yield trackEvent(request, action, eventArgs);
|
|
26
|
-
}
|
|
20
|
+
yield trackOneContent(request, content, cmsApi);
|
|
27
21
|
}
|
|
28
22
|
});
|
|
29
23
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
export function trackOneContent(request, content, cmsApi) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!cmsApi) {
|
|
27
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
28
|
+
cmsApi = flowBuilderPlugin.cmsApi;
|
|
29
|
+
}
|
|
30
|
+
const nodeContent = cmsApi.getNodeById(content.id);
|
|
31
|
+
if (nodeContent.type !== HtNodeWithContentType.KNOWLEDGE_BASE &&
|
|
32
|
+
nodeContent.type !== HtNodeWithContentType.AI_AGENT) {
|
|
33
|
+
const event = getContentEventArgs(request, nodeContent);
|
|
34
|
+
const { action } = event, eventArgs = __rest(event, ["action"]);
|
|
35
|
+
yield trackEvent(request, action, eventArgs);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function setSessionFlowThreadId(request, flowThreadId) {
|
|
34
40
|
request.session.flow_thread_id = flowThreadId;
|
|
41
|
+
}
|
|
42
|
+
function getContentEventArgs(request, nodeContent) {
|
|
43
|
+
var _a;
|
|
44
|
+
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgs(request, nodeContent);
|
|
45
|
+
setSessionFlowThreadId(request, flowThreadId);
|
|
35
46
|
return {
|
|
36
47
|
action: EventAction.FlowNode,
|
|
37
48
|
flowId,
|
|
@@ -39,18 +50,20 @@ function getContentEventArgs(request, nodeContent) {
|
|
|
39
50
|
flowNodeId,
|
|
40
51
|
flowNodeContentId,
|
|
41
52
|
flowThreadId,
|
|
42
|
-
flowNodeIsMeaningful: (
|
|
53
|
+
flowNodeIsMeaningful: (_a = nodeContent.is_meaningful) !== null && _a !== void 0 ? _a : false,
|
|
43
54
|
};
|
|
44
55
|
}
|
|
45
56
|
function getCommonFlowContentEventArgs(request, nodeContent) {
|
|
46
|
-
var _a;
|
|
57
|
+
var _a, _b;
|
|
47
58
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
48
59
|
const flowName = flowBuilderPlugin.getFlowName(nodeContent.flow_id);
|
|
60
|
+
const flowThreadId = (_a = request.session.flow_thread_id) !== null && _a !== void 0 ? _a : uuidv7();
|
|
49
61
|
return {
|
|
62
|
+
flowThreadId,
|
|
50
63
|
flowId: nodeContent.flow_id,
|
|
51
64
|
flowName,
|
|
52
65
|
flowNodeId: nodeContent.id,
|
|
53
|
-
flowNodeContentId: (
|
|
66
|
+
flowNodeContentId: (_b = nodeContent.code) !== null && _b !== void 0 ? _b : '',
|
|
54
67
|
};
|
|
55
68
|
}
|
|
56
69
|
export function getCommonFlowContentEventArgsForContentId(request, contentId) {
|
package/lib/esm/tracking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,eAAe,CAAA;AAEtD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,eAAe,CAAA;AAEtD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAInC,OAAO,EAEL,qBAAqB,GACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,UAAgB,UAAU,CAC9B,OAAsB,EACtB,WAAwB,EACxB,IAA0B;;QAE1B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;YAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;SAC/D;QACD,OAAM;IACR,CAAC;CAAA;AAED,MAAM,UAAgB,gBAAgB,CACpC,OAAsB,EACtB,QAAuB;;QAEvB,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,MA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C5B,MAAM;QACN,QAAQ;QACR,UAAU;QACV,iBAAiB;QACjB,YAAY;QACZ,oBAAoB,EAAE,MAAA,WAAW,CAAC,aAAa,mCAAI,KAAK;KACzD,CAAA;AACH,CAAC;AAUD,SAAS,6BAA6B,CACpC,OAAsB,EACtB,WAA8B;;IAE9B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IACnE,MAAM,YAAY,GAAG,MAAA,OAAO,CAAC,OAAO,CAAC,cAAc,mCAAI,MAAM,EAAE,CAAA;IAE/D,OAAO;QACL,YAAY;QACZ,MAAM,EAAE,WAAW,CAAC,OAAO;QAC3B,QAAQ;QACR,UAAU,EAAE,WAAW,CAAC,EAAE;QAC1B,iBAAiB,EAAE,MAAA,WAAW,CAAC,IAAI,mCAAI,EAAE;KAC1C,CAAA;AACH,CAAC;AAED,MAAM,UAAU,yCAAyC,CACvD,OAAsB,EACtB,SAAiB;IAEjB,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAA;IACvC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAoB,SAAS,CAAC,CAAA;IAEpE,OAAO,6BAA6B,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;AAC5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0-alpha.0",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@botonic/react": "0.
|
|
17
|
+
"@botonic/react": "0.42.0-alpha.0",
|
|
18
18
|
"axios": "^1.12.2",
|
|
19
19
|
"uuid": "^10.0.0"
|
|
20
20
|
},
|
package/src/action/index.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import { FlowBotAction } from '../content-fields/flow-bot-action'
|
|
|
15
15
|
import { ContentFilterExecutor } from '../filters'
|
|
16
16
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
17
17
|
import BotonicPluginFlowBuilder from '../index'
|
|
18
|
-
import { trackFlowContent } from '../tracking'
|
|
19
18
|
import { inputHasTextData } from '../utils'
|
|
20
19
|
import { getContentsByAiAgent } from './ai-agent'
|
|
21
20
|
import { getContentsByFallback } from './fallback'
|
|
@@ -38,7 +37,7 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
38
37
|
const context = getContext(request)
|
|
39
38
|
const contents = await getContentsByFirstInteraction(context)
|
|
40
39
|
const filteredContents = await filterContents(request, contents)
|
|
41
|
-
await
|
|
40
|
+
await FlowBuilderAction.trackAllContents(request, filteredContents)
|
|
42
41
|
await FlowBuilderAction.doHandoffAndBotActions(request, filteredContents)
|
|
43
42
|
|
|
44
43
|
return { contents: filteredContents }
|
|
@@ -50,12 +49,21 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
50
49
|
): Promise<FlowBuilderActionProps> {
|
|
51
50
|
const contents = await getContents(request, contentID)
|
|
52
51
|
const filteredContents = await filterContents(request, contents)
|
|
53
|
-
await
|
|
52
|
+
await FlowBuilderAction.trackAllContents(request, filteredContents)
|
|
54
53
|
await FlowBuilderAction.doHandoffAndBotActions(request, filteredContents)
|
|
55
54
|
|
|
56
55
|
return { contents: filteredContents }
|
|
57
56
|
}
|
|
58
57
|
|
|
58
|
+
static async trackAllContents(
|
|
59
|
+
request: ActionRequest,
|
|
60
|
+
contents: FlowContent[]
|
|
61
|
+
) {
|
|
62
|
+
for (const content of contents) {
|
|
63
|
+
await content.trackFlow(request)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
59
67
|
static async doHandoffAndBotActions(
|
|
60
68
|
request: ActionRequest,
|
|
61
69
|
contents: FlowContent[]
|
package/src/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginPreRequest } from '@botonic/core'
|
|
2
2
|
import axios from 'axios'
|
|
3
3
|
|
|
4
4
|
import {
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
HtNodeLink,
|
|
19
19
|
HtNodeWithContent,
|
|
20
20
|
HtNodeWithContentType,
|
|
21
|
-
HtNodeWithoutContentType,
|
|
22
21
|
HtPayloadNode,
|
|
23
22
|
HtRatingButton,
|
|
24
23
|
HtRatingNode,
|
|
@@ -77,9 +76,7 @@ export class FlowBuilderApi {
|
|
|
77
76
|
getNodeById<T extends HtNodeComponent>(id: string): T {
|
|
78
77
|
const node = this.flow.nodes.find(node => node.id === id)
|
|
79
78
|
if (!node) console.error(`Node with id: '${id}' not found`)
|
|
80
|
-
|
|
81
|
-
return this.getNodeByFlowId(node.content.flow_id) as T
|
|
82
|
-
}
|
|
79
|
+
|
|
83
80
|
return node as T
|
|
84
81
|
}
|
|
85
82
|
|
|
@@ -213,12 +210,7 @@ export class FlowBuilderApi {
|
|
|
213
210
|
? this.getNodeById<HtNodeWithContent | HtGoToFlow>(id)
|
|
214
211
|
: undefined
|
|
215
212
|
|
|
216
|
-
|
|
217
|
-
return this.getNodeById<HtNodeWithContent>(followUpNode?.content.flow_id)
|
|
218
|
-
.code
|
|
219
|
-
} else {
|
|
220
|
-
return followUpNode?.code
|
|
221
|
-
}
|
|
213
|
+
return followUpNode?.code
|
|
222
214
|
}
|
|
223
215
|
|
|
224
216
|
getFlowName(flowId: string): string {
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { ActionRequest } from '@botonic/react'
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
HtMediaFileLocale,
|
|
5
|
+
HtNodeLink,
|
|
3
6
|
HtQueueLocale,
|
|
4
7
|
HtTextLocale,
|
|
5
8
|
HtVideoLocale,
|
|
6
9
|
} from './hubtype-fields'
|
|
7
10
|
|
|
8
11
|
export abstract class ContentFieldsBase {
|
|
12
|
+
public code: string
|
|
13
|
+
public followUp?: HtNodeLink
|
|
14
|
+
|
|
9
15
|
constructor(public readonly id: string) {}
|
|
10
16
|
|
|
17
|
+
abstract trackFlow(request: ActionRequest): Promise<void>
|
|
18
|
+
|
|
11
19
|
static getTextByLocale(locale: string, text: HtTextLocale[]): string {
|
|
12
20
|
const result = text.find(t => t.locale === locale)
|
|
13
21
|
return result?.message ?? ''
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AgenticOutputMessage } from '@botonic/core'
|
|
2
|
-
import { ActionRequest } from '@botonic/react'
|
|
2
|
+
import { ActionRequest, Button, Carousel, Text } from '@botonic/react'
|
|
3
3
|
|
|
4
|
+
import { EMPTY_PAYLOAD, SOURCE_INFO_SEPARATOR } from '../constants'
|
|
5
|
+
import { trackOneContent } from '../tracking'
|
|
4
6
|
import { ContentFieldsBase } from './content-fields-base'
|
|
5
|
-
import {
|
|
6
|
-
import { FlowText } from './flow-text'
|
|
7
|
+
import { FlowElement } from './flow-element'
|
|
7
8
|
import { HtAiAgentNode, HtInputGuardrailRule } from './hubtype-fields/ai-agent'
|
|
8
9
|
|
|
9
10
|
export class FlowAiAgent extends ContentFieldsBase {
|
|
10
|
-
public code: string = ''
|
|
11
11
|
public name: string = ''
|
|
12
12
|
public instructions: string = ''
|
|
13
13
|
public activeTools?: { name: string }[]
|
|
@@ -18,25 +18,58 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
18
18
|
|
|
19
19
|
static fromHubtypeCMS(component: HtAiAgentNode): FlowAiAgent {
|
|
20
20
|
const newAiAgent = new FlowAiAgent(component.id)
|
|
21
|
+
newAiAgent.code = component.code
|
|
21
22
|
newAiAgent.name = component.content.name
|
|
22
23
|
newAiAgent.instructions = component.content.instructions
|
|
23
24
|
newAiAgent.activeTools = component.content.active_tools
|
|
24
25
|
newAiAgent.inputGuardrailRules =
|
|
25
26
|
component.content.input_guardrail_rules || []
|
|
26
27
|
newAiAgent.sources = component.content.sources
|
|
28
|
+
newAiAgent.followUp = component.follow_up
|
|
29
|
+
|
|
27
30
|
return newAiAgent
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
async trackFlow(request: ActionRequest): Promise<void> {
|
|
34
|
+
// We can call trackFlowContent here but the function no track events for AiAgent contents
|
|
35
|
+
// Review how we can track here the knowledge base event
|
|
36
|
+
await trackOneContent(request, this)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
toBotonic(id: string): JSX.Element {
|
|
31
40
|
return (
|
|
32
41
|
<>
|
|
33
42
|
{this.responses.map((response: AgenticOutputMessage) => {
|
|
34
|
-
if (response.type === 'text'
|
|
35
|
-
return
|
|
43
|
+
if (response.type === 'text') {
|
|
44
|
+
return <Text key={id}>{response.content.text}</Text>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (response.type === 'textWithButtons') {
|
|
48
|
+
return (
|
|
49
|
+
<Text key={id}>
|
|
50
|
+
{response.content.text}
|
|
51
|
+
{response.content.buttons.map((button, buttonIndex) => {
|
|
52
|
+
return (
|
|
53
|
+
<Button
|
|
54
|
+
key={buttonIndex}
|
|
55
|
+
payload={`${EMPTY_PAYLOAD}${SOURCE_INFO_SEPARATOR}${buttonIndex}`}
|
|
56
|
+
>
|
|
57
|
+
{button.text}
|
|
58
|
+
</Button>
|
|
59
|
+
)
|
|
60
|
+
})}
|
|
61
|
+
</Text>
|
|
62
|
+
)
|
|
36
63
|
}
|
|
37
64
|
|
|
38
65
|
if (response.type === 'carousel') {
|
|
39
|
-
return
|
|
66
|
+
return (
|
|
67
|
+
<Carousel key={id}>
|
|
68
|
+
{response.content.elements.map(element =>
|
|
69
|
+
FlowElement.fromAIAgent(id, element).toBotonic(id)
|
|
70
|
+
)}
|
|
71
|
+
</Carousel>
|
|
72
|
+
)
|
|
40
73
|
}
|
|
41
74
|
|
|
42
75
|
return <></>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { BotonicAction } from '@botonic/core'
|
|
1
|
+
import { BotonicAction, EventAction, EventBotAction } from '@botonic/core'
|
|
2
2
|
import { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
5
|
+
import {
|
|
6
|
+
getCommonFlowContentEventArgsForContentId,
|
|
7
|
+
trackEvent,
|
|
8
|
+
} from '../tracking'
|
|
5
9
|
import { ContentFieldsBase } from './content-fields-base'
|
|
6
10
|
import { HtBotActionNode } from './hubtype-fields'
|
|
7
11
|
|
|
@@ -11,16 +15,32 @@ export class FlowBotAction extends ContentFieldsBase {
|
|
|
11
15
|
|
|
12
16
|
static fromHubtypeCMS(
|
|
13
17
|
cmsBotAction: HtBotActionNode,
|
|
14
|
-
_locale: string,
|
|
15
18
|
cmsApi: FlowBuilderApi
|
|
16
19
|
): FlowBotAction {
|
|
17
20
|
const newBotAction = new FlowBotAction(cmsBotAction.id)
|
|
18
21
|
newBotAction.code = cmsBotAction.code
|
|
19
22
|
newBotAction.payload = cmsApi.createPayloadWithParams(cmsBotAction)
|
|
23
|
+
newBotAction.followUp = cmsBotAction.follow_up
|
|
20
24
|
|
|
21
25
|
return newBotAction
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
async trackFlow(request: ActionRequest): Promise<void> {
|
|
29
|
+
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
30
|
+
getCommonFlowContentEventArgsForContentId(request, this.id)
|
|
31
|
+
const eventBotAction: EventBotAction = {
|
|
32
|
+
action: EventAction.BotAction,
|
|
33
|
+
flowThreadId,
|
|
34
|
+
flowId,
|
|
35
|
+
flowName,
|
|
36
|
+
flowNodeId,
|
|
37
|
+
flowNodeContentId,
|
|
38
|
+
payload: this.payload,
|
|
39
|
+
}
|
|
40
|
+
const { action, ...eventArgs } = eventBotAction
|
|
41
|
+
await trackEvent(request, action, eventArgs)
|
|
42
|
+
}
|
|
43
|
+
|
|
24
44
|
doBotAction(request: ActionRequest): void {
|
|
25
45
|
request.session._botonic_action = `${BotonicAction.Redirect}:${this.payload}`
|
|
26
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Button, Reply, Webview } from '@botonic/react'
|
|
1
|
+
import { ActionRequest, Button, Reply, Webview } from '@botonic/react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
@@ -118,6 +118,11 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
118
118
|
return FlowWebview.fromHubtypeCMS(targetNode)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
122
|
+
async trackFlow(_request: ActionRequest): Promise<void> {
|
|
123
|
+
// Not apply for these content because it is a child of another Message
|
|
124
|
+
}
|
|
125
|
+
|
|
121
126
|
renderButton(buttonIndex: number, buttonStyle?: HtButtonStyle): JSX.Element {
|
|
122
127
|
if (buttonStyle === HtButtonStyle.QUICK_REPLY) {
|
|
123
128
|
return (
|