@botonic/plugin-flow-builder 0.42.5 → 0.43.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/action/payload.js +29 -2
- package/lib/cjs/action/payload.js.map +1 -1
- package/lib/cjs/api.d.ts +2 -0
- package/lib/cjs/api.js +11 -1
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +2 -1
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/content-fields-base.d.ts +2 -0
- package/lib/cjs/content-fields/content-fields-base.js +21 -0
- package/lib/cjs/content-fields/content-fields-base.js.map +1 -1
- package/lib/cjs/content-fields/flow-carousel.d.ts +2 -0
- package/lib/cjs/content-fields/flow-carousel.js +70 -27
- package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
- package/lib/cjs/content-fields/flow-text.d.ts +0 -2
- package/lib/cjs/content-fields/flow-text.js +1 -21
- package/lib/cjs/content-fields/flow-text.js.map +1 -1
- package/lib/cjs/content-fields/flow-whatsapp-template.d.ts +28 -0
- package/lib/cjs/content-fields/flow-whatsapp-template.js +163 -0
- package/lib/cjs/content-fields/flow-whatsapp-template.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/carousel.d.ts +1 -0
- package/lib/cjs/content-fields/hubtype-fields/common.d.ts +6 -0
- package/lib/cjs/content-fields/hubtype-fields/index.d.ts +1 -0
- package/lib/cjs/content-fields/hubtype-fields/index.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/cjs/content-fields/hubtype-fields/whatsapp-template.d.ts +66 -0
- package/lib/cjs/content-fields/hubtype-fields/whatsapp-template.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/whatsapp-template.js.map +1 -0
- package/lib/cjs/content-fields/index.d.ts +3 -2
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/flow-factory.js +2 -0
- package/lib/cjs/flow-factory.js.map +1 -1
- package/lib/esm/action/payload.js +30 -3
- package/lib/esm/action/payload.js.map +1 -1
- package/lib/esm/api.d.ts +2 -0
- package/lib/esm/api.js +11 -1
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +2 -1
- package/lib/esm/constants.js +2 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/content-fields-base.d.ts +2 -0
- package/lib/esm/content-fields/content-fields-base.js +21 -0
- package/lib/esm/content-fields/content-fields-base.js.map +1 -1
- package/lib/esm/content-fields/flow-carousel.d.ts +2 -0
- package/lib/esm/content-fields/flow-carousel.js +72 -29
- package/lib/esm/content-fields/flow-carousel.js.map +1 -1
- package/lib/esm/content-fields/flow-text.d.ts +0 -2
- package/lib/esm/content-fields/flow-text.js +2 -22
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/lib/esm/content-fields/flow-whatsapp-template.d.ts +28 -0
- package/lib/esm/content-fields/flow-whatsapp-template.js +159 -0
- package/lib/esm/content-fields/flow-whatsapp-template.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/carousel.d.ts +1 -0
- package/lib/esm/content-fields/hubtype-fields/common.d.ts +6 -0
- package/lib/esm/content-fields/hubtype-fields/index.d.ts +1 -0
- package/lib/esm/content-fields/hubtype-fields/index.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/esm/content-fields/hubtype-fields/whatsapp-template.d.ts +66 -0
- package/lib/esm/content-fields/hubtype-fields/whatsapp-template.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/whatsapp-template.js.map +1 -0
- package/lib/esm/content-fields/index.d.ts +3 -2
- package/lib/esm/content-fields/index.js +2 -1
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/flow-factory.js +3 -1
- package/lib/esm/flow-factory.js.map +1 -1
- package/package.json +3 -3
- package/src/action/payload.ts +39 -1
- package/src/api.ts +14 -1
- package/src/constants.ts +2 -1
- package/src/content-fields/content-fields-base.ts +31 -0
- package/src/content-fields/flow-carousel.tsx +103 -33
- package/src/content-fields/flow-text.tsx +2 -28
- package/src/content-fields/flow-whatsapp-template.tsx +274 -0
- package/src/content-fields/hubtype-fields/carousel.ts +1 -0
- package/src/content-fields/hubtype-fields/common.ts +7 -0
- package/src/content-fields/hubtype-fields/index.ts +1 -0
- package/src/content-fields/hubtype-fields/node-types.ts +1 -0
- package/src/content-fields/hubtype-fields/nodes.ts +2 -0
- package/src/content-fields/hubtype-fields/whatsapp-template.ts +84 -0
- package/src/content-fields/index.ts +3 -0
- package/src/flow-factory.ts +4 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WhatsAppTemplateButtonSubType, WhatsAppTemplateComponentType, WhatsAppTemplateParameterType } from '@botonic/react';
|
|
2
|
+
import { HtButton } from './button';
|
|
3
|
+
import { HtBaseNode, HtMediaFileLocale } from './common';
|
|
4
|
+
import { HtNodeWithContentType } from './node-types';
|
|
5
|
+
type HtWhatsAppTemplateButton = {
|
|
6
|
+
type: WhatsAppTemplateButtonSubType.URL;
|
|
7
|
+
text: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
index: number;
|
|
10
|
+
} | {
|
|
11
|
+
type: WhatsAppTemplateButtonSubType.QUICK_REPLY;
|
|
12
|
+
text: string;
|
|
13
|
+
id: string;
|
|
14
|
+
index: number;
|
|
15
|
+
} | {
|
|
16
|
+
type: WhatsAppTemplateButtonSubType.PHONE_NUMBER;
|
|
17
|
+
text: string;
|
|
18
|
+
phone_number: string;
|
|
19
|
+
index: number;
|
|
20
|
+
};
|
|
21
|
+
export interface HtWhatsAppTemplateHeaderComponent {
|
|
22
|
+
type: WhatsAppTemplateComponentType.HEADER;
|
|
23
|
+
format: WhatsAppTemplateParameterType.TEXT | WhatsAppTemplateParameterType.IMAGE;
|
|
24
|
+
text?: string;
|
|
25
|
+
image?: {
|
|
26
|
+
link: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface HtWhatsAppTemplateBodyComponent {
|
|
30
|
+
type: WhatsAppTemplateComponentType.BODY;
|
|
31
|
+
text: string;
|
|
32
|
+
}
|
|
33
|
+
export interface HtWhatsAppTemplateFooterComponent {
|
|
34
|
+
type: WhatsAppTemplateComponentType.FOOTER;
|
|
35
|
+
text: string;
|
|
36
|
+
}
|
|
37
|
+
export interface HtWhatsAppTemplateButtonsComponent {
|
|
38
|
+
type: WhatsAppTemplateComponentType.BUTTONS;
|
|
39
|
+
buttons: HtWhatsAppTemplateButton[];
|
|
40
|
+
}
|
|
41
|
+
export type HtWhatsAppTemplateComponent = HtWhatsAppTemplateHeaderComponent | HtWhatsAppTemplateBodyComponent | HtWhatsAppTemplateFooterComponent | HtWhatsAppTemplateButtonsComponent;
|
|
42
|
+
export interface HtWhatsAppTemplate {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
language: string;
|
|
46
|
+
status: string;
|
|
47
|
+
category: string;
|
|
48
|
+
components: HtWhatsAppTemplateComponent[];
|
|
49
|
+
namespace: string;
|
|
50
|
+
parameter_format: string;
|
|
51
|
+
}
|
|
52
|
+
export interface HtWhatsappTemplateNode extends HtBaseNode {
|
|
53
|
+
type: HtNodeWithContentType.WHATSAPP_TEMPLATE;
|
|
54
|
+
content: {
|
|
55
|
+
template: HtWhatsAppTemplate;
|
|
56
|
+
header_variables?: {
|
|
57
|
+
type: WhatsAppTemplateParameterType;
|
|
58
|
+
text?: Record<string, string>;
|
|
59
|
+
media?: HtMediaFileLocale[];
|
|
60
|
+
};
|
|
61
|
+
variable_values: Record<string, string>;
|
|
62
|
+
buttons: HtButton[];
|
|
63
|
+
url_variable_values?: Record<string, string>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whatsapp-template.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/whatsapp-template.ts"],"names":[],"mappings":""}
|
|
@@ -13,10 +13,11 @@ import { FlowRating } from './flow-rating';
|
|
|
13
13
|
import { FlowText } from './flow-text';
|
|
14
14
|
import { FlowVideo } from './flow-video';
|
|
15
15
|
import { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button';
|
|
16
|
+
import { FlowWhatsappTemplate } from './flow-whatsapp-template';
|
|
16
17
|
import { FlowWhatsappButtonList } from './whatsapp-button-list/flow-whatsapp-button-list';
|
|
17
18
|
export { ContentFieldsBase } from './content-fields-base';
|
|
18
19
|
export { FlowButton } from './flow-button';
|
|
19
20
|
export { FlowElement } from './flow-element';
|
|
20
|
-
export { FlowAiAgent, FlowBotAction, FlowCarousel, FlowChannelConditional, FlowCountryConditional, FlowCustomConditional, FlowGoToFlow, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, };
|
|
21
|
-
export type FlowContent = FlowCarousel | FlowImage | FlowText | FlowVideo | FlowWhatsappButtonList | FlowWhatsappCtaUrlButtonNode | FlowHandoff | FlowKnowledgeBase | FlowBotAction | FlowAiAgent | FlowRating | FlowCountryConditional | FlowChannelConditional | FlowQueueStatusConditional | FlowCustomConditional | FlowGoToFlow;
|
|
21
|
+
export { FlowAiAgent, FlowBotAction, FlowCarousel, FlowChannelConditional, FlowCountryConditional, FlowCustomConditional, FlowGoToFlow, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, FlowWhatsappTemplate, };
|
|
22
|
+
export type FlowContent = FlowCarousel | FlowImage | FlowText | FlowVideo | FlowWhatsappButtonList | FlowWhatsappCtaUrlButtonNode | FlowWhatsappTemplate | FlowHandoff | FlowKnowledgeBase | FlowBotAction | FlowAiAgent | FlowRating | FlowCountryConditional | FlowChannelConditional | FlowQueueStatusConditional | FlowCustomConditional | FlowGoToFlow;
|
|
22
23
|
export { DISABLED_MEMORY_LENGTH };
|
|
@@ -13,10 +13,11 @@ import { FlowRating } from './flow-rating';
|
|
|
13
13
|
import { FlowText } from './flow-text';
|
|
14
14
|
import { FlowVideo } from './flow-video';
|
|
15
15
|
import { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button';
|
|
16
|
+
import { FlowWhatsappTemplate } from './flow-whatsapp-template';
|
|
16
17
|
import { FlowWhatsappButtonList } from './whatsapp-button-list/flow-whatsapp-button-list';
|
|
17
18
|
export { ContentFieldsBase } from './content-fields-base';
|
|
18
19
|
export { FlowButton } from './flow-button';
|
|
19
20
|
export { FlowElement } from './flow-element';
|
|
20
|
-
export { FlowAiAgent, FlowBotAction, FlowCarousel, FlowChannelConditional, FlowCountryConditional, FlowCustomConditional, FlowGoToFlow, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, };
|
|
21
|
+
export { FlowAiAgent, FlowBotAction, FlowCarousel, FlowChannelConditional, FlowCountryConditional, FlowCustomConditional, FlowGoToFlow, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, FlowWhatsappTemplate, };
|
|
21
22
|
export { DISABLED_MEMORY_LENGTH };
|
|
22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,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,EACV,QAAQ,EACR,SAAS,EACT,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,GACrB,CAAA;AAqBD,OAAO,EAAE,sBAAsB,EAAE,CAAA"}
|
package/lib/esm/flow-factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { FlowAiAgent, FlowBotAction, FlowCarousel, FlowChannelConditional, FlowCountryConditional, FlowCustomConditional, FlowGoToFlow, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, } from './content-fields';
|
|
2
|
+
import { FlowAiAgent, FlowBotAction, FlowCarousel, FlowChannelConditional, FlowCountryConditional, FlowCustomConditional, FlowGoToFlow, FlowHandoff, FlowImage, FlowKnowledgeBase, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappCtaUrlButtonNode, FlowWhatsappTemplate, } from './content-fields';
|
|
3
3
|
import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
|
|
4
4
|
export class FlowFactory {
|
|
5
5
|
constructor(request, cmsApi, locale) {
|
|
@@ -36,6 +36,8 @@ export class FlowFactory {
|
|
|
36
36
|
return this.resolveFlowFunctionContent(hubtypeContent);
|
|
37
37
|
case HtNodeWithContentType.GO_TO_FLOW:
|
|
38
38
|
return FlowGoToFlow.fromHubtypeCMS(hubtypeContent, this.cmsApi);
|
|
39
|
+
case HtNodeWithContentType.WHATSAPP_TEMPLATE:
|
|
40
|
+
return FlowWhatsappTemplate.fromHubtypeCMS(hubtypeContent);
|
|
39
41
|
default:
|
|
40
42
|
return undefined;
|
|
41
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-factory.js","sourceRoot":"","sources":["../../src/flow-factory.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,sBAAsB,EAEtB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,EACV,QAAQ,EACR,SAAS,EACT,sBAAsB,EACtB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"flow-factory.js","sourceRoot":"","sources":["../../src/flow-factory.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,sBAAsB,EAEtB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,EACV,QAAQ,EACR,SAAS,EACT,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAGL,qBAAqB,GACtB,MAAM,iCAAiC,CAAA;AAExC,MAAM,OAAO,WAAW;IAKtB,YAAY,OAAsB,EAAE,MAAsB,EAAE,MAAc;QACxE,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEK,cAAc,CAClB,cAA+B;;YAE/B,QAAQ,cAAc,CAAC,IAAI,EAAE;gBAC3B,KAAK,qBAAqB,CAAC,IAAI;oBAC7B,OAAO,QAAQ,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;gBAC1E,KAAK,qBAAqB,CAAC,KAAK;oBAC9B,OAAO,SAAS,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CA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Y,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;gBAEjE,KAAK,qBAAqB,CAAC,iBAAiB;oBAC1C,OAAO,oBAAoB,CAAC,cAAc,CAAC,cAAc,CAAC,CAAA;gBAE5D;oBACE,OAAO,SAAS,CAAA;aACnB;QACH,CAAC;KAAA;IAEa,0BAA0B,CACtC,cAA8B;;YAE9B,QAAQ,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE;gBACrC,KAAK,eAAe;oBAClB,OAAO,sBAAsB,CAAC,cAAc,CAC1C,cAAc,EACd,IAAI,CAAC,cAAc,CACpB,CAAA;gBACH,KAAK,kBAAkB;oBACrB,OAAO,sBAAsB,CAAC,cAAc,CAC1C,cAAc,EACd,IAAI,CAAC,cAAc,CACpB,CAAA;gBACH,KAAK,oBAAoB;oBACvB,OAAO,0BAA0B,CAAC,cAAc,CAC9C,cAAc,EACd,IAAI,CAAC,MAAM,CACZ,CAAA;gBACH,KAAK,oBAAoB;oBACvB,OAAO,qBAAqB,CAAC,cAAc,CACzC,cAAc,EACd,IAAI,CAAC,cAAc,CACpB,CAAA;gBACH;oBACE,OAAO,SAAS,CAAA;aACnB;QACH,CAAC;KAAA;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0-alpha.1",
|
|
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": "
|
|
17
|
+
"@botonic/react": "0.43.0-alpha.1",
|
|
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
|
+
}
|
package/src/action/payload.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { EventAction, EventFeedback, storeCaseRating } from '@botonic/core'
|
|
2
2
|
import { v7 as uuid } from 'uuid'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AGENT_RATING_PAYLOAD,
|
|
6
|
+
PUSH_FLOW_PAYLOAD,
|
|
7
|
+
SEPARATOR,
|
|
8
|
+
} from '../constants'
|
|
5
9
|
import { FlowContent } from '../content-fields'
|
|
6
10
|
import { HtNodeWithContent } from '../content-fields/hubtype-fields'
|
|
7
11
|
import { trackEvent } from '../tracking'
|
|
@@ -14,6 +18,9 @@ export async function getContentsByPayload(
|
|
|
14
18
|
if (request.input.payload?.startsWith(AGENT_RATING_PAYLOAD)) {
|
|
15
19
|
return await resolveRatingPayload(context)
|
|
16
20
|
}
|
|
21
|
+
if (request.input.payload?.startsWith(PUSH_FLOW_PAYLOAD)) {
|
|
22
|
+
return await resolvePushFlowPayload(context)
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
const id = contentID
|
|
19
26
|
? cmsApi.getNodeByContentID(contentID)?.id
|
|
@@ -64,3 +71,34 @@ async function resolveRatingPayload(
|
|
|
64
71
|
|
|
65
72
|
return []
|
|
66
73
|
}
|
|
74
|
+
|
|
75
|
+
async function resolvePushFlowPayload(
|
|
76
|
+
context: FlowBuilderContext
|
|
77
|
+
): Promise<FlowContent[]> {
|
|
78
|
+
const { cmsApi, flowBuilderPlugin, request } = context
|
|
79
|
+
|
|
80
|
+
if (!request.input.payload) {
|
|
81
|
+
return []
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const parts = request.input.payload.split(SEPARATOR)
|
|
85
|
+
const pushFlowId = parts.length > 1 ? parts[1] : ''
|
|
86
|
+
|
|
87
|
+
if (!pushFlowId) {
|
|
88
|
+
return []
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const pushFlowNode =
|
|
93
|
+
cmsApi.getNodeByCampaignId<HtNodeWithContent>(pushFlowId)
|
|
94
|
+
|
|
95
|
+
if (!pushFlowNode) {
|
|
96
|
+
return []
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return await flowBuilderPlugin.getContentsByNode(pushFlowNode)
|
|
100
|
+
} catch {
|
|
101
|
+
// Campaign not found - return empty to trigger fallback
|
|
102
|
+
return []
|
|
103
|
+
}
|
|
104
|
+
}
|
package/src/api.ts
CHANGED
|
@@ -73,6 +73,12 @@ export class FlowBuilderApi {
|
|
|
73
73
|
return this.getNodeById<HtNodeWithContent>(subFlow.start_node_id)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
getNodeByCampaignId<T extends HtNodeComponent>(id: string): T {
|
|
77
|
+
const campaign = this.flow.campaigns.find(campaign => campaign.id === id)
|
|
78
|
+
if (!campaign) throw Error(`Campaign with id: '${id}' not found`)
|
|
79
|
+
return this.getNodeById<T>(campaign.start_node_id)
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
getNodeById<T extends HtNodeComponent>(id: string): T {
|
|
77
83
|
const node = this.flow.nodes.find(node => node.id === id)
|
|
78
84
|
if (!node) console.error(`Node with id: '${id}' not found`)
|
|
@@ -215,7 +221,14 @@ export class FlowBuilderApi {
|
|
|
215
221
|
|
|
216
222
|
getFlowName(flowId: string): string {
|
|
217
223
|
const flow = this.flow.flows.find(flow => flow.id === flowId)
|
|
218
|
-
return flow ? flow.name :
|
|
224
|
+
return flow ? flow.name : this.getCampaignFlowName(flowId)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getCampaignFlowName(campaignId: string): string {
|
|
228
|
+
const campaign = this.flow.campaigns.find(
|
|
229
|
+
campaign => campaign.id === campaignId
|
|
230
|
+
)
|
|
231
|
+
return campaign ? campaign.name : ''
|
|
219
232
|
}
|
|
220
233
|
|
|
221
234
|
getStartNodeKnowledgeBaseFlow(): HtNodeWithContent | undefined {
|
package/src/constants.ts
CHANGED
|
@@ -3,7 +3,7 @@ export const FLOW_BUILDER_API_URL_PROD =
|
|
|
3
3
|
export const SEPARATOR = '|'
|
|
4
4
|
export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`
|
|
5
5
|
export const EMPTY_PAYLOAD = 'fb-empty-payload'
|
|
6
|
-
export const
|
|
6
|
+
export const VARIABLE_PATTERN_GLOBAL = /{([^}]+)}/g
|
|
7
7
|
export const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'
|
|
8
8
|
export const REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/
|
|
9
9
|
export const UUID_REGEXP =
|
|
@@ -11,6 +11,7 @@ export const UUID_REGEXP =
|
|
|
11
11
|
|
|
12
12
|
/* ********** PAYLOADS ********** */
|
|
13
13
|
export const AGENT_RATING_PAYLOAD = 'agent-rating'
|
|
14
|
+
export const PUSH_FLOW_PAYLOAD = 'push-flow'
|
|
14
15
|
|
|
15
16
|
/* ********** FLOW NAMES ********** */
|
|
16
17
|
export const MAIN_FLOW_NAME = 'Main'
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react'
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
ACCESS_TOKEN_VARIABLE_KEY,
|
|
5
|
+
VARIABLE_PATTERN_GLOBAL,
|
|
6
|
+
} from '../constants'
|
|
7
|
+
import { getValueFromKeyPath } from '../utils'
|
|
3
8
|
import {
|
|
4
9
|
HtMediaFileLocale,
|
|
5
10
|
HtNodeLink,
|
|
@@ -37,4 +42,30 @@ export abstract class ContentFieldsBase {
|
|
|
37
42
|
): HtQueueLocale | undefined {
|
|
38
43
|
return queues.find(queue => queue.locale === locale)
|
|
39
44
|
}
|
|
45
|
+
|
|
46
|
+
replaceVariables(text: string, request: ActionRequest): string {
|
|
47
|
+
const matches = text.match(VARIABLE_PATTERN_GLOBAL)
|
|
48
|
+
|
|
49
|
+
let replacedText = text
|
|
50
|
+
if (matches && request) {
|
|
51
|
+
matches.forEach(match => {
|
|
52
|
+
const keyPath = match.slice(1, -1)
|
|
53
|
+
const botVariable = keyPath.endsWith(ACCESS_TOKEN_VARIABLE_KEY)
|
|
54
|
+
? match
|
|
55
|
+
: getValueFromKeyPath(request, keyPath)
|
|
56
|
+
// TODO In local if change variable and render multiple times the value is always the last update
|
|
57
|
+
replacedText = replacedText.replace(
|
|
58
|
+
match,
|
|
59
|
+
this.isValidType(botVariable) ? botVariable : match
|
|
60
|
+
)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return replacedText
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private isValidType(botVariable: any): boolean {
|
|
68
|
+
const validTypes = ['boolean', 'string', 'number']
|
|
69
|
+
return validTypes.includes(typeof botVariable)
|
|
70
|
+
}
|
|
40
71
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { CarouselMessage, isWhatsapp } from '@botonic/core'
|
|
2
2
|
import {
|
|
3
3
|
ActionRequest,
|
|
4
|
+
Button,
|
|
5
|
+
CardType,
|
|
4
6
|
Carousel,
|
|
7
|
+
Text,
|
|
5
8
|
WhatsappCTAUrlButton,
|
|
6
9
|
WhatsappCTAUrlHeaderType,
|
|
10
|
+
WhatsappInteractiveMediaCard,
|
|
7
11
|
WhatsappInteractiveMediaCarousel,
|
|
8
12
|
} from '@botonic/react'
|
|
9
13
|
import React from 'react'
|
|
@@ -16,6 +20,7 @@ import { HtCarouselNode } from './hubtype-fields'
|
|
|
16
20
|
|
|
17
21
|
const DEFAULT_TEXT_MESSAGE = 'These are the options'
|
|
18
22
|
export class FlowCarousel extends ContentFieldsBase {
|
|
23
|
+
public whatsappText: string = ''
|
|
19
24
|
public elements: FlowElement[] = []
|
|
20
25
|
|
|
21
26
|
static fromHubtypeCMS(
|
|
@@ -28,6 +33,10 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
28
33
|
newCarousel.elements = component.content.elements.map(element =>
|
|
29
34
|
FlowElement.fromHubtypeCMS(element, locale, cmsApi)
|
|
30
35
|
)
|
|
36
|
+
newCarousel.whatsappText = this.getTextByLocale(
|
|
37
|
+
locale,
|
|
38
|
+
component.content.whatsapp_text
|
|
39
|
+
)
|
|
31
40
|
newCarousel.followUp = component.follow_up
|
|
32
41
|
|
|
33
42
|
return newCarousel
|
|
@@ -41,13 +50,13 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
static areElementsValidForWhatsapp = (carouselMessage: CarouselMessage) => {
|
|
44
|
-
const isValid =
|
|
45
|
-
element => element.button.url
|
|
46
|
-
|
|
53
|
+
const isValid =
|
|
54
|
+
carouselMessage.content.elements.every(element => element.button.url) ||
|
|
55
|
+
carouselMessage.content.elements.every(element => element.button.payload)
|
|
47
56
|
|
|
48
57
|
if (!isValid) {
|
|
49
58
|
console.warn(
|
|
50
|
-
'Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent',
|
|
59
|
+
'Cannot use WhatsappInteractiveMediaCarousel for Whatsapp created by AIAgent, all elements must have either url or payload.',
|
|
51
60
|
carouselMessage.content
|
|
52
61
|
)
|
|
53
62
|
}
|
|
@@ -64,6 +73,42 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
64
73
|
return element.title
|
|
65
74
|
}
|
|
66
75
|
|
|
76
|
+
private static createCardsFromElements(
|
|
77
|
+
elements: FlowElement[]
|
|
78
|
+
): WhatsappInteractiveMediaCard[] {
|
|
79
|
+
return elements.map(element => {
|
|
80
|
+
const text = FlowCarousel.generateWhatsappElementText(element)
|
|
81
|
+
|
|
82
|
+
if (element.button?.url) {
|
|
83
|
+
return {
|
|
84
|
+
imageLink: element.image,
|
|
85
|
+
text,
|
|
86
|
+
type: CardType.CTA_URL as const,
|
|
87
|
+
action: {
|
|
88
|
+
buttonText: element.button.text,
|
|
89
|
+
buttonUrl: element.button.url,
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (element.button?.payload) {
|
|
94
|
+
return {
|
|
95
|
+
imageLink: element.image,
|
|
96
|
+
text,
|
|
97
|
+
type: CardType.QUICK_REPLY as const,
|
|
98
|
+
action: {
|
|
99
|
+
buttons: [
|
|
100
|
+
{
|
|
101
|
+
text: element.button.text,
|
|
102
|
+
payload: element.button.payload,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
throw new Error('Element must have a url or a payload')
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
67
112
|
static fromAIAgent(
|
|
68
113
|
id: string,
|
|
69
114
|
carouselMessage: CarouselMessage,
|
|
@@ -73,8 +118,13 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
73
118
|
isWhatsapp(request.session) &&
|
|
74
119
|
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)
|
|
75
120
|
) {
|
|
76
|
-
if (
|
|
121
|
+
if (
|
|
122
|
+
carouselMessage.content.elements.length === 1 &&
|
|
123
|
+
carouselMessage.content.elements[0].button?.url
|
|
124
|
+
) {
|
|
77
125
|
const element = carouselMessage.content.elements[0]
|
|
126
|
+
const buttonText = element.button.text
|
|
127
|
+
const url = carouselMessage.content.elements[0].button.url
|
|
78
128
|
// TODO: Add a new fromAIAgent method in FlowWhatsappCtaUrlButtonNode to create a WhatsappCTAUrlButton from an AIAgent message
|
|
79
129
|
return (
|
|
80
130
|
<WhatsappCTAUrlButton
|
|
@@ -83,25 +133,35 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
83
133
|
headerType={WhatsappCTAUrlHeaderType.Image}
|
|
84
134
|
headerImage={element.image}
|
|
85
135
|
footer={element.subtitle}
|
|
86
|
-
displayText={
|
|
87
|
-
url={
|
|
136
|
+
displayText={buttonText}
|
|
137
|
+
url={url}
|
|
88
138
|
/>
|
|
89
139
|
)
|
|
90
140
|
}
|
|
91
141
|
|
|
142
|
+
if (
|
|
143
|
+
carouselMessage.content.elements.length === 1 &&
|
|
144
|
+
carouselMessage.content.elements[0].button?.payload
|
|
145
|
+
) {
|
|
146
|
+
const element = carouselMessage.content.elements[0]
|
|
147
|
+
const text = FlowCarousel.generateWhatsappElementText(element)
|
|
148
|
+
const buttonPayload = carouselMessage.content.elements[0].button.payload
|
|
149
|
+
const buttonText = carouselMessage.content.elements[0].button.text
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<Text>
|
|
153
|
+
{text}
|
|
154
|
+
<Button payload={buttonPayload}>{buttonText}</Button>
|
|
155
|
+
</Text>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const elements = carouselMessage.content.elements.map((element, index) =>
|
|
160
|
+
FlowElement.fromAIAgent(`${id}-element-${index}`, element)
|
|
161
|
+
)
|
|
92
162
|
return (
|
|
93
163
|
<WhatsappInteractiveMediaCarousel
|
|
94
|
-
cards={
|
|
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
|
-
})}
|
|
164
|
+
cards={FlowCarousel.createCardsFromElements(elements)}
|
|
105
165
|
textMessage={carouselMessage.content.text || DEFAULT_TEXT_MESSAGE}
|
|
106
166
|
/>
|
|
107
167
|
)
|
|
@@ -143,8 +203,10 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
143
203
|
isWhatsapp(request.session) &&
|
|
144
204
|
FlowCarousel.areElementsValidForWhatsapp(carouselMessage)
|
|
145
205
|
) {
|
|
146
|
-
if (this.elements.length === 1) {
|
|
206
|
+
if (this.elements.length === 1 && this.elements[0].button?.url) {
|
|
147
207
|
const element = this.elements[0]
|
|
208
|
+
const buttonText = this.elements[0].button.text
|
|
209
|
+
const url = this.elements[0].button.url
|
|
148
210
|
|
|
149
211
|
return (
|
|
150
212
|
<WhatsappCTAUrlButton
|
|
@@ -152,27 +214,35 @@ export class FlowCarousel extends ContentFieldsBase {
|
|
|
152
214
|
body={element.title}
|
|
153
215
|
headerType={WhatsappCTAUrlHeaderType.Image}
|
|
154
216
|
headerImage={element.image}
|
|
155
|
-
displayText={
|
|
156
|
-
url={
|
|
217
|
+
displayText={buttonText}
|
|
218
|
+
url={url}
|
|
157
219
|
/>
|
|
158
220
|
)
|
|
159
221
|
}
|
|
160
222
|
|
|
223
|
+
if (
|
|
224
|
+
this.elements.length === 1 &&
|
|
225
|
+
this.elements[0].button &&
|
|
226
|
+
this.elements[0].button?.payload
|
|
227
|
+
) {
|
|
228
|
+
const element = this.elements[0]
|
|
229
|
+
const text = FlowCarousel.generateWhatsappElementText(element)
|
|
230
|
+
const buttonPayload = this.elements[0].button.payload
|
|
231
|
+
const buttonText = this.elements[0].button.text
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<Text>
|
|
235
|
+
{text}
|
|
236
|
+
<Button payload={buttonPayload}>{buttonText}</Button>
|
|
237
|
+
</Text>
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
|
|
161
241
|
return (
|
|
162
242
|
<WhatsappInteractiveMediaCarousel
|
|
163
|
-
cards={this.elements
|
|
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
|
-
})}
|
|
243
|
+
cards={FlowCarousel.createCardsFromElements(this.elements)}
|
|
174
244
|
// TODO: Add the text message in flow builder frontend and take it from the carousel node with different languages
|
|
175
|
-
textMessage={DEFAULT_TEXT_MESSAGE}
|
|
245
|
+
textMessage={this.whatsappText || DEFAULT_TEXT_MESSAGE}
|
|
176
246
|
/>
|
|
177
247
|
)
|
|
178
248
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
ACCESS_TOKEN_VARIABLE_KEY,
|
|
8
8
|
EMPTY_PAYLOAD,
|
|
9
9
|
SOURCE_INFO_SEPARATOR,
|
|
10
|
-
|
|
10
|
+
VARIABLE_PATTERN_GLOBAL,
|
|
11
11
|
} from '../constants'
|
|
12
12
|
import { trackOneContent } from '../tracking'
|
|
13
13
|
import { getValueFromKeyPath } from '../utils'
|
|
@@ -37,32 +37,6 @@ export class FlowText extends ContentFieldsBase {
|
|
|
37
37
|
return newText
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
static replaceVariables(text: string, request: ActionRequest): string {
|
|
41
|
-
const matches = text.match(VARIABLE_PATTERN)
|
|
42
|
-
|
|
43
|
-
let replacedText = text
|
|
44
|
-
if (matches && request) {
|
|
45
|
-
matches.forEach(match => {
|
|
46
|
-
const keyPath = match.slice(1, -1)
|
|
47
|
-
const botVariable = keyPath.endsWith(ACCESS_TOKEN_VARIABLE_KEY)
|
|
48
|
-
? match
|
|
49
|
-
: getValueFromKeyPath(request, keyPath)
|
|
50
|
-
// TODO In local if change variable and render multiple times the value is always the last update
|
|
51
|
-
replacedText = replacedText.replace(
|
|
52
|
-
match,
|
|
53
|
-
this.isValidType(botVariable) ? botVariable : match
|
|
54
|
-
)
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return replacedText
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private static isValidType(botVariable: any): boolean {
|
|
62
|
-
const validTypes = ['boolean', 'string', 'number']
|
|
63
|
-
return validTypes.includes(typeof botVariable)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
40
|
async trackFlow(request: ActionRequest): Promise<void> {
|
|
67
41
|
await trackOneContent(request, this)
|
|
68
42
|
for (const button of this.buttons) {
|
|
@@ -97,7 +71,7 @@ export class FlowText extends ContentFieldsBase {
|
|
|
97
71
|
}
|
|
98
72
|
|
|
99
73
|
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
100
|
-
const replacedText =
|
|
74
|
+
const replacedText = this.replaceVariables(this.text, request)
|
|
101
75
|
return (
|
|
102
76
|
<Text key={id}>
|
|
103
77
|
{replacedText}
|