@botonic/plugin-flow-builder 0.42.0-alpha.2 → 0.42.0-alpha.4
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/content-fields/flow-ai-agent.d.ts +1 -1
- package/lib/cjs/content-fields/flow-ai-agent.js +6 -12
- package/lib/cjs/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/cjs/content-fields/flow-button.d.ts +2 -1
- package/lib/cjs/content-fields/flow-button.js +5 -3
- package/lib/cjs/content-fields/flow-button.js.map +1 -1
- package/lib/cjs/content-fields/flow-carousel.d.ts +5 -1
- package/lib/cjs/content-fields/flow-carousel.js +74 -1
- package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
- package/lib/cjs/content-fields/flow-element.d.ts +1 -1
- package/lib/cjs/content-fields/flow-element.js +5 -4
- package/lib/cjs/content-fields/flow-element.js.map +1 -1
- package/lib/cjs/content-fields/flow-text.d.ts +2 -0
- package/lib/cjs/content-fields/flow-text.js +19 -0
- package/lib/cjs/content-fields/flow-text.js.map +1 -1
- package/lib/cjs/content-fields/flow-webview.d.ts +1 -1
- package/lib/cjs/content-fields/flow-webview.js +17 -3
- package/lib/cjs/content-fields/flow-webview.js.map +1 -1
- package/lib/esm/content-fields/flow-ai-agent.d.ts +1 -1
- package/lib/esm/content-fields/flow-ai-agent.js +7 -13
- package/lib/esm/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/esm/content-fields/flow-button.d.ts +2 -1
- package/lib/esm/content-fields/flow-button.js +5 -3
- package/lib/esm/content-fields/flow-button.js.map +1 -1
- package/lib/esm/content-fields/flow-carousel.d.ts +5 -1
- package/lib/esm/content-fields/flow-carousel.js +75 -2
- package/lib/esm/content-fields/flow-carousel.js.map +1 -1
- package/lib/esm/content-fields/flow-element.d.ts +1 -1
- package/lib/esm/content-fields/flow-element.js +5 -4
- package/lib/esm/content-fields/flow-element.js.map +1 -1
- package/lib/esm/content-fields/flow-text.d.ts +2 -0
- package/lib/esm/content-fields/flow-text.js +21 -2
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/lib/esm/content-fields/flow-webview.d.ts +1 -1
- package/lib/esm/content-fields/flow-webview.js +18 -4
- package/lib/esm/content-fields/flow-webview.js.map +1 -1
- package/package.json +3 -3
- package/src/content-fields/flow-ai-agent.tsx +7 -31
- package/src/content-fields/flow-button.tsx +6 -3
- package/src/content-fields/flow-carousel.tsx +138 -2
- package/src/content-fields/flow-element.tsx +5 -4
- package/src/content-fields/flow-text.tsx +36 -1
- package/src/content-fields/flow-webview.tsx +22 -4
|
@@ -17,5 +17,5 @@ export declare class FlowAiAgent extends ContentFieldsBase {
|
|
|
17
17
|
responses: AgenticOutputMessage[];
|
|
18
18
|
static fromHubtypeCMS(component: HtAiAgentNode): FlowAiAgent;
|
|
19
19
|
trackFlow(request: ActionRequest): Promise<void>;
|
|
20
|
-
toBotonic(id: string): JSX.Element;
|
|
20
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
21
21
|
}
|
|
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FlowAiAgent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("@botonic/react");
|
|
7
|
-
const constants_1 = require("../constants");
|
|
8
6
|
const tracking_1 = require("../tracking");
|
|
9
7
|
const content_fields_base_1 = require("./content-fields-base");
|
|
10
|
-
const
|
|
8
|
+
const flow_carousel_1 = require("./flow-carousel");
|
|
9
|
+
const flow_text_1 = require("./flow-text");
|
|
11
10
|
class FlowAiAgent extends content_fields_base_1.ContentFieldsBase {
|
|
12
11
|
constructor() {
|
|
13
12
|
super(...arguments);
|
|
@@ -34,18 +33,13 @@ class FlowAiAgent extends content_fields_base_1.ContentFieldsBase {
|
|
|
34
33
|
yield (0, tracking_1.trackOneContent)(request, this);
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
toBotonic(id) {
|
|
36
|
+
toBotonic(id, request) {
|
|
38
37
|
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: this.responses.map((response) => {
|
|
39
|
-
if (response.type === 'text') {
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
if (response.type === 'textWithButtons') {
|
|
43
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Text, { children: [response.content.text, response.content.buttons.map((button, buttonIndex) => {
|
|
44
|
-
return ((0, jsx_runtime_1.jsx)(react_1.Button, Object.assign({ payload: `${constants_1.EMPTY_PAYLOAD}${constants_1.SOURCE_INFO_SEPARATOR}${buttonIndex}` }, { children: button.text }), buttonIndex));
|
|
45
|
-
})] }, id));
|
|
38
|
+
if (response.type === 'text' || response.type === 'textWithButtons') {
|
|
39
|
+
return flow_text_1.FlowText.fromAIAgent(id, response);
|
|
46
40
|
}
|
|
47
41
|
if (response.type === 'carousel') {
|
|
48
|
-
return
|
|
42
|
+
return flow_carousel_1.FlowCarousel.fromAIAgent(id, response, request);
|
|
49
43
|
}
|
|
50
44
|
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
51
45
|
}) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-ai-agent.js","sourceRoot":"","sources":["../../../src/content-fields/flow-ai-agent.tsx"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"flow-ai-agent.js","sourceRoot":"","sources":["../../../src/content-fields/flow-ai-agent.tsx"],"names":[],"mappings":";;;;;AAGA,0CAA6C;AAC7C,+DAAyD;AACzD,mDAA8C;AAC9C,2CAAsC;AAGtC,MAAa,WAAY,SAAQ,uCAAiB;IAAlD;;QACS,SAAI,GAAW,EAAE,CAAA;QACjB,iBAAY,GAAW,EAAE,CAAA;QAKzB,cAAS,GAA2B,EAAE,CAAA;IAuC/C,CAAC;IArCC,MAAM,CAAC,cAAc,CAAC,SAAwB;QAC5C,MAAM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+11,7 @@ export declare class FlowButton extends ContentFieldsBase {
|
|
|
11
11
|
payload?: string;
|
|
12
12
|
target?: string;
|
|
13
13
|
webview?: Webview;
|
|
14
|
+
flowWebview?: FlowWebview;
|
|
14
15
|
params?: Record<string, string>;
|
|
15
16
|
static fromHubtypeCMS(cmsButton: HtButton, locale: string, cmsApi: FlowBuilderApi): FlowButton;
|
|
16
17
|
private static getWebviewParams;
|
|
@@ -24,7 +25,7 @@ export declare class FlowButton extends ContentFieldsBase {
|
|
|
24
25
|
static fromRating(button: HtRatingButton): FlowButton;
|
|
25
26
|
static getUrlId(cmsButton: HtButton, locale: string): string | undefined;
|
|
26
27
|
static getTargetWebview(cmsApi: FlowBuilderApi, targetId: string): FlowWebview | undefined;
|
|
27
|
-
trackFlow(
|
|
28
|
+
trackFlow(request: ActionRequest): Promise<void>;
|
|
28
29
|
renderButton(buttonIndex: number, buttonStyle?: HtButtonStyle): JSX.Element;
|
|
29
30
|
private getButtonPayload;
|
|
30
31
|
}
|
|
@@ -20,6 +20,7 @@ class FlowButton extends content_fields_base_1.ContentFieldsBase {
|
|
|
20
20
|
if (cmsButton.target) {
|
|
21
21
|
const webview = this.getTargetWebview(cmsApi, cmsButton.target.id);
|
|
22
22
|
if (webview) {
|
|
23
|
+
newButton.flowWebview = webview;
|
|
23
24
|
const params = this.getWebviewParams(webview, cmsApi);
|
|
24
25
|
newButton.webview = { name: webview.webviewComponentName };
|
|
25
26
|
newButton.params = params;
|
|
@@ -80,10 +81,11 @@ class FlowButton extends content_fields_base_1.ContentFieldsBase {
|
|
|
80
81
|
}
|
|
81
82
|
return flow_webview_1.FlowWebview.fromHubtypeCMS(targetNode);
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
trackFlow(_request) {
|
|
84
|
+
trackFlow(request) {
|
|
85
85
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
|
|
86
|
+
if (this.flowWebview) {
|
|
87
|
+
yield this.flowWebview.trackFlow(request);
|
|
88
|
+
}
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
renderButton(buttonIndex, buttonStyle) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-button.js","sourceRoot":"","sources":["../../../src/content-fields/flow-button.tsx"],"names":[],"mappings":";;;;;AAAA,0CAAsE;AAItE,4CAAoD;AACpD,+DAAyD;AACzD,iDAA4C;AAC5C,qDAMyB;AAGzB,MAAa,UAAW,SAAQ,uCAAiB;IAAjD;;QACS,SAAI,GAAG,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"flow-button.js","sourceRoot":"","sources":["../../../src/content-fields/flow-button.tsx"],"names":[],"mappings":";;;;;AAAA,0CAAsE;AAItE,4CAAoD;AACpD,+DAAyD;AACzD,iDAA4C;AAC5C,qDAMyB;AAGzB,MAAa,UAAW,SAAQ,uCAAiB;IAAjD;;QACS,SAAI,GAAG,EAAE,CAAA;IA2IlB,CAAC;IAnIC,MAAM,CAAC,cAAc,CACnB,SAAmB,EACnB,MAAc,EACd,MAAsB;QAEtB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAE9C,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC9C,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;QAC7D,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YAClE,IAAI,OAAO,EAAE;gBACX,SAAS,CAAC,WAAW,GAAG,OAAO,CAAA;gBAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;gBACrD,SAAS,CAAC,OAAO,GAAG,EAAE,IAAI,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QACH,CAAC;KAAA;IAED,YAAY,CAAC,WAAmB,EAAE,WAA2B;QAC3D,IAAI,WAAW,KAAK,8BAAa,CAAC,WAAW,EAAE;YAC7C,OAAO,CACL,uBAAC,aAAK,kBAAe,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,gBAC7D,IAAI,CAAC,IAAI,KADA,IAAI,CAAC,EAAE,CAEX,CACT,CAAA;SACF;QAED,OAAO,CACL,uBAAC,cAAM,kBAEL,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAC3C,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,MAAM,EAAE,IAAI,CAAC,MAAM,gBAElB,IAAI,CAAC,IAAI,KAPL,IAAI,CAAC,EAAE,CAQL,CACV,CAAA;IACH,CAAC;IAEO,gBAAgB,CAAC,WAAmB;QAC1C,OAAO,IAAI,CAAC,OAAO;YACjB,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,iCAAqB,GAAG,WAAW,EAAE;YACzD,CAAC,CAAC,SAAS,CAAA;IACf,CAAC;CACF;AA5ID,gCA4IC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { CarouselMessage } from '@botonic/core';
|
|
2
3
|
import { ActionRequest } from '@botonic/react';
|
|
3
4
|
import { FlowBuilderApi } from '../api';
|
|
4
5
|
import { ContentFieldsBase } from './content-fields-base';
|
|
@@ -8,5 +9,8 @@ export declare class FlowCarousel extends ContentFieldsBase {
|
|
|
8
9
|
elements: FlowElement[];
|
|
9
10
|
static fromHubtypeCMS(component: HtCarouselNode, locale: string, cmsApi: FlowBuilderApi): FlowCarousel;
|
|
10
11
|
trackFlow(request: ActionRequest): Promise<void>;
|
|
11
|
-
|
|
12
|
+
static areElementsValidForWhatsapp: (carouselMessage: CarouselMessage) => boolean;
|
|
13
|
+
static fromAIAgent(id: string, carouselMessage: CarouselMessage, request: ActionRequest): JSX.Element;
|
|
14
|
+
private toCarouselMessage;
|
|
15
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
12
16
|
}
|
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FlowCarousel = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const core_1 = require("@botonic/core");
|
|
6
7
|
const react_1 = require("@botonic/react");
|
|
7
8
|
const tracking_1 = require("../tracking");
|
|
8
9
|
const content_fields_base_1 = require("./content-fields-base");
|
|
9
10
|
const flow_element_1 = require("./flow-element");
|
|
11
|
+
const DEFAULT_TEXT_MESSAGE = 'These are the options';
|
|
10
12
|
class FlowCarousel extends content_fields_base_1.ContentFieldsBase {
|
|
11
13
|
constructor() {
|
|
12
14
|
super(...arguments);
|
|
@@ -22,11 +24,82 @@ class FlowCarousel extends content_fields_base_1.ContentFieldsBase {
|
|
|
22
24
|
trackFlow(request) {
|
|
23
25
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
26
|
yield (0, tracking_1.trackOneContent)(request, this);
|
|
27
|
+
for (const element of this.elements) {
|
|
28
|
+
yield element.trackFlow(request);
|
|
29
|
+
}
|
|
25
30
|
});
|
|
26
31
|
}
|
|
27
|
-
|
|
32
|
+
static fromAIAgent(id, carouselMessage, request) {
|
|
33
|
+
if ((0, core_1.isWhatsapp)(request.session) &&
|
|
34
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
35
|
+
if (carouselMessage.content.elements.length === 1) {
|
|
36
|
+
const element = carouselMessage.content.elements[0];
|
|
37
|
+
console.log('displaying whatsapp cta url button with element', element);
|
|
38
|
+
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappCTAUrlButton, { body: element.title, headerType: react_1.WhatsappCTAUrlHeaderType.Image, headerImage: element.image, footer: element.subtitle, displayText: element.button.text, url: element.button.url }, id));
|
|
40
|
+
}
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappInteractiveMediaCarousel, { cards: carouselMessage.content.elements.map(element => {
|
|
42
|
+
const buttonText = element.button.text;
|
|
43
|
+
const buttonUrl = element.button.url;
|
|
44
|
+
const imageLink = element.image;
|
|
45
|
+
return {
|
|
46
|
+
text: `*${element.title}*\n${element.subtitle}`,
|
|
47
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
48
|
+
};
|
|
49
|
+
}), textMessage: carouselMessage.content.text || DEFAULT_TEXT_MESSAGE }));
|
|
50
|
+
}
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(react_1.Carousel, { children: carouselMessage.content.elements.map((element, index) => flow_element_1.FlowElement.fromAIAgent(`${id}-element-${index}`, element).toBotonic(id)) }, id));
|
|
52
|
+
}
|
|
53
|
+
toCarouselMessage(elements) {
|
|
54
|
+
return {
|
|
55
|
+
type: 'carousel',
|
|
56
|
+
content: {
|
|
57
|
+
elements: elements.map(element => {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
return {
|
|
60
|
+
button: {
|
|
61
|
+
text: ((_a = element.button) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
62
|
+
payload: (_b = element.button) === null || _b === void 0 ? void 0 : _b.payload,
|
|
63
|
+
url: (_c = element.button) === null || _c === void 0 ? void 0 : _c.url,
|
|
64
|
+
},
|
|
65
|
+
title: element.title,
|
|
66
|
+
subtitle: element.subtitle,
|
|
67
|
+
image: element.image,
|
|
68
|
+
};
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
toBotonic(id, request) {
|
|
74
|
+
const carouselMessage = this.toCarouselMessage(this.elements);
|
|
75
|
+
if ((0, core_1.isWhatsapp)(request.session) &&
|
|
76
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
77
|
+
if (this.elements.length === 1) {
|
|
78
|
+
const element = this.elements[0];
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappCTAUrlButton, { body: element.title, headerType: react_1.WhatsappCTAUrlHeaderType.Image, headerImage: element.image, displayText: element.button.text, url: element.button.url }, id));
|
|
80
|
+
}
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappInteractiveMediaCarousel, { cards: this.elements.map(element => {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
const buttonText = ((_a = element.button) === null || _a === void 0 ? void 0 : _a.text) || '';
|
|
84
|
+
const buttonUrl = ((_b = element.button) === null || _b === void 0 ? void 0 : _b.url) || '';
|
|
85
|
+
const imageLink = element.image || '';
|
|
86
|
+
return {
|
|
87
|
+
text: element.title,
|
|
88
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
89
|
+
};
|
|
90
|
+
}),
|
|
91
|
+
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
92
|
+
textMessage: DEFAULT_TEXT_MESSAGE }));
|
|
93
|
+
}
|
|
28
94
|
return ((0, jsx_runtime_1.jsx)(react_1.Carousel, { children: this.elements.map(element => element.toBotonic(id)) }, id));
|
|
29
95
|
}
|
|
30
96
|
}
|
|
31
97
|
exports.FlowCarousel = FlowCarousel;
|
|
98
|
+
FlowCarousel.areElementsValidForWhatsapp = (carouselMessage) => {
|
|
99
|
+
const isValid = !carouselMessage.content.elements.some(element => element.button.payload) && carouselMessage.content.elements.every(element => element.button.url);
|
|
100
|
+
if (!isValid) {
|
|
101
|
+
console.warn('Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent', carouselMessage.content);
|
|
102
|
+
}
|
|
103
|
+
return isValid;
|
|
104
|
+
};
|
|
32
105
|
//# sourceMappingURL=flow-carousel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-carousel.js","sourceRoot":"","sources":["../../../src/content-fields/flow-carousel.tsx"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"flow-carousel.js","sourceRoot":"","sources":["../../../src/content-fields/flow-carousel.tsx"],"names":[],"mappings":";;;;;AAAA,wCAA2D;AAC3D,0CAMuB;AAIvB,0CAA6C;AAC7C,+DAAyD;AACzD,iDAA4C;AAG5C,MAAM,oBAAoB,GAAG,uBAAuB,CAAA;AACpD,MAAa,YAAa,SAAQ,uCAAiB;IAAnD;;QACS,aAAQ,GAAkB,EAAE,CAAA;IA4JrC,CAAC;IA1JC,MAAM,CAAC,cAAc,CACnB,SAAyB,EACzB,MAAc,EACd,MAAsB;QAEtB,MAAM,WAAW,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAClD,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QACjC,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAC9D,0BAAW,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CACpD,CAAA;QACD,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAA;QAE1C,OAAO,WAAW,CAAA;IACpB,CAAC;IAEK,SAAS,CAAC,OAAsB;;YACpC,MAAM,IAAA,0BAAe,EAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YACpC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACnC,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjC;QACH,CAAC;KAAA;IAiBD,MAAM,CAAC,WAAW,CAChB,EAAU,EACV,eAAgC,EAChC,OAAsB;QAEtB,IACE,IAAA,iBAAU,EAAC,OAAO,CAAC,OAAO,CAAC;YAC3B,YAAY,CAAC,2BAA2B,CAAC,eAAe,CAAC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eAAe,CAAC,OAAO,CACxB,CAAA;KACF;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -18,6 +18,6 @@ export declare class FlowElement extends ContentFieldsBase {
|
|
|
18
18
|
image: string;
|
|
19
19
|
button: Button;
|
|
20
20
|
}): FlowElement;
|
|
21
|
-
trackFlow(
|
|
21
|
+
trackFlow(request: ActionRequest): Promise<void>;
|
|
22
22
|
toBotonic(parentId: string): JSX.Element;
|
|
23
23
|
}
|
|
@@ -28,16 +28,17 @@ class FlowElement extends content_fields_base_1.ContentFieldsBase {
|
|
|
28
28
|
newElement.subtitle = element.subtitle;
|
|
29
29
|
newElement.image = element.image;
|
|
30
30
|
newElement.button = flow_button_1.FlowButton.fromAIAgent({
|
|
31
|
-
id:
|
|
31
|
+
id: `${id}-button`,
|
|
32
32
|
text: element.button.text,
|
|
33
33
|
url: element.button.url,
|
|
34
34
|
});
|
|
35
35
|
return newElement;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
trackFlow(_request) {
|
|
37
|
+
trackFlow(request) {
|
|
39
38
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
|
|
39
|
+
if (this.button) {
|
|
40
|
+
yield this.button.trackFlow(request);
|
|
41
|
+
}
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
toBotonic(parentId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-element.js","sourceRoot":"","sources":["../../../src/content-fields/flow-element.tsx"],"names":[],"mappings":";;;;;AACA,0CAA6E;AAG7E,+DAAyD;AACzD,+CAA0C;AAG1C,MAAa,WAAY,SAAQ,uCAAiB;IAAlD;;QACS,UAAK,GAAG,EAAE,CAAA;QACV,aAAQ,GAAG,EAAE,CAAA;QAEb,UAAK,GAAG,EAAE,CAAA;QACV,WAAM,GAAG,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"flow-element.js","sourceRoot":"","sources":["../../../src/content-fields/flow-element.tsx"],"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AAE,OAAO,CAAC,MAAM,CAAC,GAAG;SACxB,CAAC,CAAA;QACF,OAAO,UAAU,CAAA;IACnB,CAAC;IAEK,SAAS,CAAC,OAAsB;;YACpC,IAAI,IAAI,CAAC,MAAM,EAAE;gBACf,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACrC;QACH,CAAC;KAAA;IAED,SAAS,CAAC,QAAgB;;QACxB,OAAO,CACL,wBAAC,eAAO,eACN,uBAAC,WAAG,IAAC,GAAG,EAAE,IAAI,CAAC,KAAK,GAAI,EACxB,uBAAC,aAAK,cAAE,IAAI,CAAC,KAAK,GAAS,EAC3B,uBAAC,gBAAQ,cAAE,IAAI,CAAC,QAAQ,GAAY,EACnC,MAAA,IAAI,CAAC,MAAM,0CAAE,YAAY,CAAC,CAAC,CAAC,KAJjB,GAAG,QAAQ,IAAI,IAAI,CAAC,EAAE,EAAE,CAK5B,CACX,CAAA;IACH,CAAC;CACF;AA7DD,kCA6DC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { TextMessage, TextWithButtonsMessage } from '@botonic/core';
|
|
2
3
|
import { ActionRequest } from '@botonic/react';
|
|
3
4
|
import { FlowBuilderApi } from '../api';
|
|
4
5
|
import { ContentFieldsBase } from './content-fields-base';
|
|
@@ -12,5 +13,6 @@ export declare class FlowText extends ContentFieldsBase {
|
|
|
12
13
|
static replaceVariables(text: string, request: ActionRequest): string;
|
|
13
14
|
private static isValidType;
|
|
14
15
|
trackFlow(request: ActionRequest): Promise<void>;
|
|
16
|
+
static fromAIAgent(id: string, textMessage: TextMessage | TextWithButtonsMessage): JSX.Element;
|
|
15
17
|
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
16
18
|
}
|
|
@@ -48,8 +48,27 @@ class FlowText extends content_fields_base_1.ContentFieldsBase {
|
|
|
48
48
|
trackFlow(request) {
|
|
49
49
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
50
|
yield (0, tracking_1.trackOneContent)(request, this);
|
|
51
|
+
for (const button of this.buttons) {
|
|
52
|
+
yield button.trackFlow(request);
|
|
53
|
+
}
|
|
51
54
|
});
|
|
52
55
|
}
|
|
56
|
+
static fromAIAgent(id, textMessage) {
|
|
57
|
+
if (textMessage.type === 'text') {
|
|
58
|
+
return (0, jsx_runtime_1.jsx)(react_1.Text, { children: textMessage.content.text }, id);
|
|
59
|
+
}
|
|
60
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Text, { children: [textMessage.content.text, textMessage.content.buttons.map((button, buttonIndex) => {
|
|
61
|
+
const buttonData = {
|
|
62
|
+
id: `${id}-button-${buttonIndex}`,
|
|
63
|
+
text: button.text,
|
|
64
|
+
url: button.url,
|
|
65
|
+
payload: button.payload
|
|
66
|
+
? `${constants_1.EMPTY_PAYLOAD}${constants_1.SOURCE_INFO_SEPARATOR}${buttonIndex}`
|
|
67
|
+
: undefined,
|
|
68
|
+
};
|
|
69
|
+
return flow_button_1.FlowButton.fromAIAgent(buttonData).renderButton(buttonIndex);
|
|
70
|
+
})] }, id));
|
|
71
|
+
}
|
|
53
72
|
toBotonic(id, request) {
|
|
54
73
|
const replacedText = FlowText.replaceVariables(this.text, request);
|
|
55
74
|
return ((0, jsx_runtime_1.jsxs)(react_1.Text, { children: [replacedText, this.buttons.map((button, buttonIndex) => button.renderButton(buttonIndex, this.buttonStyle))] }, id));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-text.js","sourceRoot":"","sources":["../../../src/content-fields/flow-text.tsx"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"flow-text.js","sourceRoot":"","sources":["../../../src/content-fields/flow-text.tsx"],"names":[],"mappings":";;;;;AACA,0CAAoD;AAIpD,4CAKqB;AACrB,0CAA6C;AAC7C,oCAA8C;AAC9C,+DAAyD;AACzD,+CAA0C;AAC1C,qDAA4D;AAE5D,MAAa,QAAS,SAAQ,uCAAiB;IAA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AAa,GAAG,iCAAqB,GAAG,WAAW,EAAE;4BAC1D,CAAC,CAAC,SAAS;qBACd,CAAA;oBACD,OAAO,wBAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA;gBACrE,CAAC,CAAC,KAZO,EAAE,CAaN,CACR,CAAA;IACH,CAAC;IAED,SAAS,CAAC,EAAU,EAAE,OAAsB;QAC1C,MAAM,YAAY,GAAG,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAClE,OAAO,CACL,wBAAC,YAAI,eACF,YAAY,EACZ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,CACxC,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CACnD,KAJQ,EAAE,CAKN,CACR,CAAA;IACH,CAAC;CACF;AA5FD,4BA4FC"}
|
|
@@ -7,5 +7,5 @@ export declare class FlowWebview extends ContentFieldsBase {
|
|
|
7
7
|
webviewComponentName: string;
|
|
8
8
|
exits: HtWebviewExits[];
|
|
9
9
|
static fromHubtypeCMS(component: HtWebviewNode): FlowWebview;
|
|
10
|
-
trackFlow(
|
|
10
|
+
trackFlow(request: ActionRequest): Promise<void>;
|
|
11
11
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlowWebview = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@botonic/core");
|
|
6
|
+
const tracking_1 = require("../tracking");
|
|
5
7
|
const content_fields_base_1 = require("./content-fields-base");
|
|
6
8
|
class FlowWebview extends content_fields_base_1.ContentFieldsBase {
|
|
7
9
|
constructor() {
|
|
@@ -20,10 +22,22 @@ class FlowWebview extends content_fields_base_1.ContentFieldsBase {
|
|
|
20
22
|
newWebview.followUp = component.follow_up;
|
|
21
23
|
return newWebview;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
trackFlow(_request) {
|
|
25
|
+
trackFlow(request) {
|
|
25
26
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
|
|
27
|
+
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = (0, tracking_1.getCommonFlowContentEventArgsForContentId)(request, this.id);
|
|
28
|
+
const eventWebviewActionTriggered = {
|
|
29
|
+
action: core_1.EventAction.WebviewActionTriggered,
|
|
30
|
+
flowThreadId,
|
|
31
|
+
flowId,
|
|
32
|
+
flowName,
|
|
33
|
+
flowNodeId,
|
|
34
|
+
flowNodeContentId,
|
|
35
|
+
flowNodeIsMeaningful: false,
|
|
36
|
+
webviewTargetId: this.webviewTargetId,
|
|
37
|
+
webviewName: this.webviewName,
|
|
38
|
+
};
|
|
39
|
+
const { action } = eventWebviewActionTriggered, eventArgs = tslib_1.__rest(eventWebviewActionTriggered, ["action"]);
|
|
40
|
+
yield (0, tracking_1.trackEvent)(request, action, eventArgs);
|
|
27
41
|
});
|
|
28
42
|
}
|
|
29
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-webview.js","sourceRoot":"","sources":["../../../src/content-fields/flow-webview.tsx"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"flow-webview.js","sourceRoot":"","sources":["../../../src/content-fields/flow-webview.tsx"],"names":[],"mappings":";;;;AAAA,wCAAwE;AAGxE,0CAGoB;AACpB,+DAAyD;AAGzD,MAAa,WAAY,SAAQ,uCAAiB;IAAlD;;QACS,oBAAe,GAAW,EAAE,CAAA;QAC5B,gBAAW,GAAW,EAAE,CAAA;QACxB,yBAAoB,GAAW,EAAE,CAAA;QACjC,UAAK,GAAqB,EAAE,CAAA;IA+BrC,CAAC;IA7BC,MAAM,CAAC,cAAc,CAAC,SAAwB;QAC5C,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAChD,UAAU,CAAC,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,iBAAiB,CAAA;QAChE,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,CAAA;QACvD,UAAU,CAAC,oBAAoB,GAAG,SAAS,CAAC,OAAO,CAAC,sBAAsB,CAAA;QAC1E,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAA;QAC1C,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAA;QAEzC,OAAO,UAAU,CAAA;IACnB,CAAC;IAEK,SAAS,CAAC,OAAsB;;YACpC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,GACrE,IAAA,oDAAyC,EAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;YAE7D,MAAM,2BAA2B,GAAgC;gBAC/D,MAAM,EAAE,kBAAW,CAAC,sBAAsB;gBAC1C,YAAY;gBACZ,MAAM;gBACN,QAAQ;gBACR,UAAU;gBACV,iBAAiB;gBACjB,oBAAoB,EAAE,KAAK;gBAC3B,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAA;YACD,MAAM,EAAE,MAAM,KAAmB,2BAA2B,EAAzC,SAAS,kBAAK,2BAA2B,EAAtD,UAAwB,CAA8B,CAAA;YAC5D,MAAM,IAAA,qBAAU,EAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QAC9C,CAAC;KAAA;CACF;AAnCD,kCAmCC"}
|
|
@@ -17,5 +17,5 @@ export declare class FlowAiAgent extends ContentFieldsBase {
|
|
|
17
17
|
responses: AgenticOutputMessage[];
|
|
18
18
|
static fromHubtypeCMS(component: HtAiAgentNode): FlowAiAgent;
|
|
19
19
|
trackFlow(request: ActionRequest): Promise<void>;
|
|
20
|
-
toBotonic(id: string): JSX.Element;
|
|
20
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
21
21
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
import { Button, Carousel, Text } from '@botonic/react';
|
|
4
|
-
import { EMPTY_PAYLOAD, SOURCE_INFO_SEPARATOR } from '../constants';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
5
3
|
import { trackOneContent } from '../tracking';
|
|
6
4
|
import { ContentFieldsBase } from './content-fields-base';
|
|
7
|
-
import {
|
|
5
|
+
import { FlowCarousel } from './flow-carousel';
|
|
6
|
+
import { FlowText } from './flow-text';
|
|
8
7
|
export class FlowAiAgent extends ContentFieldsBase {
|
|
9
8
|
constructor() {
|
|
10
9
|
super(...arguments);
|
|
@@ -31,18 +30,13 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
31
30
|
yield trackOneContent(request, this);
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
|
-
toBotonic(id) {
|
|
33
|
+
toBotonic(id, request) {
|
|
35
34
|
return (_jsx(_Fragment, { children: this.responses.map((response) => {
|
|
36
|
-
if (response.type === 'text') {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
if (response.type === 'textWithButtons') {
|
|
40
|
-
return (_jsxs(Text, { children: [response.content.text, response.content.buttons.map((button, buttonIndex) => {
|
|
41
|
-
return (_jsx(Button, Object.assign({ payload: `${EMPTY_PAYLOAD}${SOURCE_INFO_SEPARATOR}${buttonIndex}` }, { children: button.text }), buttonIndex));
|
|
42
|
-
})] }, id));
|
|
35
|
+
if (response.type === 'text' || response.type === 'textWithButtons') {
|
|
36
|
+
return FlowText.fromAIAgent(id, response);
|
|
43
37
|
}
|
|
44
38
|
if (response.type === 'carousel') {
|
|
45
|
-
return
|
|
39
|
+
return FlowCarousel.fromAIAgent(id, response, request);
|
|
46
40
|
}
|
|
47
41
|
return _jsx(_Fragment, {});
|
|
48
42
|
}) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-ai-agent.js","sourceRoot":"","sources":["../../../src/content-fields/flow-ai-agent.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"flow-ai-agent.js","sourceRoot":"","sources":["../../../src/content-fields/flow-ai-agent.tsx"],"names":[],"mappings":";;AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAAlD;;QACS,SAAI,GAAW,EAAE,CAAA;QACjB,iBAAY,GAAW,EAAE,CAAA;QAKzB,cAAS,GAA2B,EAAE,CAAA;IAuC/C,CAAC;IArCC,MAAM,CAAC,cAAc,CAAC,SAAwB;QAC5C,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAChD,UAAU,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QAChC,UAAU,CAAC,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAA;QACxC,UAAU,CAAC,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,CAAA;QACxD,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,CAAA;QACvD,UAAU,CAAC,mBAAmB;YAC5B,SAAS,CAAC,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAA;QAC/C,UAAU,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAA;QAC9C,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAA;QAEzC,OAAO,UAAU,CAAA;IACnB,CAAC;IAEK,SAAS,CAAC,OAAsB;;YACpC,0FAA0F;YAC1F,wDAAwD;YACxD,MAAM,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC;KAAA;IAED,SAAS,CAAC,EAAU,EAAE,OAAsB;QAC1C,OAAO,CACL,4BACG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAA8B,EAAE,EAAE;gBACrD,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,iBAAiB,EAAE;oBACnE,OAAO,QAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;iBAC1C;gBAED,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE;oBAChC,OAAO,YAAY,CAAC,WAAW,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;iBACvD;gBAED,OAAO,mBAAK,CAAA;YACd,CAAC,CAAC,GACD,CACJ,CAAA;IACH,CAAC;CACF"}
|
|
@@ -11,6 +11,7 @@ export declare class FlowButton extends ContentFieldsBase {
|
|
|
11
11
|
payload?: string;
|
|
12
12
|
target?: string;
|
|
13
13
|
webview?: Webview;
|
|
14
|
+
flowWebview?: FlowWebview;
|
|
14
15
|
params?: Record<string, string>;
|
|
15
16
|
static fromHubtypeCMS(cmsButton: HtButton, locale: string, cmsApi: FlowBuilderApi): FlowButton;
|
|
16
17
|
private static getWebviewParams;
|
|
@@ -24,7 +25,7 @@ export declare class FlowButton extends ContentFieldsBase {
|
|
|
24
25
|
static fromRating(button: HtRatingButton): FlowButton;
|
|
25
26
|
static getUrlId(cmsButton: HtButton, locale: string): string | undefined;
|
|
26
27
|
static getTargetWebview(cmsApi: FlowBuilderApi, targetId: string): FlowWebview | undefined;
|
|
27
|
-
trackFlow(
|
|
28
|
+
trackFlow(request: ActionRequest): Promise<void>;
|
|
28
29
|
renderButton(buttonIndex: number, buttonStyle?: HtButtonStyle): JSX.Element;
|
|
29
30
|
private getButtonPayload;
|
|
30
31
|
}
|
|
@@ -17,6 +17,7 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
17
17
|
if (cmsButton.target) {
|
|
18
18
|
const webview = this.getTargetWebview(cmsApi, cmsButton.target.id);
|
|
19
19
|
if (webview) {
|
|
20
|
+
newButton.flowWebview = webview;
|
|
20
21
|
const params = this.getWebviewParams(webview, cmsApi);
|
|
21
22
|
newButton.webview = { name: webview.webviewComponentName };
|
|
22
23
|
newButton.params = params;
|
|
@@ -77,10 +78,11 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
77
78
|
}
|
|
78
79
|
return FlowWebview.fromHubtypeCMS(targetNode);
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
trackFlow(_request) {
|
|
81
|
+
trackFlow(request) {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
|
|
83
|
+
if (this.flowWebview) {
|
|
84
|
+
yield this.flowWebview.trackFlow(request);
|
|
85
|
+
}
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
renderButton(buttonIndex, buttonStyle) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-button.js","sourceRoot":"","sources":["../../../src/content-fields/flow-button.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAiB,MAAM,EAAE,KAAK,EAAW,MAAM,gBAAgB,CAAA;AAItE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAEL,aAAa,EAEb,qBAAqB,GAEtB,MAAM,kBAAkB,CAAA;AAGzB,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAAjD;;QACS,SAAI,GAAG,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"flow-button.js","sourceRoot":"","sources":["../../../src/content-fields/flow-button.tsx"],"names":[],"mappings":";;AAAA,OAAO,EA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,IAAI,CAAC,EAAE,CAEX,CACT,CAAA;SACF;QAED,OAAO,CACL,KAAC,MAAM,kBAEL,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAC3C,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,MAAM,EAAE,IAAI,CAAC,MAAM,gBAElB,IAAI,CAAC,IAAI,KAPL,IAAI,CAAC,EAAE,CAQL,CACV,CAAA;IACH,CAAC;IAEO,gBAAgB,CAAC,WAAmB;QAC1C,OAAO,IAAI,CAAC,OAAO;YACjB,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,qBAAqB,GAAG,WAAW,EAAE;YACzD,CAAC,CAAC,SAAS,CAAA;IACf,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { CarouselMessage } from '@botonic/core';
|
|
2
3
|
import { ActionRequest } from '@botonic/react';
|
|
3
4
|
import { FlowBuilderApi } from '../api';
|
|
4
5
|
import { ContentFieldsBase } from './content-fields-base';
|
|
@@ -8,5 +9,8 @@ export declare class FlowCarousel extends ContentFieldsBase {
|
|
|
8
9
|
elements: FlowElement[];
|
|
9
10
|
static fromHubtypeCMS(component: HtCarouselNode, locale: string, cmsApi: FlowBuilderApi): FlowCarousel;
|
|
10
11
|
trackFlow(request: ActionRequest): Promise<void>;
|
|
11
|
-
|
|
12
|
+
static areElementsValidForWhatsapp: (carouselMessage: CarouselMessage) => boolean;
|
|
13
|
+
static fromAIAgent(id: string, carouselMessage: CarouselMessage, request: ActionRequest): JSX.Element;
|
|
14
|
+
private toCarouselMessage;
|
|
15
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
12
16
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { isWhatsapp } from '@botonic/core';
|
|
4
|
+
import { Carousel, WhatsappCTAUrlButton, WhatsappCTAUrlHeaderType, WhatsappInteractiveMediaCarousel, } from '@botonic/react';
|
|
4
5
|
import { trackOneContent } from '../tracking';
|
|
5
6
|
import { ContentFieldsBase } from './content-fields-base';
|
|
6
7
|
import { FlowElement } from './flow-element';
|
|
8
|
+
const DEFAULT_TEXT_MESSAGE = 'These are the options';
|
|
7
9
|
export class FlowCarousel extends ContentFieldsBase {
|
|
8
10
|
constructor() {
|
|
9
11
|
super(...arguments);
|
|
@@ -19,10 +21,81 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
19
21
|
trackFlow(request) {
|
|
20
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
23
|
yield trackOneContent(request, this);
|
|
24
|
+
for (const element of this.elements) {
|
|
25
|
+
yield element.trackFlow(request);
|
|
26
|
+
}
|
|
22
27
|
});
|
|
23
28
|
}
|
|
24
|
-
|
|
29
|
+
static fromAIAgent(id, carouselMessage, request) {
|
|
30
|
+
if (isWhatsapp(request.session) &&
|
|
31
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
32
|
+
if (carouselMessage.content.elements.length === 1) {
|
|
33
|
+
const element = carouselMessage.content.elements[0];
|
|
34
|
+
console.log('displaying whatsapp cta url button with element', element);
|
|
35
|
+
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
36
|
+
return (_jsx(WhatsappCTAUrlButton, { body: element.title, headerType: WhatsappCTAUrlHeaderType.Image, headerImage: element.image, footer: element.subtitle, displayText: element.button.text, url: element.button.url }, id));
|
|
37
|
+
}
|
|
38
|
+
return (_jsx(WhatsappInteractiveMediaCarousel, { cards: carouselMessage.content.elements.map(element => {
|
|
39
|
+
const buttonText = element.button.text;
|
|
40
|
+
const buttonUrl = element.button.url;
|
|
41
|
+
const imageLink = element.image;
|
|
42
|
+
return {
|
|
43
|
+
text: `*${element.title}*\n${element.subtitle}`,
|
|
44
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
45
|
+
};
|
|
46
|
+
}), textMessage: carouselMessage.content.text || DEFAULT_TEXT_MESSAGE }));
|
|
47
|
+
}
|
|
48
|
+
return (_jsx(Carousel, { children: carouselMessage.content.elements.map((element, index) => FlowElement.fromAIAgent(`${id}-element-${index}`, element).toBotonic(id)) }, id));
|
|
49
|
+
}
|
|
50
|
+
toCarouselMessage(elements) {
|
|
51
|
+
return {
|
|
52
|
+
type: 'carousel',
|
|
53
|
+
content: {
|
|
54
|
+
elements: elements.map(element => {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
return {
|
|
57
|
+
button: {
|
|
58
|
+
text: ((_a = element.button) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
59
|
+
payload: (_b = element.button) === null || _b === void 0 ? void 0 : _b.payload,
|
|
60
|
+
url: (_c = element.button) === null || _c === void 0 ? void 0 : _c.url,
|
|
61
|
+
},
|
|
62
|
+
title: element.title,
|
|
63
|
+
subtitle: element.subtitle,
|
|
64
|
+
image: element.image,
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
toBotonic(id, request) {
|
|
71
|
+
const carouselMessage = this.toCarouselMessage(this.elements);
|
|
72
|
+
if (isWhatsapp(request.session) &&
|
|
73
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
74
|
+
if (this.elements.length === 1) {
|
|
75
|
+
const element = this.elements[0];
|
|
76
|
+
return (_jsx(WhatsappCTAUrlButton, { body: element.title, headerType: WhatsappCTAUrlHeaderType.Image, headerImage: element.image, displayText: element.button.text, url: element.button.url }, id));
|
|
77
|
+
}
|
|
78
|
+
return (_jsx(WhatsappInteractiveMediaCarousel, { cards: this.elements.map(element => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const buttonText = ((_a = element.button) === null || _a === void 0 ? void 0 : _a.text) || '';
|
|
81
|
+
const buttonUrl = ((_b = element.button) === null || _b === void 0 ? void 0 : _b.url) || '';
|
|
82
|
+
const imageLink = element.image || '';
|
|
83
|
+
return {
|
|
84
|
+
text: element.title,
|
|
85
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
86
|
+
};
|
|
87
|
+
}),
|
|
88
|
+
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
89
|
+
textMessage: DEFAULT_TEXT_MESSAGE }));
|
|
90
|
+
}
|
|
25
91
|
return (_jsx(Carousel, { children: this.elements.map(element => element.toBotonic(id)) }, id));
|
|
26
92
|
}
|
|
27
93
|
}
|
|
94
|
+
FlowCarousel.areElementsValidForWhatsapp = (carouselMessage) => {
|
|
95
|
+
const isValid = !carouselMessage.content.elements.some(element => element.button.payload) && carouselMessage.content.elements.every(element => element.button.url);
|
|
96
|
+
if (!isValid) {
|
|
97
|
+
console.warn('Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent', carouselMessage.content);
|
|
98
|
+
}
|
|
99
|
+
return isValid;
|
|
100
|
+
};
|
|
28
101
|
//# sourceMappingURL=flow-carousel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-carousel.js","sourceRoot":"","sources":["../../../src/content-fields/flow-carousel.tsx"],"names":[],"mappings":";;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"flow-carousel.js","sourceRoot":"","sources":["../../../src/content-fields/flow-carousel.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAEL,QAAQ,EACR,oBAAoB,EACpB,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,gBAAgB,CAAA;AAIvB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,WAAW,EAA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AM,0CAAE,IAAI,KAAI,EAAE,CAAA;oBAC7C,MAAM,SAAS,GAAG,CAAA,MAAA,OAAO,CAAC,MAAM,0CAAE,GAAG,KAAI,EAAE,CAAA;oBAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAA;oBAErC,OAAO;wBACL,IAAI,EAAE,OAAO,CAAC,KAAK;wBACnB,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE;qBAC7C,CAAA;gBACH,CAAC,CAAC;gBACF,kHAAkH;gBAClH,WAAW,EAAE,oBAAoB,GACjC,CACH,CAAA;SACF;QACD,OAAO,CACL,KAAC,QAAQ,cACN,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,IADvC,EAAE,CAEN,CACZ,CAAA;IACH,CAAC;;AAnIM,wCAA2B,GAAG,CAAC,eAAgC,EAAE,EAAE;IACxE,MAAM,OAAO,GACX,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CACpC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAClC,IAAI,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAE5E,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,CAAC,IAAI,CACV,6EAA6E,EAC7E,eAAe,CAAC,OAAO,CACxB,CAAA;KACF;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -18,6 +18,6 @@ export declare class FlowElement extends ContentFieldsBase {
|
|
|
18
18
|
image: string;
|
|
19
19
|
button: Button;
|
|
20
20
|
}): FlowElement;
|
|
21
|
-
trackFlow(
|
|
21
|
+
trackFlow(request: ActionRequest): Promise<void>;
|
|
22
22
|
toBotonic(parentId: string): JSX.Element;
|
|
23
23
|
}
|
|
@@ -25,16 +25,17 @@ export class FlowElement extends ContentFieldsBase {
|
|
|
25
25
|
newElement.subtitle = element.subtitle;
|
|
26
26
|
newElement.image = element.image;
|
|
27
27
|
newElement.button = FlowButton.fromAIAgent({
|
|
28
|
-
id:
|
|
28
|
+
id: `${id}-button`,
|
|
29
29
|
text: element.button.text,
|
|
30
30
|
url: element.button.url,
|
|
31
31
|
});
|
|
32
32
|
return newElement;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
trackFlow(_request) {
|
|
34
|
+
trackFlow(request) {
|
|
36
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
|
|
36
|
+
if (this.button) {
|
|
37
|
+
yield this.button.trackFlow(request);
|
|
38
|
+
}
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
toBotonic(parentId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-element.js","sourceRoot":"","sources":["../../../src/content-fields/flow-element.tsx"],"names":[],"mappings":";;AACA,OAAO,EAAiB,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG1C,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAAlD;;QACS,UAAK,GAAG,EAAE,CAAA;QACV,aAAQ,GAAG,EAAE,CAAA;QAEb,UAAK,GAAG,EAAE,CAAA;QACV,WAAM,GAAG,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"flow-element.js","sourceRoot":"","sources":["../../../src/content-fields/flow-element.tsx"],"names":[],"mappings":";;AACA,OAAO,EAAiB,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA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AO,CAAC,MAAM,CAAC,GAAG;SACxB,CAAC,CAAA;QACF,OAAO,UAAU,CAAA;IACnB,CAAC;IAEK,SAAS,CAAC,OAAsB;;YACpC,IAAI,IAAI,CAAC,MAAM,EAAE;gBACf,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACrC;QACH,CAAC;KAAA;IAED,SAAS,CAAC,QAAgB;;QACxB,OAAO,CACL,MAAC,OAAO,eACN,KAAC,GAAG,IAAC,GAAG,EAAE,IAAI,CAAC,KAAK,GAAI,EACxB,KAAC,KAAK,cAAE,IAAI,CAAC,KAAK,GAAS,EAC3B,KAAC,QAAQ,cAAE,IAAI,CAAC,QAAQ,GAAY,EACnC,MAAA,IAAI,CAAC,MAAM,0CAAE,YAAY,CAAC,CAAC,CAAC,KAJjB,GAAG,QAAQ,IAAI,IAAI,CAAC,EAAE,EAAE,CAK5B,CACX,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { TextMessage, TextWithButtonsMessage } from '@botonic/core';
|
|
2
3
|
import { ActionRequest } from '@botonic/react';
|
|
3
4
|
import { FlowBuilderApi } from '../api';
|
|
4
5
|
import { ContentFieldsBase } from './content-fields-base';
|
|
@@ -12,5 +13,6 @@ export declare class FlowText extends ContentFieldsBase {
|
|
|
12
13
|
static replaceVariables(text: string, request: ActionRequest): string;
|
|
13
14
|
private static isValidType;
|
|
14
15
|
trackFlow(request: ActionRequest): Promise<void>;
|
|
16
|
+
static fromAIAgent(id: string, textMessage: TextMessage | TextWithButtonsMessage): JSX.Element;
|
|
15
17
|
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
16
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Text } from '@botonic/react';
|
|
4
|
-
import { ACCESS_TOKEN_VARIABLE_KEY, VARIABLE_PATTERN } from '../constants';
|
|
4
|
+
import { ACCESS_TOKEN_VARIABLE_KEY, EMPTY_PAYLOAD, SOURCE_INFO_SEPARATOR, VARIABLE_PATTERN, } from '../constants';
|
|
5
5
|
import { trackOneContent } from '../tracking';
|
|
6
6
|
import { getValueFromKeyPath } from '../utils';
|
|
7
7
|
import { ContentFieldsBase } from './content-fields-base';
|
|
@@ -45,8 +45,27 @@ export class FlowText extends ContentFieldsBase {
|
|
|
45
45
|
trackFlow(request) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
47
|
yield trackOneContent(request, this);
|
|
48
|
+
for (const button of this.buttons) {
|
|
49
|
+
yield button.trackFlow(request);
|
|
50
|
+
}
|
|
48
51
|
});
|
|
49
52
|
}
|
|
53
|
+
static fromAIAgent(id, textMessage) {
|
|
54
|
+
if (textMessage.type === 'text') {
|
|
55
|
+
return _jsx(Text, { children: textMessage.content.text }, id);
|
|
56
|
+
}
|
|
57
|
+
return (_jsxs(Text, { children: [textMessage.content.text, textMessage.content.buttons.map((button, buttonIndex) => {
|
|
58
|
+
const buttonData = {
|
|
59
|
+
id: `${id}-button-${buttonIndex}`,
|
|
60
|
+
text: button.text,
|
|
61
|
+
url: button.url,
|
|
62
|
+
payload: button.payload
|
|
63
|
+
? `${EMPTY_PAYLOAD}${SOURCE_INFO_SEPARATOR}${buttonIndex}`
|
|
64
|
+
: undefined,
|
|
65
|
+
};
|
|
66
|
+
return FlowButton.fromAIAgent(buttonData).renderButton(buttonIndex);
|
|
67
|
+
})] }, id));
|
|
68
|
+
}
|
|
50
69
|
toBotonic(id, request) {
|
|
51
70
|
const replacedText = FlowText.replaceVariables(this.text, request);
|
|
52
71
|
return (_jsxs(Text, { children: [replacedText, this.buttons.map((button, buttonIndex) => button.renderButton(buttonIndex, this.buttonStyle))] }, id));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-text.js","sourceRoot":"","sources":["../../../src/content-fields/flow-text.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"flow-text.js","sourceRoot":"","sources":["../../../src/content-fields/flow-text.tsx"],"names":[],"mappings":";;AACA,OAAO,EAAiB,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAIpD,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAc,MAAM,kBAAkB,CAAA;AAE5D,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAA/C;;QACS,SAAI,GAAG,EAAE,CAAA;QACT,YAAO,GAAiB,EAAE,CAAA;QAC1B,gBAAW,GAAG,aAAa,CAAC,MAAM,CAAA;IAyF3C,CAAC;IAvFC,MAAM,CAAC,cAAc,CACnB,OAAmB,EACnB,MAAc,EACd,MAAsB;QAEtB,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACxC,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QAC3B,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,CAAA;QAC3E,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACjE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CACrD,UA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|
|
|
7
7
|
webviewComponentName: string;
|
|
8
8
|
exits: HtWebviewExits[];
|
|
9
9
|
static fromHubtypeCMS(component: HtWebviewNode): FlowWebview;
|
|
10
|
-
trackFlow(
|
|
10
|
+
trackFlow(request: ActionRequest): Promise<void>;
|
|
11
11
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
import { EventAction } from '@botonic/core';
|
|
3
|
+
import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking';
|
|
2
4
|
import { ContentFieldsBase } from './content-fields-base';
|
|
3
5
|
export class FlowWebview extends ContentFieldsBase {
|
|
4
6
|
constructor() {
|
|
@@ -17,10 +19,22 @@ export class FlowWebview extends ContentFieldsBase {
|
|
|
17
19
|
newWebview.followUp = component.follow_up;
|
|
18
20
|
return newWebview;
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
trackFlow(_request) {
|
|
22
|
+
trackFlow(request) {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
|
|
24
|
+
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgsForContentId(request, this.id);
|
|
25
|
+
const eventWebviewActionTriggered = {
|
|
26
|
+
action: EventAction.WebviewActionTriggered,
|
|
27
|
+
flowThreadId,
|
|
28
|
+
flowId,
|
|
29
|
+
flowName,
|
|
30
|
+
flowNodeId,
|
|
31
|
+
flowNodeContentId,
|
|
32
|
+
flowNodeIsMeaningful: false,
|
|
33
|
+
webviewTargetId: this.webviewTargetId,
|
|
34
|
+
webviewName: this.webviewName,
|
|
35
|
+
};
|
|
36
|
+
const { action } = eventWebviewActionTriggered, eventArgs = __rest(eventWebviewActionTriggered, ["action"]);
|
|
37
|
+
yield trackEvent(request, action, eventArgs);
|
|
24
38
|
});
|
|
25
39
|
}
|
|
26
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-webview.js","sourceRoot":"","sources":["../../../src/content-fields/flow-webview.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"flow-webview.js","sourceRoot":"","sources":["../../../src/content-fields/flow-webview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAA+B,MAAM,eAAe,CAAA;AAGxE,OAAO,EACL,yCAAyC,EACzC,UAAU,GACX,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAGzD,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAAlD;;QACS,oBAAe,GAAW,EAAE,CAAA;QAC5B,gBAAW,GAAW,EAAE,CAAA;QACxB,yBAAoB,GAAW,EAAE,CAAA;QACjC,UAAK,GAAqB,EAAE,CAAA;IA+BrC,CAAC;IA7BC,MAAM,CAAC,cAAc,CAAC,SAAwB;QAC5C,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAChD,UAAU,CAAC,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,iBAAiB,CAAA;QAChE,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,CAAA;QACvD,UAAU,CAAC,oBAAoB,GAAG,SAAS,CAAC,OAAO,CAAC,sBAAsB,CAAA;QAC1E,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAA;QAC1C,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAA;QAEzC,OAAO,UAAU,CAAA;IACnB,CAAC;IAEK,SAAS,CAAC,OAAsB;;YACpC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,GACrE,yCAAyC,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;YAE7D,MAAM,2BAA2B,GAAgC;gBAC/D,MAAM,EAAE,WAAW,CAAC,sBAAsB;gBAC1C,YAAY;gBACZ,MAAM;gBACN,QAAQ;gBACR,UAAU;gBACV,iBAAiB;gBACjB,oBAAoB,EAAE,KAAK;gBAC3B,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAA;YACD,MAAM,EAAE,MAAM,KAAmB,2BAA2B,EAAzC,SAAS,UAAK,2BAA2B,EAAtD,UAAwB,CAA8B,CAAA;YAC5D,MAAM,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QAC9C,CAAC;KAAA;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.42.0-alpha.
|
|
3
|
+
"version": "0.42.0-alpha.4",
|
|
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.42.0-alpha.
|
|
17
|
+
"@botonic/react": "0.42.0-alpha.4",
|
|
18
18
|
"axios": "^1.12.2",
|
|
19
19
|
"uuid": "^10.0.0"
|
|
20
20
|
},
|
|
@@ -50,4 +50,4 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/uuid": "^10.0.0"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AgenticOutputMessage } from '@botonic/core'
|
|
2
|
-
import { ActionRequest
|
|
2
|
+
import { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
|
-
import { EMPTY_PAYLOAD, SOURCE_INFO_SEPARATOR } from '../constants'
|
|
5
4
|
import { trackOneContent } from '../tracking'
|
|
6
5
|
import { ContentFieldsBase } from './content-fields-base'
|
|
7
|
-
import {
|
|
6
|
+
import { FlowCarousel } from './flow-carousel'
|
|
7
|
+
import { FlowText } from './flow-text'
|
|
8
8
|
import { HtAiAgentNode, HtInputGuardrailRule } from './hubtype-fields/ai-agent'
|
|
9
9
|
|
|
10
10
|
export class FlowAiAgent extends ContentFieldsBase {
|
|
@@ -36,40 +36,16 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
36
36
|
await trackOneContent(request, this)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
toBotonic(id: string): JSX.Element {
|
|
39
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
40
40
|
return (
|
|
41
41
|
<>
|
|
42
42
|
{this.responses.map((response: AgenticOutputMessage) => {
|
|
43
|
-
if (response.type === 'text') {
|
|
44
|
-
return
|
|
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
|
-
)
|
|
43
|
+
if (response.type === 'text' || response.type === 'textWithButtons') {
|
|
44
|
+
return FlowText.fromAIAgent(id, response)
|
|
63
45
|
}
|
|
64
46
|
|
|
65
47
|
if (response.type === 'carousel') {
|
|
66
|
-
return (
|
|
67
|
-
<Carousel key={id}>
|
|
68
|
-
{response.content.elements.map(element =>
|
|
69
|
-
FlowElement.fromAIAgent(id, element).toBotonic(id)
|
|
70
|
-
)}
|
|
71
|
-
</Carousel>
|
|
72
|
-
)
|
|
48
|
+
return FlowCarousel.fromAIAgent(id, response, request)
|
|
73
49
|
}
|
|
74
50
|
|
|
75
51
|
return <></>
|
|
@@ -20,6 +20,7 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
20
20
|
public payload?: string
|
|
21
21
|
public target?: string
|
|
22
22
|
public webview?: Webview
|
|
23
|
+
public flowWebview?: FlowWebview // Used for tracking
|
|
23
24
|
public params?: Record<string, string>
|
|
24
25
|
|
|
25
26
|
static fromHubtypeCMS(
|
|
@@ -34,6 +35,7 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
34
35
|
if (cmsButton.target) {
|
|
35
36
|
const webview = this.getTargetWebview(cmsApi, cmsButton.target.id)
|
|
36
37
|
if (webview) {
|
|
38
|
+
newButton.flowWebview = webview
|
|
37
39
|
const params = this.getWebviewParams(webview, cmsApi)
|
|
38
40
|
newButton.webview = { name: webview.webviewComponentName }
|
|
39
41
|
newButton.params = params
|
|
@@ -118,9 +120,10 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
118
120
|
return FlowWebview.fromHubtypeCMS(targetNode)
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
async trackFlow(request: ActionRequest): Promise<void> {
|
|
124
|
+
if (this.flowWebview) {
|
|
125
|
+
await this.flowWebview.trackFlow(request)
|
|
126
|
+
}
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
renderButton(buttonIndex: number, buttonStyle?: HtButtonStyle): JSX.Element {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CarouselMessage, isWhatsapp } from '@botonic/core'
|
|
2
|
+
import {
|
|
3
|
+
ActionRequest,
|
|
4
|
+
Carousel,
|
|
5
|
+
WhatsappCTAUrlButton,
|
|
6
|
+
WhatsappCTAUrlHeaderType,
|
|
7
|
+
WhatsappInteractiveMediaCarousel,
|
|
8
|
+
} from '@botonic/react'
|
|
2
9
|
import React from 'react'
|
|
3
10
|
|
|
4
11
|
import { FlowBuilderApi } from '../api'
|
|
@@ -7,6 +14,7 @@ import { ContentFieldsBase } from './content-fields-base'
|
|
|
7
14
|
import { FlowElement } from './flow-element'
|
|
8
15
|
import { HtCarouselNode } from './hubtype-fields'
|
|
9
16
|
|
|
17
|
+
const DEFAULT_TEXT_MESSAGE = 'These are the options'
|
|
10
18
|
export class FlowCarousel extends ContentFieldsBase {
|
|
11
19
|
public elements: FlowElement[] = []
|
|
12
20
|
|
|
@@ -27,9 +35,137 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
27
35
|
|
|
28
36
|
async trackFlow(request: ActionRequest): Promise<void> {
|
|
29
37
|
await trackOneContent(request, this)
|
|
38
|
+
for (const element of this.elements) {
|
|
39
|
+
await element.trackFlow(request)
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
static areElementsValidForWhatsapp = (carouselMessage: CarouselMessage) => {
|
|
44
|
+
const isValid =
|
|
45
|
+
!carouselMessage.content.elements.some(
|
|
46
|
+
element => element.button.payload
|
|
47
|
+
) && carouselMessage.content.elements.every(element => element.button.url)
|
|
48
|
+
|
|
49
|
+
if (!isValid) {
|
|
50
|
+
console.warn(
|
|
51
|
+
'Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent',
|
|
52
|
+
carouselMessage.content
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return isValid
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static fromAIAgent(
|
|
59
|
+
id: string,
|
|
60
|
+
carouselMessage: CarouselMessage,
|
|
61
|
+
request: ActionRequest
|
|
62
|
+
): JSX.Element {
|
|
63
|
+
if (
|
|
64
|
+
isWhatsapp(request.session) &&
|
|
65
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)
|
|
66
|
+
) {
|
|
67
|
+
if (carouselMessage.content.elements.length === 1) {
|
|
68
|
+
const element = carouselMessage.content.elements[0]
|
|
69
|
+
console.log('displaying whatsapp cta url button with element', element)
|
|
70
|
+
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
71
|
+
return (
|
|
72
|
+
<WhatsappCTAUrlButton
|
|
73
|
+
key={id}
|
|
74
|
+
body={element.title}
|
|
75
|
+
headerType={WhatsappCTAUrlHeaderType.Image}
|
|
76
|
+
headerImage={element.image}
|
|
77
|
+
footer={element.subtitle}
|
|
78
|
+
displayText={element.button.text}
|
|
79
|
+
url={element.button.url!}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<WhatsappInteractiveMediaCarousel
|
|
86
|
+
cards={carouselMessage.content.elements.map(element => {
|
|
87
|
+
const buttonText = element.button.text
|
|
88
|
+
const buttonUrl = element.button.url!
|
|
89
|
+
const imageLink = element.image
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
text: `*${element.title}*\n${element.subtitle}`,
|
|
93
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
94
|
+
}
|
|
95
|
+
})}
|
|
96
|
+
textMessage={carouselMessage.content.text || DEFAULT_TEXT_MESSAGE}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
return (
|
|
101
|
+
<Carousel key={id}>
|
|
102
|
+
{carouselMessage.content.elements.map((element, index) =>
|
|
103
|
+
FlowElement.fromAIAgent(`${id}-element-${index}`, element).toBotonic(
|
|
104
|
+
id
|
|
105
|
+
)
|
|
106
|
+
)}
|
|
107
|
+
</Carousel>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private toCarouselMessage(elements: FlowElement[]): CarouselMessage {
|
|
112
|
+
return {
|
|
113
|
+
type: 'carousel',
|
|
114
|
+
content: {
|
|
115
|
+
elements: elements.map(element => {
|
|
116
|
+
return {
|
|
117
|
+
button: {
|
|
118
|
+
text: element.button?.text || '',
|
|
119
|
+
payload: element.button?.payload,
|
|
120
|
+
url: element.button?.url,
|
|
121
|
+
},
|
|
122
|
+
title: element.title,
|
|
123
|
+
subtitle: element.subtitle,
|
|
124
|
+
image: element.image,
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
132
|
+
const carouselMessage = this.toCarouselMessage(this.elements)
|
|
133
|
+
if (
|
|
134
|
+
isWhatsapp(request.session) &&
|
|
135
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)
|
|
136
|
+
) {
|
|
137
|
+
if (this.elements.length === 1) {
|
|
138
|
+
const element = this.elements[0]
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<WhatsappCTAUrlButton
|
|
142
|
+
key={id}
|
|
143
|
+
body={element.title}
|
|
144
|
+
headerType={WhatsappCTAUrlHeaderType.Image}
|
|
145
|
+
headerImage={element.image}
|
|
146
|
+
displayText={element.button!.text}
|
|
147
|
+
url={element.button!.url!}
|
|
148
|
+
/>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<WhatsappInteractiveMediaCarousel
|
|
154
|
+
cards={this.elements.map(element => {
|
|
155
|
+
const buttonText = element.button?.text || ''
|
|
156
|
+
const buttonUrl = element.button?.url || ''
|
|
157
|
+
const imageLink = element.image || ''
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
text: element.title,
|
|
161
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
162
|
+
}
|
|
163
|
+
})}
|
|
164
|
+
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
165
|
+
textMessage={DEFAULT_TEXT_MESSAGE}
|
|
166
|
+
/>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
33
169
|
return (
|
|
34
170
|
<Carousel key={id}>
|
|
35
171
|
{this.elements.map(element => element.toBotonic(id))}
|
|
@@ -44,16 +44,17 @@ export class FlowElement extends ContentFieldsBase {
|
|
|
44
44
|
newElement.subtitle = element.subtitle
|
|
45
45
|
newElement.image = element.image
|
|
46
46
|
newElement.button = FlowButton.fromAIAgent({
|
|
47
|
-
id:
|
|
47
|
+
id: `${id}-button`,
|
|
48
48
|
text: element.button.text,
|
|
49
49
|
url: element.button.url,
|
|
50
50
|
})
|
|
51
51
|
return newElement
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
async trackFlow(request: ActionRequest): Promise<void> {
|
|
55
|
+
if (this.button) {
|
|
56
|
+
await this.button.trackFlow(request)
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
toBotonic(parentId: string): JSX.Element {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { TextMessage, TextWithButtonsMessage } from '@botonic/core'
|
|
1
2
|
import { ActionRequest, Text } from '@botonic/react'
|
|
2
3
|
import React from 'react'
|
|
3
4
|
|
|
4
5
|
import { FlowBuilderApi } from '../api'
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ACCESS_TOKEN_VARIABLE_KEY,
|
|
8
|
+
EMPTY_PAYLOAD,
|
|
9
|
+
SOURCE_INFO_SEPARATOR,
|
|
10
|
+
VARIABLE_PATTERN,
|
|
11
|
+
} from '../constants'
|
|
6
12
|
import { trackOneContent } from '../tracking'
|
|
7
13
|
import { getValueFromKeyPath } from '../utils'
|
|
8
14
|
import { ContentFieldsBase } from './content-fields-base'
|
|
@@ -59,6 +65,35 @@ export class FlowText extends ContentFieldsBase {
|
|
|
59
65
|
|
|
60
66
|
async trackFlow(request: ActionRequest): Promise<void> {
|
|
61
67
|
await trackOneContent(request, this)
|
|
68
|
+
for (const button of this.buttons) {
|
|
69
|
+
await button.trackFlow(request)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static fromAIAgent(
|
|
74
|
+
id: string,
|
|
75
|
+
textMessage: TextMessage | TextWithButtonsMessage
|
|
76
|
+
): JSX.Element {
|
|
77
|
+
if (textMessage.type === 'text') {
|
|
78
|
+
return <Text key={id}>{textMessage.content.text}</Text>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Text key={id}>
|
|
83
|
+
{textMessage.content.text}
|
|
84
|
+
{textMessage.content.buttons.map((button, buttonIndex) => {
|
|
85
|
+
const buttonData = {
|
|
86
|
+
id: `${id}-button-${buttonIndex}`,
|
|
87
|
+
text: button.text,
|
|
88
|
+
url: button.url,
|
|
89
|
+
payload: button.payload
|
|
90
|
+
? `${EMPTY_PAYLOAD}${SOURCE_INFO_SEPARATOR}${buttonIndex}`
|
|
91
|
+
: undefined,
|
|
92
|
+
}
|
|
93
|
+
return FlowButton.fromAIAgent(buttonData).renderButton(buttonIndex)
|
|
94
|
+
})}
|
|
95
|
+
</Text>
|
|
96
|
+
)
|
|
62
97
|
}
|
|
63
98
|
|
|
64
99
|
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { EventAction, EventWebviewActionTriggered } from '@botonic/core'
|
|
1
2
|
import { ActionRequest } from '@botonic/react'
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getCommonFlowContentEventArgsForContentId,
|
|
6
|
+
trackEvent,
|
|
7
|
+
} from '../tracking'
|
|
4
8
|
import { ContentFieldsBase } from './content-fields-base'
|
|
5
9
|
import { HtWebviewExits, HtWebviewNode } from './hubtype-fields'
|
|
6
10
|
|
|
@@ -21,8 +25,22 @@ export class FlowWebview extends ContentFieldsBase {
|
|
|
21
25
|
return newWebview
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
async trackFlow(request: ActionRequest): Promise<void> {
|
|
29
|
+
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
30
|
+
getCommonFlowContentEventArgsForContentId(request, this.id)
|
|
31
|
+
|
|
32
|
+
const eventWebviewActionTriggered: EventWebviewActionTriggered = {
|
|
33
|
+
action: EventAction.WebviewActionTriggered,
|
|
34
|
+
flowThreadId,
|
|
35
|
+
flowId,
|
|
36
|
+
flowName,
|
|
37
|
+
flowNodeId,
|
|
38
|
+
flowNodeContentId,
|
|
39
|
+
flowNodeIsMeaningful: false,
|
|
40
|
+
webviewTargetId: this.webviewTargetId,
|
|
41
|
+
webviewName: this.webviewName,
|
|
42
|
+
}
|
|
43
|
+
const { action, ...eventArgs } = eventWebviewActionTriggered
|
|
44
|
+
await trackEvent(request, action, eventArgs)
|
|
27
45
|
}
|
|
28
46
|
}
|