@botonic/plugin-flow-builder 0.42.0-alpha.3 → 0.42.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/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-carousel.d.ts +9 -1
- package/lib/cjs/content-fields/flow-carousel.js +77 -1
- package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
- package/lib/cjs/content-fields/flow-element.js +1 -1
- 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 +16 -0
- package/lib/cjs/content-fields/flow-text.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-carousel.d.ts +9 -1
- package/lib/esm/content-fields/flow-carousel.js +78 -2
- package/lib/esm/content-fields/flow-carousel.js.map +1 -1
- package/lib/esm/content-fields/flow-element.js +1 -1
- 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 +18 -2
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/package.json +3 -3
- package/src/content-fields/flow-ai-agent.tsx +7 -31
- package/src/content-fields/flow-carousel.tsx +145 -2
- package/src/content-fields/flow-element.tsx +1 -1
- package/src/content-fields/flow-text.tsx +33 -1
|
@@ -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,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,IAAA,0BAAe,EAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC;KAAA;IAED,SAAS,CAAC,EAAU,EAAE,OAAsB;QAC1C,OAAO,CACL,2DACG,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,oBAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;iBAC1C;gBAED,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE;oBAChC,OAAO,4BAAY,CAAC,WAAW,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;iBACvD;gBAED,OAAO,kDAAK,CAAA;YACd,CAAC,CAAC,GACD,CACJ,CAAA;IACH,CAAC;CACF;AA9CD,kCA8CC"}
|
|
@@ -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,12 @@ 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 generateWhatsappElementText(element: {
|
|
14
|
+
title: string;
|
|
15
|
+
subtitle?: string;
|
|
16
|
+
}): string;
|
|
17
|
+
static fromAIAgent(id: string, carouselMessage: CarouselMessage, request: ActionRequest): JSX.Element;
|
|
18
|
+
private toCarouselMessage;
|
|
19
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
12
20
|
}
|
|
@@ -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);
|
|
@@ -27,9 +29,83 @@ class FlowCarousel extends content_fields_base_1.ContentFieldsBase {
|
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
|
-
|
|
32
|
+
static generateWhatsappElementText(element) {
|
|
33
|
+
if (element.subtitle) {
|
|
34
|
+
return `*${element.title}*\n${element.subtitle}`;
|
|
35
|
+
}
|
|
36
|
+
return element.title;
|
|
37
|
+
}
|
|
38
|
+
static fromAIAgent(id, carouselMessage, request) {
|
|
39
|
+
if ((0, core_1.isWhatsapp)(request.session) &&
|
|
40
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
41
|
+
if (carouselMessage.content.elements.length === 1) {
|
|
42
|
+
const element = carouselMessage.content.elements[0];
|
|
43
|
+
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
44
|
+
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));
|
|
45
|
+
}
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappInteractiveMediaCarousel, { cards: carouselMessage.content.elements.map(element => {
|
|
47
|
+
const buttonText = element.button.text;
|
|
48
|
+
const buttonUrl = element.button.url;
|
|
49
|
+
const imageLink = element.image;
|
|
50
|
+
const text = FlowCarousel.generateWhatsappElementText(element);
|
|
51
|
+
return {
|
|
52
|
+
text,
|
|
53
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
54
|
+
};
|
|
55
|
+
}), textMessage: carouselMessage.content.text || DEFAULT_TEXT_MESSAGE }));
|
|
56
|
+
}
|
|
57
|
+
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));
|
|
58
|
+
}
|
|
59
|
+
toCarouselMessage(elements) {
|
|
60
|
+
return {
|
|
61
|
+
type: 'carousel',
|
|
62
|
+
content: {
|
|
63
|
+
elements: elements.map(element => {
|
|
64
|
+
var _a, _b, _c;
|
|
65
|
+
return {
|
|
66
|
+
button: {
|
|
67
|
+
text: ((_a = element.button) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
68
|
+
payload: (_b = element.button) === null || _b === void 0 ? void 0 : _b.payload,
|
|
69
|
+
url: (_c = element.button) === null || _c === void 0 ? void 0 : _c.url,
|
|
70
|
+
},
|
|
71
|
+
title: element.title,
|
|
72
|
+
subtitle: element.subtitle,
|
|
73
|
+
image: element.image,
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
toBotonic(id, request) {
|
|
80
|
+
const carouselMessage = this.toCarouselMessage(this.elements);
|
|
81
|
+
if ((0, core_1.isWhatsapp)(request.session) &&
|
|
82
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
83
|
+
if (this.elements.length === 1) {
|
|
84
|
+
const element = this.elements[0];
|
|
85
|
+
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));
|
|
86
|
+
}
|
|
87
|
+
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappInteractiveMediaCarousel, { cards: this.elements.map(element => {
|
|
88
|
+
const text = FlowCarousel.generateWhatsappElementText(element);
|
|
89
|
+
const buttonText = element.button.text;
|
|
90
|
+
const buttonUrl = element.button.url;
|
|
91
|
+
const imageLink = element.image;
|
|
92
|
+
return {
|
|
93
|
+
text,
|
|
94
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
95
|
+
};
|
|
96
|
+
}),
|
|
97
|
+
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
98
|
+
textMessage: DEFAULT_TEXT_MESSAGE }));
|
|
99
|
+
}
|
|
31
100
|
return ((0, jsx_runtime_1.jsx)(react_1.Carousel, { children: this.elements.map(element => element.toBotonic(id)) }, id));
|
|
32
101
|
}
|
|
33
102
|
}
|
|
34
103
|
exports.FlowCarousel = FlowCarousel;
|
|
104
|
+
FlowCarousel.areElementsValidForWhatsapp = (carouselMessage) => {
|
|
105
|
+
const isValid = carouselMessage.content.elements.every(element => element.button.url);
|
|
106
|
+
if (!isValid) {
|
|
107
|
+
console.warn('Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent', carouselMessage.content);
|
|
108
|
+
}
|
|
109
|
+
return isValid;
|
|
110
|
+
};
|
|
35
111
|
//# 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":["../../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{
|
|
|
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
|
});
|
|
@@ -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;IAwDvB,CAAC;IAtDC,MAAM,CAAC,cAAc,CACnB,SAA4B,EAC5B,MAAc,EACd,MAAsB;QAEtB,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAChD,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;QAChE,UAAU,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAA;QACtE,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;QACjE,UAAU,CAAC,MAAM,GAAG,wBAAU,CAAC,cAAc,CAC3C,SAAS,CAAC,MAAM,EAChB,MAAM,EACN,MAAM,CACP,CAAA;QACD,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,MAAM,CAAC,WAAW,CAChB,EAAU,EACV,OAKC;QAED,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAA;QACtC,UAAU,C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CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,UAAU,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QACtC,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,UAAU,CAAC,MAAM,GAAG,wBAAU,CAAC,WAAW,CAAC;YACzC,EAAE,EAAE,GAAG,EAAE,SAAS;YAClB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI;YACzB,GAAG,EAAE,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
|
}
|
|
@@ -53,6 +53,22 @@ class FlowText extends content_fields_base_1.ContentFieldsBase {
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
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
|
+
}
|
|
56
72
|
toBotonic(id, request) {
|
|
57
73
|
const replacedText = FlowText.replaceVariables(this.text, request);
|
|
58
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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;wBACjC,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,GAAG,EAAE,MAAM,CAAC,GAAG;wBACf,OAAO,EAAE,MAAM,CAAC,OAAO;4BACrB,CAAC,CAAC,GAAG,yBAAa,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"}
|
|
@@ -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,aA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AAQ,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"}
|
|
@@ -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,12 @@ 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 generateWhatsappElementText(element: {
|
|
14
|
+
title: string;
|
|
15
|
+
subtitle?: string;
|
|
16
|
+
}): string;
|
|
17
|
+
static fromAIAgent(id: string, carouselMessage: CarouselMessage, request: ActionRequest): JSX.Element;
|
|
18
|
+
private toCarouselMessage;
|
|
19
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element;
|
|
12
20
|
}
|
|
@@ -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);
|
|
@@ -24,8 +26,82 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
24
26
|
}
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
static generateWhatsappElementText(element) {
|
|
30
|
+
if (element.subtitle) {
|
|
31
|
+
return `*${element.title}*\n${element.subtitle}`;
|
|
32
|
+
}
|
|
33
|
+
return element.title;
|
|
34
|
+
}
|
|
35
|
+
static fromAIAgent(id, carouselMessage, request) {
|
|
36
|
+
if (isWhatsapp(request.session) &&
|
|
37
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
38
|
+
if (carouselMessage.content.elements.length === 1) {
|
|
39
|
+
const element = carouselMessage.content.elements[0];
|
|
40
|
+
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
41
|
+
return (_jsx(WhatsappCTAUrlButton, { body: element.title, headerType: WhatsappCTAUrlHeaderType.Image, headerImage: element.image, footer: element.subtitle, displayText: element.button.text, url: element.button.url }, id));
|
|
42
|
+
}
|
|
43
|
+
return (_jsx(WhatsappInteractiveMediaCarousel, { cards: carouselMessage.content.elements.map(element => {
|
|
44
|
+
const buttonText = element.button.text;
|
|
45
|
+
const buttonUrl = element.button.url;
|
|
46
|
+
const imageLink = element.image;
|
|
47
|
+
const text = FlowCarousel.generateWhatsappElementText(element);
|
|
48
|
+
return {
|
|
49
|
+
text,
|
|
50
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
51
|
+
};
|
|
52
|
+
}), textMessage: carouselMessage.content.text || DEFAULT_TEXT_MESSAGE }));
|
|
53
|
+
}
|
|
54
|
+
return (_jsx(Carousel, { children: carouselMessage.content.elements.map((element, index) => FlowElement.fromAIAgent(`${id}-element-${index}`, element).toBotonic(id)) }, id));
|
|
55
|
+
}
|
|
56
|
+
toCarouselMessage(elements) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'carousel',
|
|
59
|
+
content: {
|
|
60
|
+
elements: elements.map(element => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
return {
|
|
63
|
+
button: {
|
|
64
|
+
text: ((_a = element.button) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
65
|
+
payload: (_b = element.button) === null || _b === void 0 ? void 0 : _b.payload,
|
|
66
|
+
url: (_c = element.button) === null || _c === void 0 ? void 0 : _c.url,
|
|
67
|
+
},
|
|
68
|
+
title: element.title,
|
|
69
|
+
subtitle: element.subtitle,
|
|
70
|
+
image: element.image,
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
toBotonic(id, request) {
|
|
77
|
+
const carouselMessage = this.toCarouselMessage(this.elements);
|
|
78
|
+
if (isWhatsapp(request.session) &&
|
|
79
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)) {
|
|
80
|
+
if (this.elements.length === 1) {
|
|
81
|
+
const element = this.elements[0];
|
|
82
|
+
return (_jsx(WhatsappCTAUrlButton, { body: element.title, headerType: WhatsappCTAUrlHeaderType.Image, headerImage: element.image, displayText: element.button.text, url: element.button.url }, id));
|
|
83
|
+
}
|
|
84
|
+
return (_jsx(WhatsappInteractiveMediaCarousel, { cards: this.elements.map(element => {
|
|
85
|
+
const text = FlowCarousel.generateWhatsappElementText(element);
|
|
86
|
+
const buttonText = element.button.text;
|
|
87
|
+
const buttonUrl = element.button.url;
|
|
88
|
+
const imageLink = element.image;
|
|
89
|
+
return {
|
|
90
|
+
text,
|
|
91
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
92
|
+
};
|
|
93
|
+
}),
|
|
94
|
+
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
95
|
+
textMessage: DEFAULT_TEXT_MESSAGE }));
|
|
96
|
+
}
|
|
28
97
|
return (_jsx(Carousel, { children: this.elements.map(element => element.toBotonic(id)) }, id));
|
|
29
98
|
}
|
|
30
99
|
}
|
|
100
|
+
FlowCarousel.areElementsValidForWhatsapp = (carouselMessage) => {
|
|
101
|
+
const isValid = carouselMessage.content.elements.every(element => element.button.url);
|
|
102
|
+
if (!isValid) {
|
|
103
|
+
console.warn('Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent', carouselMessage.content);
|
|
104
|
+
}
|
|
105
|
+
return isValid;
|
|
106
|
+
};
|
|
31
107
|
//# 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,EAAE,MAAM,gBAAgB,CAAA;AAG5C,MAAM,oBAAoB,GAAG,uBAAuB,CAAA;AACpD,MAAM,OAAO,YAAa,SAAQ,iBAAiB;IAAnD;;QACS,aAAQ,GAAkB,EAAE,CAAA;IAsKrC,CAAC;IApKC,MAAM,CAAC,cAAc,CACnB,SAAyB,EACzB,MAAc,EACd,MA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K,CAAA;oBACxC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAO,CAAC,GAAI,CAAA;oBACtC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAM,CAAA;oBAEhC,OAAO;wBACL,IAAI;wBACJ,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;;AA7IM,wCAA2B,GAAG,CAAC,eAAgC,EAAE,EAAE;IACxE,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CACpD,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAC9B,CAAA;IAED,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,CAAC,IAAI,CACV,6EAA6E,EAC7E,eAAe,CAAC,OAAO,CACxB,CAAA;KACF;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -25,7 +25,7 @@ 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
|
});
|
|
@@ -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,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,CAAC,QAAQ,CAAA;QACtC,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC;YACzC,EAAE,EAAE,GAAG,EAAE,SAAS;YAClB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI;YACzB,GAAG,EAAE,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,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';
|
|
@@ -50,6 +50,22 @@ export class FlowText extends ContentFieldsBase {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
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
|
+
}
|
|
53
69
|
toBotonic(id, request) {
|
|
54
70
|
const replacedText = FlowText.replaceVariables(this.text, request);
|
|
55
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,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CAKN,CACR,CAAA;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.42.0
|
|
3
|
+
"version": "0.42.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.42.0
|
|
17
|
+
"@botonic/react": "^0.42.0",
|
|
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 <></>
|
|
@@ -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
|
|
|
@@ -32,7 +40,142 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
static areElementsValidForWhatsapp = (carouselMessage: CarouselMessage) => {
|
|
44
|
+
const isValid = carouselMessage.content.elements.every(
|
|
45
|
+
element => element.button.url
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if (!isValid) {
|
|
49
|
+
console.warn(
|
|
50
|
+
'Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent',
|
|
51
|
+
carouselMessage.content
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
return isValid
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static generateWhatsappElementText(element: {
|
|
58
|
+
title: string
|
|
59
|
+
subtitle?: string
|
|
60
|
+
}): string {
|
|
61
|
+
if (element.subtitle) {
|
|
62
|
+
return `*${element.title}*\n${element.subtitle}`
|
|
63
|
+
}
|
|
64
|
+
return element.title
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static fromAIAgent(
|
|
68
|
+
id: string,
|
|
69
|
+
carouselMessage: CarouselMessage,
|
|
70
|
+
request: ActionRequest
|
|
71
|
+
): JSX.Element {
|
|
72
|
+
if (
|
|
73
|
+
isWhatsapp(request.session) &&
|
|
74
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)
|
|
75
|
+
) {
|
|
76
|
+
if (carouselMessage.content.elements.length === 1) {
|
|
77
|
+
const element = carouselMessage.content.elements[0]
|
|
78
|
+
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
79
|
+
return (
|
|
80
|
+
<WhatsappCTAUrlButton
|
|
81
|
+
key={id}
|
|
82
|
+
body={element.title}
|
|
83
|
+
headerType={WhatsappCTAUrlHeaderType.Image}
|
|
84
|
+
headerImage={element.image}
|
|
85
|
+
footer={element.subtitle}
|
|
86
|
+
displayText={element.button.text}
|
|
87
|
+
url={element.button.url!}
|
|
88
|
+
/>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<WhatsappInteractiveMediaCarousel
|
|
94
|
+
cards={carouselMessage.content.elements.map(element => {
|
|
95
|
+
const buttonText = element.button.text
|
|
96
|
+
const buttonUrl = element.button.url!
|
|
97
|
+
const imageLink = element.image
|
|
98
|
+
const text = FlowCarousel.generateWhatsappElementText(element)
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
text,
|
|
102
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
103
|
+
}
|
|
104
|
+
})}
|
|
105
|
+
textMessage={carouselMessage.content.text || DEFAULT_TEXT_MESSAGE}
|
|
106
|
+
/>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
return (
|
|
110
|
+
<Carousel key={id}>
|
|
111
|
+
{carouselMessage.content.elements.map((element, index) =>
|
|
112
|
+
FlowElement.fromAIAgent(`${id}-element-${index}`, element).toBotonic(
|
|
113
|
+
id
|
|
114
|
+
)
|
|
115
|
+
)}
|
|
116
|
+
</Carousel>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private toCarouselMessage(elements: FlowElement[]): CarouselMessage {
|
|
121
|
+
return {
|
|
122
|
+
type: 'carousel',
|
|
123
|
+
content: {
|
|
124
|
+
elements: elements.map(element => {
|
|
125
|
+
return {
|
|
126
|
+
button: {
|
|
127
|
+
text: element.button?.text || '',
|
|
128
|
+
payload: element.button?.payload,
|
|
129
|
+
url: element.button?.url,
|
|
130
|
+
},
|
|
131
|
+
title: element.title,
|
|
132
|
+
subtitle: element.subtitle,
|
|
133
|
+
image: element.image,
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
141
|
+
const carouselMessage = this.toCarouselMessage(this.elements)
|
|
142
|
+
if (
|
|
143
|
+
isWhatsapp(request.session) &&
|
|
144
|
+
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)
|
|
145
|
+
) {
|
|
146
|
+
if (this.elements.length === 1) {
|
|
147
|
+
const element = this.elements[0]
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<WhatsappCTAUrlButton
|
|
151
|
+
key={id}
|
|
152
|
+
body={element.title}
|
|
153
|
+
headerType={WhatsappCTAUrlHeaderType.Image}
|
|
154
|
+
headerImage={element.image}
|
|
155
|
+
displayText={element.button!.text}
|
|
156
|
+
url={element.button!.url!}
|
|
157
|
+
/>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<WhatsappInteractiveMediaCarousel
|
|
163
|
+
cards={this.elements.map(element => {
|
|
164
|
+
const text = FlowCarousel.generateWhatsappElementText(element)
|
|
165
|
+
const buttonText = element.button!.text!
|
|
166
|
+
const buttonUrl = element.button!.url!
|
|
167
|
+
const imageLink = element.image!
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
text,
|
|
171
|
+
action: { buttonText, buttonUrl, imageLink },
|
|
172
|
+
}
|
|
173
|
+
})}
|
|
174
|
+
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
175
|
+
textMessage={DEFAULT_TEXT_MESSAGE}
|
|
176
|
+
/>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
36
179
|
return (
|
|
37
180
|
<Carousel key={id}>
|
|
38
181
|
{this.elements.map(element => element.toBotonic(id))}
|
|
@@ -44,7 +44,7 @@ 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
|
})
|
|
@@ -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'
|
|
@@ -64,6 +70,32 @@ export class FlowText extends ContentFieldsBase {
|
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
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
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
67
99
|
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
68
100
|
const replacedText = FlowText.replaceVariables(this.text, request)
|
|
69
101
|
return (
|