@capillarytech/creatives-library 8.0.87-alpha.18 → 8.0.87-alpha.2
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/initialState.js +0 -1
- package/package.json +1 -1
- package/services/api.js +7 -6
- package/v2Components/CapWhatsappCTA/messages.js +4 -0
- package/v2Components/CapWhatsappCarouselButton/constant.js +51 -0
- package/v2Components/CapWhatsappCarouselButton/index.js +446 -0
- package/v2Components/CapWhatsappCarouselButton/index.scss +39 -0
- package/v2Components/FormBuilder/index.js +3 -7
- package/v2Components/TemplatePreview/_templatePreview.scss +9 -0
- package/v2Components/TemplatePreview/assets/images/empty_image_preview.svg +4 -0
- package/v2Components/TemplatePreview/assets/images/empty_video_preview.svg +4 -0
- package/v2Components/TemplatePreview/index.js +169 -104
- package/v2Containers/Cap/actions.js +0 -8
- package/v2Containers/Cap/constants.js +0 -4
- package/v2Containers/Cap/reducer.js +0 -6
- package/v2Containers/Cap/sagas.js +0 -23
- package/v2Containers/Cap/selectors.js +0 -6
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +0 -1
- package/v2Containers/CreativesContainer/SlideBoxContent.js +1 -11
- package/v2Containers/CreativesContainer/constants.js +0 -3
- package/v2Containers/CreativesContainer/index.js +88 -78
- package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +0 -25
- package/v2Containers/CreativesContainer/tests/index.test.js +0 -2
- package/v2Containers/Email/index.js +0 -1
- package/v2Containers/EmailWrapper/index.js +0 -2
- package/v2Containers/MobilePush/Create/index.js +0 -1
- package/v2Containers/MobilePush/Edit/index.js +0 -1
- package/v2Containers/MobilepushWrapper/index.js +1 -2
- package/v2Containers/Sms/Create/index.js +0 -1
- package/v2Containers/Sms/Edit/index.js +0 -1
- package/v2Containers/SmsWrapper/index.js +0 -2
- package/v2Containers/Templates/_templates.scss +35 -0
- package/v2Containers/Templates/index.js +64 -5
- package/v2Containers/TemplatesV2/index.js +0 -7
- package/v2Containers/Whatsapp/constants.js +83 -1
- package/v2Containers/Whatsapp/index.js +709 -182
- package/v2Containers/Whatsapp/index.scss +52 -1
- package/v2Containers/Whatsapp/messages.js +38 -2
- package/v2Containers/Whatsapp/utils.js +34 -0
- package/v2Containers/mockdata.js +0 -3
- package/utils/transformerUtils.js +0 -524
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
// Import channel constants from the existing constants file
|
|
2
|
-
import {
|
|
3
|
-
SMS,
|
|
4
|
-
EMAIL,
|
|
5
|
-
MOBILE_PUSH,
|
|
6
|
-
WHATSAPP,
|
|
7
|
-
PUSH,
|
|
8
|
-
ZALO
|
|
9
|
-
} from "../v2Containers/CreativesContainer/constants";
|
|
10
|
-
|
|
11
|
-
// Transforms the channel payload based on the channel type
|
|
12
|
-
/**
|
|
13
|
-
* General transformer function that handles different channel types
|
|
14
|
-
* @param {Object} data - The input data
|
|
15
|
-
* @param {Object} options - Additional options for transformation
|
|
16
|
-
* @returns {Object} - Transformed payload based on channel type
|
|
17
|
-
*/
|
|
18
|
-
export const transformChannelPayload = (data, options = {}) => {
|
|
19
|
-
const channel = data.channel?.toUpperCase();
|
|
20
|
-
|
|
21
|
-
switch (channel) {
|
|
22
|
-
case SMS:
|
|
23
|
-
return transformSmsPayload(data, options);
|
|
24
|
-
case MOBILE_PUSH:
|
|
25
|
-
return transformMpushPayload(data, options);
|
|
26
|
-
case EMAIL:
|
|
27
|
-
return transformEmailPayload(data, options);
|
|
28
|
-
case WHATSAPP:
|
|
29
|
-
return transformWhatsappPayload(data, options);
|
|
30
|
-
case ZALO:
|
|
31
|
-
return transformZaloPayload(data, options);
|
|
32
|
-
default:
|
|
33
|
-
return data; // Return unchanged for unsupported channels
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Transforms SMS data to the required payload format
|
|
38
|
-
* @param {Object} smsData - Current SMS data
|
|
39
|
-
* @param {Object} options - Additional options (ouId, sourceEntityId, etc.)
|
|
40
|
-
* @returns {Object} - Transformed SMS payload
|
|
41
|
-
*/
|
|
42
|
-
const transformSmsPayload = (smsData, options = {}) => {
|
|
43
|
-
const { channel, loyaltyMetaData = {} } = options;
|
|
44
|
-
|
|
45
|
-
const {
|
|
46
|
-
actionId,
|
|
47
|
-
actionName,
|
|
48
|
-
ouId,
|
|
49
|
-
clientName,
|
|
50
|
-
module,
|
|
51
|
-
metaId,
|
|
52
|
-
setMetaId = () => {},
|
|
53
|
-
transformedMessageDetails = {}
|
|
54
|
-
} = loyaltyMetaData;
|
|
55
|
-
|
|
56
|
-
const { smsDeliverySettings } = transformedMessageDetails;
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
centralCommsPayload: {
|
|
60
|
-
ouId: ouId || -1,
|
|
61
|
-
sourceEntityId: actionId,
|
|
62
|
-
channel: SMS,
|
|
63
|
-
module,
|
|
64
|
-
smsMessageContent: {
|
|
65
|
-
channel: SMS,
|
|
66
|
-
message: smsData.messageBody || ""
|
|
67
|
-
},
|
|
68
|
-
smsDeliverySettings: smsDeliverySettings || {},
|
|
69
|
-
executionParams: {},
|
|
70
|
-
clientName: clientName || "EMF"
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Transforms Email data to the required payload format
|
|
76
|
-
* @param {Object} emailData - Current email data
|
|
77
|
-
* @param {Object} options - Additional options (ouId, sourceEntityId, etc.)
|
|
78
|
-
* @returns {Object} - Transformed Email payload
|
|
79
|
-
*/
|
|
80
|
-
const transformEmailPayload = (emailData, options = {}) => {
|
|
81
|
-
const { loyaltyMetaData = {} } = options;
|
|
82
|
-
|
|
83
|
-
const {
|
|
84
|
-
actionId,
|
|
85
|
-
actionName,
|
|
86
|
-
ouId,
|
|
87
|
-
clientName,
|
|
88
|
-
module,
|
|
89
|
-
metaId,
|
|
90
|
-
setMetaId = () => {},
|
|
91
|
-
transformedMessageDetails = {}
|
|
92
|
-
} = loyaltyMetaData;
|
|
93
|
-
|
|
94
|
-
const { emailDeliverySettings = {} } = transformedMessageDetails;
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
centralCommsPayload: {
|
|
98
|
-
ouId: ouId || -1,
|
|
99
|
-
sourceEntityId: actionId,
|
|
100
|
-
channel: EMAIL,
|
|
101
|
-
module,
|
|
102
|
-
emailMessageContent: {
|
|
103
|
-
channel: EMAIL,
|
|
104
|
-
messageBody: emailData.emailBody || "",
|
|
105
|
-
messageSubject: emailData.emailSubject || ""
|
|
106
|
-
},
|
|
107
|
-
emailDeliverySettings: emailDeliverySettings || {},
|
|
108
|
-
executionParams: {},
|
|
109
|
-
clientName: clientName || "EMF"
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Transforms Mobile Push data to the required payload format
|
|
115
|
-
* @param {Object} mpushData - Current mobile push data
|
|
116
|
-
* @param {Object} options - Additional options (ouId, sourceEntityId, etc.)
|
|
117
|
-
* @returns {Object} - Transformed Mobile Push payload
|
|
118
|
-
*/
|
|
119
|
-
const transformMpushPayload = (mpushData, options = {}) => {
|
|
120
|
-
const { loyaltyMetaData = {} } = options;
|
|
121
|
-
|
|
122
|
-
const {
|
|
123
|
-
actionId,
|
|
124
|
-
actionName,
|
|
125
|
-
ouId,
|
|
126
|
-
clientName,
|
|
127
|
-
module,
|
|
128
|
-
metaId,
|
|
129
|
-
setMetaId = () => {},
|
|
130
|
-
transformedMessageDetails = {}
|
|
131
|
-
} = loyaltyMetaData;
|
|
132
|
-
|
|
133
|
-
const { mobilePushDeliverySettings = {} } = transformedMessageDetails;
|
|
134
|
-
|
|
135
|
-
// Set default values for androidContent if not provided
|
|
136
|
-
const androidContent = mpushData.androidContent || {};
|
|
137
|
-
|
|
138
|
-
// Set default values for iosContent if needed
|
|
139
|
-
const iosContent = mpushData.iosContent || {
|
|
140
|
-
type: androidContent.type || "TEXT",
|
|
141
|
-
deviceType: "IOS",
|
|
142
|
-
title: mpushData.messageSubject || "",
|
|
143
|
-
message: ""
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
centralCommsPayload: {
|
|
148
|
-
channel: PUSH,
|
|
149
|
-
ouId: ouId || -1,
|
|
150
|
-
sourceEntityId: actionId,
|
|
151
|
-
clientName: clientName || "VENENO",
|
|
152
|
-
module,
|
|
153
|
-
mpushMessageContent: {
|
|
154
|
-
channel: PUSH,
|
|
155
|
-
messageSubject: mpushData.messageSubject || "",
|
|
156
|
-
androidContent: {
|
|
157
|
-
type: androidContent.type || "TEXT",
|
|
158
|
-
deviceType: "ANDROID",
|
|
159
|
-
title: androidContent.title || "",
|
|
160
|
-
message: androidContent.message || "",
|
|
161
|
-
cta: {
|
|
162
|
-
type: "EXTERNAL_URL",
|
|
163
|
-
actionText: null,
|
|
164
|
-
templateCtaId: null,
|
|
165
|
-
actionLink: androidContent.cta?.actionLink || ""
|
|
166
|
-
},
|
|
167
|
-
expandableDetails: {
|
|
168
|
-
style: androidContent.expandableDetails?.style || "BIG_TEXT",
|
|
169
|
-
message: androidContent.expandableDetails?.message || "",
|
|
170
|
-
ctas: androidContent.expandableDetails?.ctas || [],
|
|
171
|
-
image: androidContent.expandableDetails?.image || "",
|
|
172
|
-
categoryId: androidContent.expandableDetails?.categoryId || ""
|
|
173
|
-
},
|
|
174
|
-
customProperties: androidContent.custom || {}
|
|
175
|
-
},
|
|
176
|
-
iosContent: {
|
|
177
|
-
type: iosContent.type || "TEXT",
|
|
178
|
-
deviceType: "IOS",
|
|
179
|
-
title: iosContent.title || "",
|
|
180
|
-
message: iosContent.message || "",
|
|
181
|
-
cta: {
|
|
182
|
-
type: "EXTERNAL_URL",
|
|
183
|
-
actionText: null,
|
|
184
|
-
templateCtaId: null,
|
|
185
|
-
actionLink: iosContent.cta?.actionLink || ""
|
|
186
|
-
},
|
|
187
|
-
expandableDetails: {
|
|
188
|
-
style: iosContent.expandableDetails?.style || "BIG_TEXT",
|
|
189
|
-
message: iosContent.expandableDetails?.message || "",
|
|
190
|
-
ctas: iosContent.expandableDetails?.ctas || [],
|
|
191
|
-
image: iosContent.expandableDetails?.image || "",
|
|
192
|
-
categoryId: iosContent.expandableDetails?.categoryId || ""
|
|
193
|
-
},
|
|
194
|
-
customProperties: iosContent.custom || {}
|
|
195
|
-
},
|
|
196
|
-
accountId: mpushData.accountId || 0
|
|
197
|
-
},
|
|
198
|
-
mpushDeliverySettings: mobilePushDeliverySettings || {}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Transforms WhatsApp data to the required payload format
|
|
204
|
-
* @param {Object} whatsappData - Current WhatsApp data
|
|
205
|
-
* @param {Object} options - Additional options (ouId, sourceEntityId, etc.)
|
|
206
|
-
* @returns {Object} - Transformed WhatsApp payload
|
|
207
|
-
*/
|
|
208
|
-
const transformWhatsappPayload = (whatsappData, options = {}) => {
|
|
209
|
-
const { loyaltyMetaData = {} } = options;
|
|
210
|
-
|
|
211
|
-
const {
|
|
212
|
-
actionId,
|
|
213
|
-
actionName,
|
|
214
|
-
ouId,
|
|
215
|
-
clientName,
|
|
216
|
-
module,
|
|
217
|
-
metaId,
|
|
218
|
-
setMetaId = () => {},
|
|
219
|
-
transformedMessageDetails = {}
|
|
220
|
-
} = loyaltyMetaData;
|
|
221
|
-
|
|
222
|
-
const { whatsappDeliverySettings = {} } = transformedMessageDetails;
|
|
223
|
-
|
|
224
|
-
// Get template configurations or set defaults
|
|
225
|
-
const templateConfigs = whatsappData.templateConfigs || {};
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
centralCommsPayload: {
|
|
229
|
-
ouId: ouId || -1,
|
|
230
|
-
sourceEntityId: actionId,
|
|
231
|
-
channel: WHATSAPP,
|
|
232
|
-
module,
|
|
233
|
-
whatsappMessageContent: {
|
|
234
|
-
messageBody: whatsappData.messageBody || "",
|
|
235
|
-
accountId: whatsappData.accountId || 0,
|
|
236
|
-
templateConfigs,
|
|
237
|
-
channel: WHATSAPP
|
|
238
|
-
},
|
|
239
|
-
whatsappDeliverySettings: whatsappDeliverySettings || {},
|
|
240
|
-
executionParams: {},
|
|
241
|
-
clientName: clientName || "VENENO"
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Transforms Zalo data to the required payload format
|
|
247
|
-
* @param {Object} zaloData - Current Zalo data
|
|
248
|
-
* @param {Object} options - Additional options (ouId, sourceEntityId, etc.)
|
|
249
|
-
* @returns {Object} - Transformed Zalo payload
|
|
250
|
-
*/
|
|
251
|
-
const transformZaloPayload = (zaloData, options = {}) => {
|
|
252
|
-
const { loyaltyMetaData = {} } = options;
|
|
253
|
-
|
|
254
|
-
const {
|
|
255
|
-
actionId,
|
|
256
|
-
actionName,
|
|
257
|
-
ouId,
|
|
258
|
-
clientName,
|
|
259
|
-
module,
|
|
260
|
-
metaId,
|
|
261
|
-
setMetaId = () => {},
|
|
262
|
-
transformedMessageDetails = {}
|
|
263
|
-
} = loyaltyMetaData;
|
|
264
|
-
|
|
265
|
-
const { zaloDeliverySettings = {} } = transformedMessageDetails;
|
|
266
|
-
|
|
267
|
-
// Get template configurations or set defaults
|
|
268
|
-
const templateConfigs = zaloData.templateConfigs || {};
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
centralCommsPayload: {
|
|
272
|
-
ouId: ouId || -1,
|
|
273
|
-
sourceEntityId: actionId,
|
|
274
|
-
channel: ZALO,
|
|
275
|
-
module,
|
|
276
|
-
zaloMessageContent: {
|
|
277
|
-
channel: ZALO,
|
|
278
|
-
messageBody: zaloData.messageBody || "",
|
|
279
|
-
accountId: zaloData.accountId || "",
|
|
280
|
-
accountName: zaloData.accountName || "",
|
|
281
|
-
templateConfigs,
|
|
282
|
-
token: zaloData.token || ""
|
|
283
|
-
},
|
|
284
|
-
zaloDeliverySettings: zaloDeliverySettings || {},
|
|
285
|
-
executionParams: {},
|
|
286
|
-
clientName: clientName || "VENENO"
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// Checks if the template has changed
|
|
292
|
-
export const getTemplateDiffState = (channel, oldData, newData) => {
|
|
293
|
-
switch (channel.toUpperCase()) {
|
|
294
|
-
case SMS:
|
|
295
|
-
return checkSmsDiff(oldData, newData);
|
|
296
|
-
case EMAIL:
|
|
297
|
-
return checkEmailDiff(oldData, newData);
|
|
298
|
-
case MOBILE_PUSH:
|
|
299
|
-
case PUSH:
|
|
300
|
-
return checkPushDiff(oldData, newData);
|
|
301
|
-
case WHATSAPP:
|
|
302
|
-
return checkWhatsappDiff(oldData, newData);
|
|
303
|
-
case ZALO:
|
|
304
|
-
return checkZaloDiff(oldData, newData);
|
|
305
|
-
default:
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
/**
|
|
310
|
-
* Checks differences between old and new SMS data
|
|
311
|
-
* @param {Object} oldData - Previous SMS template data
|
|
312
|
-
* @param {Object} newData - Updated SMS template data
|
|
313
|
-
* @returns {Boolean} - Whether the template has changed
|
|
314
|
-
*/
|
|
315
|
-
const checkSmsDiff = (oldData, newData) => {
|
|
316
|
-
// Extract old message content
|
|
317
|
-
const oldMessage =
|
|
318
|
-
oldData?.transformedMessageDetails?.smsMessageContent?.message || "";
|
|
319
|
-
|
|
320
|
-
// Extract new message content
|
|
321
|
-
const newMessage = newData?.messageBody || "";
|
|
322
|
-
|
|
323
|
-
// Compare message content
|
|
324
|
-
return oldMessage !== newMessage;
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* Checks differences between old and new Email data
|
|
328
|
-
* @param {Object} oldData - Previous Email template data
|
|
329
|
-
* @param {Object} newData - Updated Email template data
|
|
330
|
-
* @returns {Boolean} - Whether the template has changed
|
|
331
|
-
*/
|
|
332
|
-
const checkEmailDiff = (oldData, newData) => {
|
|
333
|
-
// Extract old email content
|
|
334
|
-
const oldEmailBody =
|
|
335
|
-
oldData?.transformedMessageDetails?.emailMessageContent?.messageBody || "";
|
|
336
|
-
const oldEmailSubject =
|
|
337
|
-
oldData?.transformedMessageDetails?.emailMessageContent?.messageSubject ||
|
|
338
|
-
"";
|
|
339
|
-
|
|
340
|
-
// Extract new email content
|
|
341
|
-
const newEmailBody = newData?.emailBody || "";
|
|
342
|
-
const newEmailSubject = newData?.emailSubject || "";
|
|
343
|
-
|
|
344
|
-
// Compare both subject and body
|
|
345
|
-
return oldEmailBody !== newEmailBody || oldEmailSubject !== newEmailSubject;
|
|
346
|
-
};
|
|
347
|
-
/**
|
|
348
|
-
* Checks differences between old and new Push data
|
|
349
|
-
* @param {Object} oldData - Previous Push template data
|
|
350
|
-
* @param {Object} newData - Updated Push template data
|
|
351
|
-
* @returns {Boolean} - Whether the template has changed
|
|
352
|
-
*/
|
|
353
|
-
const checkPushDiff = (oldData, newData) => {
|
|
354
|
-
// Extract old push content
|
|
355
|
-
const oldAndroidContent =
|
|
356
|
-
oldData?.transformedMessageDetails?.mpushMessageContent?.androidContent ||
|
|
357
|
-
{};
|
|
358
|
-
const oldIosContent =
|
|
359
|
-
oldData?.transformedMessageDetails?.mpushMessageContent?.iosContent || {};
|
|
360
|
-
const oldSubject =
|
|
361
|
-
oldData?.transformedMessageDetails?.mpushMessageContent?.messageSubject ||
|
|
362
|
-
"";
|
|
363
|
-
|
|
364
|
-
// Extract new push content
|
|
365
|
-
const newAndroidContent = newData?.androidContent || {};
|
|
366
|
-
const newIosContent = newData?.iosContent || {};
|
|
367
|
-
const newSubject = newData?.messageSubject || "";
|
|
368
|
-
|
|
369
|
-
// Compare subject
|
|
370
|
-
if (oldSubject !== newSubject) return true;
|
|
371
|
-
|
|
372
|
-
// Compare Android content
|
|
373
|
-
if (oldAndroidContent.title !== newAndroidContent.title) return true;
|
|
374
|
-
if (oldAndroidContent.message !== newAndroidContent.message) return true;
|
|
375
|
-
if (oldAndroidContent.cta?.actionLink !== newAndroidContent.cta?.actionLink)
|
|
376
|
-
return true;
|
|
377
|
-
|
|
378
|
-
// Compare iOS content
|
|
379
|
-
if (oldIosContent.title !== newIosContent.title) return true;
|
|
380
|
-
if (oldIosContent.message !== newIosContent.message) return true;
|
|
381
|
-
if (oldIosContent.cta?.actionLink !== newIosContent.cta?.actionLink)
|
|
382
|
-
return true;
|
|
383
|
-
|
|
384
|
-
return false;
|
|
385
|
-
};
|
|
386
|
-
/**
|
|
387
|
-
* Checks differences between old and new WhatsApp data
|
|
388
|
-
* @param {Object} oldData - Previous WhatsApp template data
|
|
389
|
-
* @param {Object} newData - Updated WhatsApp template data
|
|
390
|
-
* @returns {Boolean} - Whether the template has changed
|
|
391
|
-
*/
|
|
392
|
-
const checkWhatsappDiff = (oldData, newData) => {
|
|
393
|
-
// Extract old WhatsApp content
|
|
394
|
-
const oldMessage =
|
|
395
|
-
oldData?.transformedMessageDetails?.whatsappMessageContent?.messageBody ||
|
|
396
|
-
"";
|
|
397
|
-
const oldTemplateConfigs =
|
|
398
|
-
oldData?.transformedMessageDetails?.whatsappMessageContent
|
|
399
|
-
?.templateConfigs || {};
|
|
400
|
-
|
|
401
|
-
// Extract new WhatsApp content
|
|
402
|
-
const newMessage = newData?.messageBody || "";
|
|
403
|
-
const newTemplateConfigs = newData?.templateConfigs || {};
|
|
404
|
-
|
|
405
|
-
// Compare message content
|
|
406
|
-
if (oldMessage !== newMessage) return true;
|
|
407
|
-
|
|
408
|
-
// If new data has template configs but old data doesn't, there is a change
|
|
409
|
-
if (
|
|
410
|
-
Object.keys(newTemplateConfigs).length > 0 &&
|
|
411
|
-
Object.keys(oldTemplateConfigs).length === 0
|
|
412
|
-
) {
|
|
413
|
-
return true;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// If both have template configs, perform detailed comparison
|
|
417
|
-
if (
|
|
418
|
-
Object.keys(newTemplateConfigs).length > 0 &&
|
|
419
|
-
Object.keys(oldTemplateConfigs).length > 0
|
|
420
|
-
) {
|
|
421
|
-
// Compare template names and IDs
|
|
422
|
-
if (oldTemplateConfigs.id !== newTemplateConfigs.id) return true;
|
|
423
|
-
if (oldTemplateConfigs.name !== newTemplateConfigs.name) return true;
|
|
424
|
-
if (oldTemplateConfigs.template !== newTemplateConfigs.template)
|
|
425
|
-
return true;
|
|
426
|
-
|
|
427
|
-
// Compare template variables
|
|
428
|
-
if (
|
|
429
|
-
JSON.stringify(oldTemplateConfigs.varMapped) !==
|
|
430
|
-
JSON.stringify(newTemplateConfigs.varMapped)
|
|
431
|
-
)
|
|
432
|
-
return true;
|
|
433
|
-
|
|
434
|
-
// Compare media settings
|
|
435
|
-
if (
|
|
436
|
-
JSON.stringify(oldTemplateConfigs.whatsappMedia) !==
|
|
437
|
-
JSON.stringify(newTemplateConfigs.whatsappMedia)
|
|
438
|
-
)
|
|
439
|
-
return true;
|
|
440
|
-
|
|
441
|
-
// Compare other template properties
|
|
442
|
-
if (oldTemplateConfigs.category !== newTemplateConfigs.category)
|
|
443
|
-
return true;
|
|
444
|
-
if (oldTemplateConfigs.language !== newTemplateConfigs.language)
|
|
445
|
-
return true;
|
|
446
|
-
if (oldTemplateConfigs.buttonType !== newTemplateConfigs.buttonType)
|
|
447
|
-
return true;
|
|
448
|
-
if (
|
|
449
|
-
JSON.stringify(oldTemplateConfigs.buttons) !==
|
|
450
|
-
JSON.stringify(newTemplateConfigs.buttons)
|
|
451
|
-
)
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Check if account details have changed
|
|
456
|
-
if (
|
|
457
|
-
oldData?.transformedMessageDetails?.whatsappMessageContent?.accountId !==
|
|
458
|
-
newData?.accountId
|
|
459
|
-
)
|
|
460
|
-
return true;
|
|
461
|
-
if (
|
|
462
|
-
oldData?.transformedMessageDetails?.whatsappMessageContent
|
|
463
|
-
?.sourceAccountIdentifier !== newData?.sourceAccountIdentifier
|
|
464
|
-
)
|
|
465
|
-
return true;
|
|
466
|
-
|
|
467
|
-
return false;
|
|
468
|
-
};
|
|
469
|
-
/**
|
|
470
|
-
* Checks differences between old and new Zalo data
|
|
471
|
-
* @param {Object} oldData - Previous Zalo template data
|
|
472
|
-
* @param {Object} newData - Updated Zalo template data
|
|
473
|
-
* @returns {Boolean} - Whether the template has changed
|
|
474
|
-
*/
|
|
475
|
-
const checkZaloDiff = (oldData, newData) => {
|
|
476
|
-
// Extract old Zalo content
|
|
477
|
-
const oldTemplateConfigs =
|
|
478
|
-
oldData?.transformedMessageDetails?.zaloMessageContent?.templateConfigs ||
|
|
479
|
-
{};
|
|
480
|
-
const oldAccountId =
|
|
481
|
-
oldData?.transformedMessageDetails?.zaloMessageContent?.accountId || "";
|
|
482
|
-
const oldToken =
|
|
483
|
-
oldData?.transformedMessageDetails?.zaloMessageContent?.token || "";
|
|
484
|
-
|
|
485
|
-
// Extract new Zalo content
|
|
486
|
-
const newTemplateConfigs = newData?.templateConfigs || {};
|
|
487
|
-
const newAccountId = newData?.accountId || "";
|
|
488
|
-
const newToken = newData?.token || "";
|
|
489
|
-
|
|
490
|
-
// Compare account ID
|
|
491
|
-
if (oldAccountId !== newAccountId) return true;
|
|
492
|
-
|
|
493
|
-
// Compare token
|
|
494
|
-
if (oldToken !== newToken) return true;
|
|
495
|
-
|
|
496
|
-
// If new data has template configs but old data doesn't, there is a change
|
|
497
|
-
if (
|
|
498
|
-
Object.keys(newTemplateConfigs).length > 0 &&
|
|
499
|
-
Object.keys(oldTemplateConfigs).length === 0
|
|
500
|
-
) {
|
|
501
|
-
return true;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// If both have template configs, perform detailed comparison
|
|
505
|
-
if (
|
|
506
|
-
Object.keys(newTemplateConfigs).length > 0 &&
|
|
507
|
-
Object.keys(oldTemplateConfigs).length > 0
|
|
508
|
-
) {
|
|
509
|
-
// Compare template IDs and names
|
|
510
|
-
if (oldTemplateConfigs.id !== newTemplateConfigs.id) return true;
|
|
511
|
-
if (oldTemplateConfigs.name !== newTemplateConfigs.name) return true;
|
|
512
|
-
if (oldTemplateConfigs.template !== newTemplateConfigs.template)
|
|
513
|
-
return true;
|
|
514
|
-
|
|
515
|
-
// Compare template variables
|
|
516
|
-
if (
|
|
517
|
-
JSON.stringify(oldTemplateConfigs.varMapped) !==
|
|
518
|
-
JSON.stringify(newTemplateConfigs.varMapped)
|
|
519
|
-
)
|
|
520
|
-
return true;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
return false;
|
|
524
|
-
};
|