@botonic/plugin-flow-builder 0.52.0 → 0.53.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-whatsapp-template.d.ts +6 -1
- package/lib/cjs/content-fields/flow-whatsapp-template.js +90 -25
- package/lib/cjs/content-fields/flow-whatsapp-template.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/whatsapp-template.d.ts +22 -2
- package/lib/cjs/content-fields/hubtype-fields/whatsapp-template.js +6 -0
- package/lib/cjs/content-fields/hubtype-fields/whatsapp-template.js.map +1 -1
- package/lib/esm/content-fields/flow-whatsapp-template.d.ts +6 -1
- package/lib/esm/content-fields/flow-whatsapp-template.js +90 -25
- package/lib/esm/content-fields/flow-whatsapp-template.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/whatsapp-template.d.ts +22 -2
- package/lib/esm/content-fields/hubtype-fields/whatsapp-template.js +6 -0
- package/lib/esm/content-fields/hubtype-fields/whatsapp-template.js.map +1 -1
- package/package.json +3 -3
- package/src/content-fields/flow-whatsapp-template.tsx +171 -34
- package/src/content-fields/hubtype-fields/whatsapp-template.ts +26 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BotContext } from '@botonic/core';
|
|
2
2
|
import { WhatsAppTemplateParameterType } from '@botonic/react';
|
|
3
3
|
import { ContentFieldsBase } from './content-fields-base';
|
|
4
|
-
import type
|
|
4
|
+
import { type HtButton, type HtFlowButtonActionValue, type HtMediaFileLocale, type HtWhatsAppTemplate, type HtWhatsappTemplateNode } from './hubtype-fields';
|
|
5
5
|
interface HeaderVariables {
|
|
6
6
|
type: WhatsAppTemplateParameterType;
|
|
7
7
|
text?: Record<string, string>;
|
|
@@ -13,6 +13,7 @@ export declare class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
13
13
|
headerVariables?: HeaderVariables;
|
|
14
14
|
buttons?: HtButton[];
|
|
15
15
|
urlVariableValues?: Record<string, string>;
|
|
16
|
+
flowButtonActionValues?: Record<string, HtFlowButtonActionValue>;
|
|
16
17
|
static fromHubtypeCMS(component: HtWhatsappTemplateNode, currentLocale: string): FlowWhatsappTemplate;
|
|
17
18
|
private static getContentByLocale;
|
|
18
19
|
private getHeaderComponent;
|
|
@@ -21,9 +22,13 @@ export declare class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
21
22
|
private createHeaderVideoComponent;
|
|
22
23
|
private getBodyComponent;
|
|
23
24
|
private getButtons;
|
|
25
|
+
private mapTemplateButton;
|
|
24
26
|
private createUrlButtonComponent;
|
|
25
27
|
private createQuickReplyButtonComponent;
|
|
26
28
|
private createVoiceCallButtonComponent;
|
|
29
|
+
private createPhoneNumberButtonComponent;
|
|
30
|
+
private resolveFlowActionData;
|
|
31
|
+
private createFlowButtonComponent;
|
|
27
32
|
trackFlow(botContext: BotContext): Promise<void>;
|
|
28
33
|
processContent(botContext: BotContext): Promise<void>;
|
|
29
34
|
toBotonic(botContext: BotContext): JSX.Element;
|
|
@@ -7,6 +7,7 @@ const react_1 = require("@botonic/react");
|
|
|
7
7
|
const tracking_1 = require("../tracking");
|
|
8
8
|
const get_flow_builder_plugin_1 = require("../utils/get-flow-builder-plugin");
|
|
9
9
|
const content_fields_base_1 = require("./content-fields-base");
|
|
10
|
+
const hubtype_fields_1 = require("./hubtype-fields");
|
|
10
11
|
class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
11
12
|
constructor() {
|
|
12
13
|
super(...arguments);
|
|
@@ -17,10 +18,15 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
17
18
|
whatsappTemplate.code = component.code;
|
|
18
19
|
whatsappTemplate.buttons = component.content.buttons;
|
|
19
20
|
const contentByLocale = FlowWhatsappTemplate.getContentByLocale(component, currentLocale);
|
|
21
|
+
if (!contentByLocale.template) {
|
|
22
|
+
throw new Error(`Whatsapp template not configured for locale: ${currentLocale}`);
|
|
23
|
+
}
|
|
20
24
|
whatsappTemplate.htWhatsappTemplate = contentByLocale.template;
|
|
21
25
|
whatsappTemplate.headerVariables = contentByLocale.header_variables;
|
|
22
|
-
whatsappTemplate.variableValues = contentByLocale.variable_values;
|
|
26
|
+
whatsappTemplate.variableValues = contentByLocale.variable_values || {};
|
|
23
27
|
whatsappTemplate.urlVariableValues = contentByLocale.url_variable_values;
|
|
28
|
+
whatsappTemplate.flowButtonActionValues =
|
|
29
|
+
contentByLocale.flow_button_action_values;
|
|
24
30
|
whatsappTemplate.followUp = component.follow_up;
|
|
25
31
|
return whatsappTemplate;
|
|
26
32
|
}
|
|
@@ -99,31 +105,45 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
99
105
|
}),
|
|
100
106
|
};
|
|
101
107
|
}
|
|
102
|
-
getButtons(whatsappTemplate, buttonNodes, urlVariableValues, botContext) {
|
|
108
|
+
getButtons(whatsappTemplate, buttonNodes, urlVariableValues, flowButtonActionValues, botContext) {
|
|
103
109
|
const htWhatsappTemplateButtons = whatsappTemplate.components.find(component => component.type === react_1.WhatsAppTemplateComponentType.BUTTONS);
|
|
104
|
-
if (htWhatsappTemplateButtons) {
|
|
105
|
-
|
|
106
|
-
.map((button, index) => {
|
|
107
|
-
if (button.type === react_1.WhatsAppTemplateButtonSubType.URL) {
|
|
108
|
-
const urlParam = urlVariableValues?.[String(index)];
|
|
109
|
-
if (!urlParam) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return this.createUrlButtonComponent(index, urlParam, botContext);
|
|
113
|
-
}
|
|
114
|
-
if (button.type === react_1.WhatsAppTemplateButtonSubType.QUICK_REPLY) {
|
|
115
|
-
const payload = buttonNodes[index].target?.id || '';
|
|
116
|
-
return this.createQuickReplyButtonComponent(index, payload);
|
|
117
|
-
}
|
|
118
|
-
return this.createVoiceCallButtonComponent(index);
|
|
119
|
-
})
|
|
120
|
-
.filter(button => button !== null);
|
|
121
|
-
return {
|
|
122
|
-
type: react_1.WhatsAppTemplateComponentType.BUTTONS,
|
|
123
|
-
buttons: buttons,
|
|
124
|
-
};
|
|
110
|
+
if (!htWhatsappTemplateButtons) {
|
|
111
|
+
return undefined;
|
|
125
112
|
}
|
|
126
|
-
|
|
113
|
+
const buttons = htWhatsappTemplateButtons.buttons
|
|
114
|
+
.map((button, index) => this.mapTemplateButton(button, index, whatsappTemplate.name, buttonNodes, urlVariableValues, flowButtonActionValues, botContext))
|
|
115
|
+
.filter(button => button !== null);
|
|
116
|
+
return {
|
|
117
|
+
type: react_1.WhatsAppTemplateComponentType.BUTTONS,
|
|
118
|
+
buttons: buttons,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
mapTemplateButton(button, index, templateName, buttonNodes, urlVariableValues, flowButtonActionValues, botContext) {
|
|
122
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.URL) {
|
|
123
|
+
const urlParam = urlVariableValues?.[String(index)];
|
|
124
|
+
if (!urlParam) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return this.createUrlButtonComponent(index, urlParam, botContext);
|
|
128
|
+
}
|
|
129
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.QUICK_REPLY) {
|
|
130
|
+
const payload = buttonNodes[index].target?.id || '';
|
|
131
|
+
return this.createQuickReplyButtonComponent(index, payload);
|
|
132
|
+
}
|
|
133
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.PHONE_NUMBER) {
|
|
134
|
+
return this.createPhoneNumberButtonComponent(index);
|
|
135
|
+
}
|
|
136
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.VOICE_CALL) {
|
|
137
|
+
return this.createVoiceCallButtonComponent(index);
|
|
138
|
+
}
|
|
139
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.FLOW) {
|
|
140
|
+
const actionValue = flowButtonActionValues?.[String(index)];
|
|
141
|
+
if (!actionValue) {
|
|
142
|
+
throw new Error(`WhatsApp template '${templateName}' FLOW button at index ${index} requires flow_button_action_values`);
|
|
143
|
+
}
|
|
144
|
+
return this.createFlowButtonComponent(index, button, actionValue, botContext, templateName);
|
|
145
|
+
}
|
|
146
|
+
throw new Error(`WhatsApp template '${templateName}' has unsupported button at index ${index}`);
|
|
127
147
|
}
|
|
128
148
|
createUrlButtonComponent(index, urlParam, botContext) {
|
|
129
149
|
const variableUrlParam = this.replaceVariables(urlParam, botContext);
|
|
@@ -162,6 +182,51 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
162
182
|
parameters: [],
|
|
163
183
|
};
|
|
164
184
|
}
|
|
185
|
+
createPhoneNumberButtonComponent(index) {
|
|
186
|
+
return {
|
|
187
|
+
type: react_1.WhatsAppTemplateComponentType.BUTTON,
|
|
188
|
+
sub_type: react_1.WhatsAppTemplateButtonSubType.PHONE_NUMBER,
|
|
189
|
+
index: index,
|
|
190
|
+
parameters: [],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
resolveFlowActionData(flowActionData, botContext) {
|
|
194
|
+
if (!flowActionData) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
const resolvedData = Object.fromEntries(Object.entries(flowActionData).map(([key, value]) => [
|
|
198
|
+
key,
|
|
199
|
+
this.replaceVariables(value, botContext),
|
|
200
|
+
]));
|
|
201
|
+
return Object.keys(resolvedData).length > 0 ? resolvedData : undefined;
|
|
202
|
+
}
|
|
203
|
+
createFlowButtonComponent(index, templateButton, actionValue, botContext, templateName) {
|
|
204
|
+
const flowToken = this.replaceVariables(actionValue.flow_token, botContext);
|
|
205
|
+
if (!flowToken.trim()) {
|
|
206
|
+
throw new Error(`WhatsApp template '${templateName}' FLOW button at index ${index} requires a non-empty flow_token`);
|
|
207
|
+
}
|
|
208
|
+
const action = {
|
|
209
|
+
flow_token: flowToken,
|
|
210
|
+
};
|
|
211
|
+
if (templateButton.flow_action !==
|
|
212
|
+
hubtype_fields_1.HtWhatsAppTemplateFlowActionType.DATA_EXCHANGE) {
|
|
213
|
+
const flowActionData = this.resolveFlowActionData(actionValue.flow_action_data, botContext);
|
|
214
|
+
if (flowActionData) {
|
|
215
|
+
action.flow_action_data = flowActionData;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
type: react_1.WhatsAppTemplateComponentType.BUTTON,
|
|
220
|
+
sub_type: react_1.WhatsAppTemplateButtonSubType.FLOW,
|
|
221
|
+
index: String(index),
|
|
222
|
+
parameters: [
|
|
223
|
+
{
|
|
224
|
+
type: react_1.WhatsAppTemplateParameterType.ACTION,
|
|
225
|
+
action,
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
};
|
|
229
|
+
}
|
|
165
230
|
async trackFlow(botContext) {
|
|
166
231
|
await (0, tracking_1.trackOneContent)(botContext, this);
|
|
167
232
|
}
|
|
@@ -177,7 +242,7 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
177
242
|
const pluginFlowBuilder = (0, get_flow_builder_plugin_1.getFlowBuilderPlugin)(botContext.plugins);
|
|
178
243
|
const resolvedLocale = pluginFlowBuilder.cmsApi.getResolvedLocale();
|
|
179
244
|
const header = this.getHeaderComponent(this.htWhatsappTemplate, this.headerVariables || {}, resolvedLocale, botContext);
|
|
180
|
-
const buttons = this.getButtons(this.htWhatsappTemplate, this.buttons || [], this.urlVariableValues || {}, botContext);
|
|
245
|
+
const buttons = this.getButtons(this.htWhatsappTemplate, this.buttons || [], this.urlVariableValues || {}, this.flowButtonActionValues || {}, botContext);
|
|
181
246
|
if ((0, core_1.isWhatsapp)(botContext.session)) {
|
|
182
247
|
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappTemplate, { name: templateName, language: templateLanguage, header: header, body: body, buttons: buttons }, this.id));
|
|
183
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-whatsapp-template.js","sourceRoot":"","sources":["../../../src/content-fields/flow-whatsapp-template.tsx"],"names":[],"mappings":";;;;AAAA,wCAA2D;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AAE,CAAC,CAAC,EAAE,EAC1C,OAAO,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,KAJxC,IAAI,CAAC,EAAE,CAKX,CACR,CAAA;IACH,CAAC;CACF;AApaD,oDAoaC"}
|
|
@@ -2,6 +2,10 @@ import type { WhatsAppTemplateButtonSubType, WhatsAppTemplateComponentType, What
|
|
|
2
2
|
import type { HtButton } from './button';
|
|
3
3
|
import type { HtBaseNode, HtMediaFileLocale } from './common';
|
|
4
4
|
import type { HtNodeWithContentType } from './node-types';
|
|
5
|
+
export declare enum HtWhatsAppTemplateFlowActionType {
|
|
6
|
+
NAVIGATE = "navigate",
|
|
7
|
+
DATA_EXCHANGE = "data_exchange"
|
|
8
|
+
}
|
|
5
9
|
type HtWhatsAppTemplateButton = {
|
|
6
10
|
type: WhatsAppTemplateButtonSubType.URL;
|
|
7
11
|
text: string;
|
|
@@ -17,7 +21,22 @@ type HtWhatsAppTemplateButton = {
|
|
|
17
21
|
text: string;
|
|
18
22
|
phone_number: string;
|
|
19
23
|
index: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: WhatsAppTemplateButtonSubType.VOICE_CALL;
|
|
26
|
+
text: string;
|
|
27
|
+
index: number;
|
|
28
|
+
} | {
|
|
29
|
+
type: WhatsAppTemplateButtonSubType.FLOW;
|
|
30
|
+
text: string;
|
|
31
|
+
flow_id: string;
|
|
32
|
+
flow_action?: HtWhatsAppTemplateFlowActionType;
|
|
33
|
+
navigate_screen?: string;
|
|
34
|
+
index: number;
|
|
20
35
|
};
|
|
36
|
+
export interface HtFlowButtonActionValue {
|
|
37
|
+
flow_token: string;
|
|
38
|
+
flow_action_data?: Record<string, string>;
|
|
39
|
+
}
|
|
21
40
|
export interface HtWhatsAppTemplateHeaderComponent {
|
|
22
41
|
type: WhatsAppTemplateComponentType.HEADER;
|
|
23
42
|
format: WhatsAppTemplateParameterType.TEXT | WhatsAppTemplateParameterType.IMAGE | WhatsAppTemplateParameterType.VIDEO;
|
|
@@ -53,14 +72,15 @@ export interface HtWhatsAppTemplate {
|
|
|
53
72
|
parameter_format: string;
|
|
54
73
|
}
|
|
55
74
|
export interface HtWhatsappTemplateContentByLocale {
|
|
56
|
-
template
|
|
75
|
+
template?: HtWhatsAppTemplate;
|
|
57
76
|
header_variables?: {
|
|
58
77
|
type: WhatsAppTemplateParameterType;
|
|
59
78
|
text?: Record<string, string>;
|
|
60
79
|
media?: HtMediaFileLocale[];
|
|
61
80
|
};
|
|
62
|
-
variable_values
|
|
81
|
+
variable_values?: Record<string, string>;
|
|
63
82
|
url_variable_values?: Record<string, string>;
|
|
83
|
+
flow_button_action_values?: Record<string, HtFlowButtonActionValue>;
|
|
64
84
|
}
|
|
65
85
|
export interface HtWhatsappTemplateNode extends HtBaseNode {
|
|
66
86
|
type: HtNodeWithContentType.WHATSAPP_TEMPLATE;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HtWhatsAppTemplateFlowActionType = void 0;
|
|
4
|
+
var HtWhatsAppTemplateFlowActionType;
|
|
5
|
+
(function (HtWhatsAppTemplateFlowActionType) {
|
|
6
|
+
HtWhatsAppTemplateFlowActionType["NAVIGATE"] = "navigate";
|
|
7
|
+
HtWhatsAppTemplateFlowActionType["DATA_EXCHANGE"] = "data_exchange";
|
|
8
|
+
})(HtWhatsAppTemplateFlowActionType || (exports.HtWhatsAppTemplateFlowActionType = HtWhatsAppTemplateFlowActionType = {}));
|
|
3
9
|
//# sourceMappingURL=whatsapp-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsapp-template.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/whatsapp-template.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"whatsapp-template.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/whatsapp-template.ts"],"names":[],"mappings":";;;AAUA,IAAY,gCAGX;AAHD,WAAY,gCAAgC;IAC1C,yDAAqB,CAAA;IACrB,mEAA+B,CAAA;AACjC,CAAC,EAHW,gCAAgC,gDAAhC,gCAAgC,QAG3C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BotContext } from '@botonic/core';
|
|
2
2
|
import { WhatsAppTemplateParameterType } from '@botonic/react';
|
|
3
3
|
import { ContentFieldsBase } from './content-fields-base';
|
|
4
|
-
import type
|
|
4
|
+
import { type HtButton, type HtFlowButtonActionValue, type HtMediaFileLocale, type HtWhatsAppTemplate, type HtWhatsappTemplateNode } from './hubtype-fields';
|
|
5
5
|
interface HeaderVariables {
|
|
6
6
|
type: WhatsAppTemplateParameterType;
|
|
7
7
|
text?: Record<string, string>;
|
|
@@ -13,6 +13,7 @@ export declare class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
13
13
|
headerVariables?: HeaderVariables;
|
|
14
14
|
buttons?: HtButton[];
|
|
15
15
|
urlVariableValues?: Record<string, string>;
|
|
16
|
+
flowButtonActionValues?: Record<string, HtFlowButtonActionValue>;
|
|
16
17
|
static fromHubtypeCMS(component: HtWhatsappTemplateNode, currentLocale: string): FlowWhatsappTemplate;
|
|
17
18
|
private static getContentByLocale;
|
|
18
19
|
private getHeaderComponent;
|
|
@@ -21,9 +22,13 @@ export declare class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
21
22
|
private createHeaderVideoComponent;
|
|
22
23
|
private getBodyComponent;
|
|
23
24
|
private getButtons;
|
|
25
|
+
private mapTemplateButton;
|
|
24
26
|
private createUrlButtonComponent;
|
|
25
27
|
private createQuickReplyButtonComponent;
|
|
26
28
|
private createVoiceCallButtonComponent;
|
|
29
|
+
private createPhoneNumberButtonComponent;
|
|
30
|
+
private resolveFlowActionData;
|
|
31
|
+
private createFlowButtonComponent;
|
|
27
32
|
trackFlow(botContext: BotContext): Promise<void>;
|
|
28
33
|
processContent(botContext: BotContext): Promise<void>;
|
|
29
34
|
toBotonic(botContext: BotContext): JSX.Element;
|
|
@@ -7,6 +7,7 @@ const react_1 = require("@botonic/react");
|
|
|
7
7
|
const tracking_1 = require("../tracking");
|
|
8
8
|
const get_flow_builder_plugin_1 = require("../utils/get-flow-builder-plugin");
|
|
9
9
|
const content_fields_base_1 = require("./content-fields-base");
|
|
10
|
+
const hubtype_fields_1 = require("./hubtype-fields");
|
|
10
11
|
class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
11
12
|
constructor() {
|
|
12
13
|
super(...arguments);
|
|
@@ -17,10 +18,15 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
17
18
|
whatsappTemplate.code = component.code;
|
|
18
19
|
whatsappTemplate.buttons = component.content.buttons;
|
|
19
20
|
const contentByLocale = FlowWhatsappTemplate.getContentByLocale(component, currentLocale);
|
|
21
|
+
if (!contentByLocale.template) {
|
|
22
|
+
throw new Error(`Whatsapp template not configured for locale: ${currentLocale}`);
|
|
23
|
+
}
|
|
20
24
|
whatsappTemplate.htWhatsappTemplate = contentByLocale.template;
|
|
21
25
|
whatsappTemplate.headerVariables = contentByLocale.header_variables;
|
|
22
|
-
whatsappTemplate.variableValues = contentByLocale.variable_values;
|
|
26
|
+
whatsappTemplate.variableValues = contentByLocale.variable_values || {};
|
|
23
27
|
whatsappTemplate.urlVariableValues = contentByLocale.url_variable_values;
|
|
28
|
+
whatsappTemplate.flowButtonActionValues =
|
|
29
|
+
contentByLocale.flow_button_action_values;
|
|
24
30
|
whatsappTemplate.followUp = component.follow_up;
|
|
25
31
|
return whatsappTemplate;
|
|
26
32
|
}
|
|
@@ -99,31 +105,45 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
99
105
|
}),
|
|
100
106
|
};
|
|
101
107
|
}
|
|
102
|
-
getButtons(whatsappTemplate, buttonNodes, urlVariableValues, botContext) {
|
|
108
|
+
getButtons(whatsappTemplate, buttonNodes, urlVariableValues, flowButtonActionValues, botContext) {
|
|
103
109
|
const htWhatsappTemplateButtons = whatsappTemplate.components.find(component => component.type === react_1.WhatsAppTemplateComponentType.BUTTONS);
|
|
104
|
-
if (htWhatsappTemplateButtons) {
|
|
105
|
-
|
|
106
|
-
.map((button, index) => {
|
|
107
|
-
if (button.type === react_1.WhatsAppTemplateButtonSubType.URL) {
|
|
108
|
-
const urlParam = urlVariableValues?.[String(index)];
|
|
109
|
-
if (!urlParam) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return this.createUrlButtonComponent(index, urlParam, botContext);
|
|
113
|
-
}
|
|
114
|
-
if (button.type === react_1.WhatsAppTemplateButtonSubType.QUICK_REPLY) {
|
|
115
|
-
const payload = buttonNodes[index].target?.id || '';
|
|
116
|
-
return this.createQuickReplyButtonComponent(index, payload);
|
|
117
|
-
}
|
|
118
|
-
return this.createVoiceCallButtonComponent(index);
|
|
119
|
-
})
|
|
120
|
-
.filter(button => button !== null);
|
|
121
|
-
return {
|
|
122
|
-
type: react_1.WhatsAppTemplateComponentType.BUTTONS,
|
|
123
|
-
buttons: buttons,
|
|
124
|
-
};
|
|
110
|
+
if (!htWhatsappTemplateButtons) {
|
|
111
|
+
return undefined;
|
|
125
112
|
}
|
|
126
|
-
|
|
113
|
+
const buttons = htWhatsappTemplateButtons.buttons
|
|
114
|
+
.map((button, index) => this.mapTemplateButton(button, index, whatsappTemplate.name, buttonNodes, urlVariableValues, flowButtonActionValues, botContext))
|
|
115
|
+
.filter(button => button !== null);
|
|
116
|
+
return {
|
|
117
|
+
type: react_1.WhatsAppTemplateComponentType.BUTTONS,
|
|
118
|
+
buttons: buttons,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
mapTemplateButton(button, index, templateName, buttonNodes, urlVariableValues, flowButtonActionValues, botContext) {
|
|
122
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.URL) {
|
|
123
|
+
const urlParam = urlVariableValues?.[String(index)];
|
|
124
|
+
if (!urlParam) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return this.createUrlButtonComponent(index, urlParam, botContext);
|
|
128
|
+
}
|
|
129
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.QUICK_REPLY) {
|
|
130
|
+
const payload = buttonNodes[index].target?.id || '';
|
|
131
|
+
return this.createQuickReplyButtonComponent(index, payload);
|
|
132
|
+
}
|
|
133
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.PHONE_NUMBER) {
|
|
134
|
+
return this.createPhoneNumberButtonComponent(index);
|
|
135
|
+
}
|
|
136
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.VOICE_CALL) {
|
|
137
|
+
return this.createVoiceCallButtonComponent(index);
|
|
138
|
+
}
|
|
139
|
+
if (button.type === react_1.WhatsAppTemplateButtonSubType.FLOW) {
|
|
140
|
+
const actionValue = flowButtonActionValues?.[String(index)];
|
|
141
|
+
if (!actionValue) {
|
|
142
|
+
throw new Error(`WhatsApp template '${templateName}' FLOW button at index ${index} requires flow_button_action_values`);
|
|
143
|
+
}
|
|
144
|
+
return this.createFlowButtonComponent(index, button, actionValue, botContext, templateName);
|
|
145
|
+
}
|
|
146
|
+
throw new Error(`WhatsApp template '${templateName}' has unsupported button at index ${index}`);
|
|
127
147
|
}
|
|
128
148
|
createUrlButtonComponent(index, urlParam, botContext) {
|
|
129
149
|
const variableUrlParam = this.replaceVariables(urlParam, botContext);
|
|
@@ -162,6 +182,51 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
162
182
|
parameters: [],
|
|
163
183
|
};
|
|
164
184
|
}
|
|
185
|
+
createPhoneNumberButtonComponent(index) {
|
|
186
|
+
return {
|
|
187
|
+
type: react_1.WhatsAppTemplateComponentType.BUTTON,
|
|
188
|
+
sub_type: react_1.WhatsAppTemplateButtonSubType.PHONE_NUMBER,
|
|
189
|
+
index: index,
|
|
190
|
+
parameters: [],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
resolveFlowActionData(flowActionData, botContext) {
|
|
194
|
+
if (!flowActionData) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
const resolvedData = Object.fromEntries(Object.entries(flowActionData).map(([key, value]) => [
|
|
198
|
+
key,
|
|
199
|
+
this.replaceVariables(value, botContext),
|
|
200
|
+
]));
|
|
201
|
+
return Object.keys(resolvedData).length > 0 ? resolvedData : undefined;
|
|
202
|
+
}
|
|
203
|
+
createFlowButtonComponent(index, templateButton, actionValue, botContext, templateName) {
|
|
204
|
+
const flowToken = this.replaceVariables(actionValue.flow_token, botContext);
|
|
205
|
+
if (!flowToken.trim()) {
|
|
206
|
+
throw new Error(`WhatsApp template '${templateName}' FLOW button at index ${index} requires a non-empty flow_token`);
|
|
207
|
+
}
|
|
208
|
+
const action = {
|
|
209
|
+
flow_token: flowToken,
|
|
210
|
+
};
|
|
211
|
+
if (templateButton.flow_action !==
|
|
212
|
+
hubtype_fields_1.HtWhatsAppTemplateFlowActionType.DATA_EXCHANGE) {
|
|
213
|
+
const flowActionData = this.resolveFlowActionData(actionValue.flow_action_data, botContext);
|
|
214
|
+
if (flowActionData) {
|
|
215
|
+
action.flow_action_data = flowActionData;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
type: react_1.WhatsAppTemplateComponentType.BUTTON,
|
|
220
|
+
sub_type: react_1.WhatsAppTemplateButtonSubType.FLOW,
|
|
221
|
+
index: String(index),
|
|
222
|
+
parameters: [
|
|
223
|
+
{
|
|
224
|
+
type: react_1.WhatsAppTemplateParameterType.ACTION,
|
|
225
|
+
action,
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
};
|
|
229
|
+
}
|
|
165
230
|
async trackFlow(botContext) {
|
|
166
231
|
await (0, tracking_1.trackOneContent)(botContext, this);
|
|
167
232
|
}
|
|
@@ -177,7 +242,7 @@ class FlowWhatsappTemplate extends content_fields_base_1.ContentFieldsBase {
|
|
|
177
242
|
const pluginFlowBuilder = (0, get_flow_builder_plugin_1.getFlowBuilderPlugin)(botContext.plugins);
|
|
178
243
|
const resolvedLocale = pluginFlowBuilder.cmsApi.getResolvedLocale();
|
|
179
244
|
const header = this.getHeaderComponent(this.htWhatsappTemplate, this.headerVariables || {}, resolvedLocale, botContext);
|
|
180
|
-
const buttons = this.getButtons(this.htWhatsappTemplate, this.buttons || [], this.urlVariableValues || {}, botContext);
|
|
245
|
+
const buttons = this.getButtons(this.htWhatsappTemplate, this.buttons || [], this.urlVariableValues || {}, this.flowButtonActionValues || {}, botContext);
|
|
181
246
|
if ((0, core_1.isWhatsapp)(botContext.session)) {
|
|
182
247
|
return ((0, jsx_runtime_1.jsx)(react_1.WhatsappTemplate, { name: templateName, language: templateLanguage, header: header, body: body, buttons: buttons }, this.id));
|
|
183
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-whatsapp-template.js","sourceRoot":"","sources":["../../../src/content-fields/flow-whatsapp-template.tsx"],"names":[],"mappings":";;;;AAAA,wCAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"flow-whatsapp-template.js","sourceRoot":"","sources":["../../../src/content-fields/flow-whatsapp-template.tsx"],"names":[],"mappings":";;;;AAAA,wCAA2D;AAC3D,0CAgBuB;AAEvB,0CAA6C;AAC7C,8EAAuE;AACvE,+DAAyD;AACzD,qDAUyB;AAQzB,MAAa,oBAAqB,SAAQ,uCAAiB;IAA3D;;QAES,mBAAc,GAA2B,EAAE,CAAA;IAkapD,CAAC;IA5ZC,MAAM,CAAC,cAAc,CACnB,SAAiC,EACjC,aAAqB;QAErB,MAAM,gBAAgB,GAAG,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC/D,gBAAgB,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QACtC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAA;QACpD,MAAM,eAAe,GAAG,oBAAoB,CA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kBAAkB,EACvB,IAAI,CAAC,OAAO,IAAI,EAAE,EAClB,IAAI,CAAC,iBAAiB,IAAI,EAAE,EAC5B,IAAI,CAAC,sBAAsB,IAAI,EAAE,EACjC,UAAU,CACX,CAAA;QAED,IAAI,IAAA,iBAAU,EAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACnC,OAAO,CACL,uBAAC,wBAAgB,IAEf,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,IALX,IAAI,CAAC,EAAE,CAMZ,CACH,CAAA;QACH,CAAC;QAED,OAAO,CACL,wBAAC,YAAI,eACF,sBAAsB,YAAY,KAAK,gBAAgB,GAAG,EAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAC9C,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAC1C,OAAO,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,KAJxC,IAAI,CAAC,EAAE,CAKX,CACR,CAAA;IACH,CAAC;CACF;AApaD,oDAoaC"}
|
|
@@ -2,6 +2,10 @@ import type { WhatsAppTemplateButtonSubType, WhatsAppTemplateComponentType, What
|
|
|
2
2
|
import type { HtButton } from './button';
|
|
3
3
|
import type { HtBaseNode, HtMediaFileLocale } from './common';
|
|
4
4
|
import type { HtNodeWithContentType } from './node-types';
|
|
5
|
+
export declare enum HtWhatsAppTemplateFlowActionType {
|
|
6
|
+
NAVIGATE = "navigate",
|
|
7
|
+
DATA_EXCHANGE = "data_exchange"
|
|
8
|
+
}
|
|
5
9
|
type HtWhatsAppTemplateButton = {
|
|
6
10
|
type: WhatsAppTemplateButtonSubType.URL;
|
|
7
11
|
text: string;
|
|
@@ -17,7 +21,22 @@ type HtWhatsAppTemplateButton = {
|
|
|
17
21
|
text: string;
|
|
18
22
|
phone_number: string;
|
|
19
23
|
index: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: WhatsAppTemplateButtonSubType.VOICE_CALL;
|
|
26
|
+
text: string;
|
|
27
|
+
index: number;
|
|
28
|
+
} | {
|
|
29
|
+
type: WhatsAppTemplateButtonSubType.FLOW;
|
|
30
|
+
text: string;
|
|
31
|
+
flow_id: string;
|
|
32
|
+
flow_action?: HtWhatsAppTemplateFlowActionType;
|
|
33
|
+
navigate_screen?: string;
|
|
34
|
+
index: number;
|
|
20
35
|
};
|
|
36
|
+
export interface HtFlowButtonActionValue {
|
|
37
|
+
flow_token: string;
|
|
38
|
+
flow_action_data?: Record<string, string>;
|
|
39
|
+
}
|
|
21
40
|
export interface HtWhatsAppTemplateHeaderComponent {
|
|
22
41
|
type: WhatsAppTemplateComponentType.HEADER;
|
|
23
42
|
format: WhatsAppTemplateParameterType.TEXT | WhatsAppTemplateParameterType.IMAGE | WhatsAppTemplateParameterType.VIDEO;
|
|
@@ -53,14 +72,15 @@ export interface HtWhatsAppTemplate {
|
|
|
53
72
|
parameter_format: string;
|
|
54
73
|
}
|
|
55
74
|
export interface HtWhatsappTemplateContentByLocale {
|
|
56
|
-
template
|
|
75
|
+
template?: HtWhatsAppTemplate;
|
|
57
76
|
header_variables?: {
|
|
58
77
|
type: WhatsAppTemplateParameterType;
|
|
59
78
|
text?: Record<string, string>;
|
|
60
79
|
media?: HtMediaFileLocale[];
|
|
61
80
|
};
|
|
62
|
-
variable_values
|
|
81
|
+
variable_values?: Record<string, string>;
|
|
63
82
|
url_variable_values?: Record<string, string>;
|
|
83
|
+
flow_button_action_values?: Record<string, HtFlowButtonActionValue>;
|
|
64
84
|
}
|
|
65
85
|
export interface HtWhatsappTemplateNode extends HtBaseNode {
|
|
66
86
|
type: HtNodeWithContentType.WHATSAPP_TEMPLATE;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HtWhatsAppTemplateFlowActionType = void 0;
|
|
4
|
+
var HtWhatsAppTemplateFlowActionType;
|
|
5
|
+
(function (HtWhatsAppTemplateFlowActionType) {
|
|
6
|
+
HtWhatsAppTemplateFlowActionType["NAVIGATE"] = "navigate";
|
|
7
|
+
HtWhatsAppTemplateFlowActionType["DATA_EXCHANGE"] = "data_exchange";
|
|
8
|
+
})(HtWhatsAppTemplateFlowActionType || (exports.HtWhatsAppTemplateFlowActionType = HtWhatsAppTemplateFlowActionType = {}));
|
|
3
9
|
//# sourceMappingURL=whatsapp-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsapp-template.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/whatsapp-template.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"whatsapp-template.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/whatsapp-template.ts"],"names":[],"mappings":";;;AAUA,IAAY,gCAGX;AAHD,WAAY,gCAAgC;IAC1C,yDAAqB,CAAA;IACrB,mEAA+B,CAAA;AACjC,CAAC,EAHW,gCAAgC,gDAAhC,gCAAgC,QAG3C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.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",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"format": "biome format --write src/ tests/"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@botonic/react": "^0.
|
|
19
|
-
"axios": "^1.
|
|
18
|
+
"@botonic/react": "^0.53.0",
|
|
19
|
+
"axios": "^1.18.1",
|
|
20
20
|
"uuid": "^10.0.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
type WhatsappTemplateComponentBody,
|
|
10
10
|
type WhatsappTemplateComponentButtons,
|
|
11
11
|
type WhatsappTemplateComponentHeader,
|
|
12
|
+
type WhatsappTemplateFlowAction,
|
|
13
|
+
type WhatsappTemplateFlowButton,
|
|
14
|
+
type WhatsappTemplatePhoneNumberButton,
|
|
12
15
|
type WhatsappTemplateQuickReplyButton,
|
|
13
16
|
type WhatsappTemplateUrlButton,
|
|
14
17
|
type WhatsappTemplateVoiceCallButton,
|
|
@@ -17,14 +20,16 @@ import {
|
|
|
17
20
|
import { trackOneContent } from '../tracking'
|
|
18
21
|
import { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'
|
|
19
22
|
import { ContentFieldsBase } from './content-fields-base'
|
|
20
|
-
import
|
|
21
|
-
HtButton,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
import {
|
|
24
|
+
type HtButton,
|
|
25
|
+
type HtFlowButtonActionValue,
|
|
26
|
+
type HtMediaFileLocale,
|
|
27
|
+
type HtWhatsAppTemplate,
|
|
28
|
+
type HtWhatsAppTemplateButtonsComponent,
|
|
29
|
+
HtWhatsAppTemplateFlowActionType,
|
|
30
|
+
type HtWhatsAppTemplateHeaderComponent,
|
|
31
|
+
type HtWhatsappTemplateContentByLocale,
|
|
32
|
+
type HtWhatsappTemplateNode,
|
|
28
33
|
} from './hubtype-fields'
|
|
29
34
|
|
|
30
35
|
interface HeaderVariables {
|
|
@@ -39,6 +44,7 @@ export class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
39
44
|
public headerVariables?: HeaderVariables
|
|
40
45
|
public buttons?: HtButton[]
|
|
41
46
|
public urlVariableValues?: Record<string, string>
|
|
47
|
+
public flowButtonActionValues?: Record<string, HtFlowButtonActionValue>
|
|
42
48
|
|
|
43
49
|
static fromHubtypeCMS(
|
|
44
50
|
component: HtWhatsappTemplateNode,
|
|
@@ -52,10 +58,18 @@ export class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
52
58
|
currentLocale
|
|
53
59
|
)
|
|
54
60
|
|
|
61
|
+
if (!contentByLocale.template) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Whatsapp template not configured for locale: ${currentLocale}`
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
whatsappTemplate.htWhatsappTemplate = contentByLocale.template
|
|
56
68
|
whatsappTemplate.headerVariables = contentByLocale.header_variables
|
|
57
|
-
whatsappTemplate.variableValues = contentByLocale.variable_values
|
|
69
|
+
whatsappTemplate.variableValues = contentByLocale.variable_values || {}
|
|
58
70
|
whatsappTemplate.urlVariableValues = contentByLocale.url_variable_values
|
|
71
|
+
whatsappTemplate.flowButtonActionValues =
|
|
72
|
+
contentByLocale.flow_button_action_values
|
|
59
73
|
|
|
60
74
|
whatsappTemplate.followUp = component.follow_up
|
|
61
75
|
|
|
@@ -184,40 +198,86 @@ export class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
184
198
|
whatsappTemplate: HtWhatsAppTemplate,
|
|
185
199
|
buttonNodes: HtButton[],
|
|
186
200
|
urlVariableValues: Record<string, string>,
|
|
201
|
+
flowButtonActionValues: Record<string, HtFlowButtonActionValue>,
|
|
187
202
|
botContext: BotContext
|
|
188
203
|
): WhatsappTemplateComponentButtons | undefined {
|
|
189
204
|
const htWhatsappTemplateButtons = whatsappTemplate.components.find(
|
|
190
205
|
component => component.type === WhatsAppTemplateComponentType.BUTTONS
|
|
191
206
|
) as HtWhatsAppTemplateButtonsComponent | undefined
|
|
192
207
|
|
|
193
|
-
if (htWhatsappTemplateButtons) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
208
|
+
if (!htWhatsappTemplateButtons) {
|
|
209
|
+
return undefined
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const buttons = htWhatsappTemplateButtons.buttons
|
|
213
|
+
.map((button, index) =>
|
|
214
|
+
this.mapTemplateButton(
|
|
215
|
+
button,
|
|
216
|
+
index,
|
|
217
|
+
whatsappTemplate.name,
|
|
218
|
+
buttonNodes,
|
|
219
|
+
urlVariableValues,
|
|
220
|
+
flowButtonActionValues,
|
|
221
|
+
botContext
|
|
222
|
+
)
|
|
223
|
+
)
|
|
224
|
+
.filter(button => button !== null)
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
type: WhatsAppTemplateComponentType.BUTTONS,
|
|
228
|
+
buttons: buttons as WhatsappTemplateButton[],
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private mapTemplateButton(
|
|
233
|
+
button: HtWhatsAppTemplateButtonsComponent['buttons'][number],
|
|
234
|
+
index: number,
|
|
235
|
+
templateName: string,
|
|
236
|
+
buttonNodes: HtButton[],
|
|
237
|
+
urlVariableValues: Record<string, string>,
|
|
238
|
+
flowButtonActionValues: Record<string, HtFlowButtonActionValue>,
|
|
239
|
+
botContext: BotContext
|
|
240
|
+
): WhatsappTemplateButton | null {
|
|
241
|
+
if (button.type === WhatsAppTemplateButtonSubType.URL) {
|
|
242
|
+
const urlParam: string | undefined = urlVariableValues?.[String(index)]
|
|
243
|
+
if (!urlParam) {
|
|
244
|
+
return null
|
|
217
245
|
}
|
|
246
|
+
return this.createUrlButtonComponent(index, urlParam, botContext)
|
|
218
247
|
}
|
|
219
248
|
|
|
220
|
-
|
|
249
|
+
if (button.type === WhatsAppTemplateButtonSubType.QUICK_REPLY) {
|
|
250
|
+
const payload = buttonNodes[index].target?.id || ''
|
|
251
|
+
return this.createQuickReplyButtonComponent(index, payload)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (button.type === WhatsAppTemplateButtonSubType.PHONE_NUMBER) {
|
|
255
|
+
return this.createPhoneNumberButtonComponent(index)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (button.type === WhatsAppTemplateButtonSubType.VOICE_CALL) {
|
|
259
|
+
return this.createVoiceCallButtonComponent(index)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (button.type === WhatsAppTemplateButtonSubType.FLOW) {
|
|
263
|
+
const actionValue = flowButtonActionValues?.[String(index)]
|
|
264
|
+
if (!actionValue) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
`WhatsApp template '${templateName}' FLOW button at index ${index} requires flow_button_action_values`
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
return this.createFlowButtonComponent(
|
|
270
|
+
index,
|
|
271
|
+
button,
|
|
272
|
+
actionValue,
|
|
273
|
+
botContext,
|
|
274
|
+
templateName
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
throw new Error(
|
|
279
|
+
`WhatsApp template '${templateName}' has unsupported button at index ${index}`
|
|
280
|
+
)
|
|
221
281
|
}
|
|
222
282
|
|
|
223
283
|
private createUrlButtonComponent(
|
|
@@ -269,6 +329,82 @@ export class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
269
329
|
}
|
|
270
330
|
}
|
|
271
331
|
|
|
332
|
+
private createPhoneNumberButtonComponent(
|
|
333
|
+
index: number
|
|
334
|
+
): WhatsappTemplatePhoneNumberButton {
|
|
335
|
+
return {
|
|
336
|
+
type: WhatsAppTemplateComponentType.BUTTON,
|
|
337
|
+
sub_type: WhatsAppTemplateButtonSubType.PHONE_NUMBER,
|
|
338
|
+
index: index,
|
|
339
|
+
parameters: [],
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private resolveFlowActionData(
|
|
344
|
+
flowActionData: Record<string, string> | undefined,
|
|
345
|
+
botContext: BotContext
|
|
346
|
+
): Record<string, string> | undefined {
|
|
347
|
+
if (!flowActionData) {
|
|
348
|
+
return undefined
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const resolvedData = Object.fromEntries(
|
|
352
|
+
Object.entries(flowActionData).map(([key, value]) => [
|
|
353
|
+
key,
|
|
354
|
+
this.replaceVariables(value, botContext),
|
|
355
|
+
])
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
return Object.keys(resolvedData).length > 0 ? resolvedData : undefined
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private createFlowButtonComponent(
|
|
362
|
+
index: number,
|
|
363
|
+
templateButton: Extract<
|
|
364
|
+
HtWhatsAppTemplateButtonsComponent['buttons'][number],
|
|
365
|
+
{ type: WhatsAppTemplateButtonSubType.FLOW }
|
|
366
|
+
>,
|
|
367
|
+
actionValue: HtFlowButtonActionValue,
|
|
368
|
+
botContext: BotContext,
|
|
369
|
+
templateName: string
|
|
370
|
+
): WhatsappTemplateFlowButton {
|
|
371
|
+
const flowToken = this.replaceVariables(actionValue.flow_token, botContext)
|
|
372
|
+
if (!flowToken.trim()) {
|
|
373
|
+
throw new Error(
|
|
374
|
+
`WhatsApp template '${templateName}' FLOW button at index ${index} requires a non-empty flow_token`
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const action: WhatsappTemplateFlowAction = {
|
|
379
|
+
flow_token: flowToken,
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (
|
|
383
|
+
templateButton.flow_action !==
|
|
384
|
+
HtWhatsAppTemplateFlowActionType.DATA_EXCHANGE
|
|
385
|
+
) {
|
|
386
|
+
const flowActionData = this.resolveFlowActionData(
|
|
387
|
+
actionValue.flow_action_data,
|
|
388
|
+
botContext
|
|
389
|
+
)
|
|
390
|
+
if (flowActionData) {
|
|
391
|
+
action.flow_action_data = flowActionData
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
type: WhatsAppTemplateComponentType.BUTTON,
|
|
397
|
+
sub_type: WhatsAppTemplateButtonSubType.FLOW,
|
|
398
|
+
index: String(index),
|
|
399
|
+
parameters: [
|
|
400
|
+
{
|
|
401
|
+
type: WhatsAppTemplateParameterType.ACTION,
|
|
402
|
+
action,
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
272
408
|
async trackFlow(botContext: BotContext): Promise<void> {
|
|
273
409
|
await trackOneContent(botContext, this)
|
|
274
410
|
}
|
|
@@ -296,6 +432,7 @@ export class FlowWhatsappTemplate extends ContentFieldsBase {
|
|
|
296
432
|
this.htWhatsappTemplate,
|
|
297
433
|
this.buttons || [],
|
|
298
434
|
this.urlVariableValues || {},
|
|
435
|
+
this.flowButtonActionValues || {},
|
|
299
436
|
botContext
|
|
300
437
|
)
|
|
301
438
|
|
|
@@ -8,6 +8,11 @@ import type { HtButton } from './button'
|
|
|
8
8
|
import type { HtBaseNode, HtMediaFileLocale } from './common'
|
|
9
9
|
import type { HtNodeWithContentType } from './node-types'
|
|
10
10
|
|
|
11
|
+
export enum HtWhatsAppTemplateFlowActionType {
|
|
12
|
+
NAVIGATE = 'navigate',
|
|
13
|
+
DATA_EXCHANGE = 'data_exchange',
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
type HtWhatsAppTemplateButton =
|
|
12
17
|
| {
|
|
13
18
|
type: WhatsAppTemplateButtonSubType.URL
|
|
@@ -27,6 +32,24 @@ type HtWhatsAppTemplateButton =
|
|
|
27
32
|
phone_number: string
|
|
28
33
|
index: number
|
|
29
34
|
}
|
|
35
|
+
| {
|
|
36
|
+
type: WhatsAppTemplateButtonSubType.VOICE_CALL
|
|
37
|
+
text: string
|
|
38
|
+
index: number
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
type: WhatsAppTemplateButtonSubType.FLOW
|
|
42
|
+
text: string
|
|
43
|
+
flow_id: string
|
|
44
|
+
flow_action?: HtWhatsAppTemplateFlowActionType
|
|
45
|
+
navigate_screen?: string
|
|
46
|
+
index: number
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface HtFlowButtonActionValue {
|
|
50
|
+
flow_token: string
|
|
51
|
+
flow_action_data?: Record<string, string>
|
|
52
|
+
}
|
|
30
53
|
|
|
31
54
|
export interface HtWhatsAppTemplateHeaderComponent {
|
|
32
55
|
type: WhatsAppTemplateComponentType.HEADER
|
|
@@ -71,14 +94,15 @@ export interface HtWhatsAppTemplate {
|
|
|
71
94
|
}
|
|
72
95
|
|
|
73
96
|
export interface HtWhatsappTemplateContentByLocale {
|
|
74
|
-
template
|
|
97
|
+
template?: HtWhatsAppTemplate
|
|
75
98
|
header_variables?: {
|
|
76
99
|
type: WhatsAppTemplateParameterType
|
|
77
100
|
text?: Record<string, string>
|
|
78
101
|
media?: HtMediaFileLocale[]
|
|
79
102
|
}
|
|
80
|
-
variable_values
|
|
103
|
+
variable_values?: Record<string, string>
|
|
81
104
|
url_variable_values?: Record<string, string>
|
|
105
|
+
flow_button_action_values?: Record<string, HtFlowButtonActionValue>
|
|
82
106
|
}
|
|
83
107
|
|
|
84
108
|
export interface HtWhatsappTemplateNode extends HtBaseNode {
|