@dev.smartpricing/message-composer-layer 5.0.0 → 5.0.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.
|
@@ -51,6 +51,12 @@ function handleButtonAdded(button: WaButtonV1) {
|
|
|
51
51
|
* Syncs button removal to all other languages
|
|
52
52
|
*/
|
|
53
53
|
function handleButtonRemoved(buttonId: string) {
|
|
54
|
+
// A message has at most one unsubscribe button: if the main language has none,
|
|
55
|
+
// drop it from translations too, even when older data gave it a different ID
|
|
56
|
+
const mainHasUnsubscribe = model.value.body.buttons.buttons.some(
|
|
57
|
+
(btn) => btn.type === 'unsubscribe',
|
|
58
|
+
)
|
|
59
|
+
|
|
54
60
|
for (const langId in props.messages) {
|
|
55
61
|
if (langId === props.mainLanguageId) continue
|
|
56
62
|
|
|
@@ -59,7 +65,7 @@ function handleButtonRemoved(buttonId: string) {
|
|
|
59
65
|
|
|
60
66
|
// Remove button by ID
|
|
61
67
|
targetMsg.body.buttons.buttons = targetMsg.body.buttons.buttons.filter(
|
|
62
|
-
(btn) => btn.id !== buttonId,
|
|
68
|
+
(btn) => btn.id !== buttonId && (mainHasUnsubscribe || btn.type !== 'unsubscribe'),
|
|
63
69
|
)
|
|
64
70
|
targetMsg.body.buttons.enabled = targetMsg.body.buttons.buttons.length > 0
|
|
65
71
|
}
|
|
@@ -13,40 +13,38 @@ interface UseWhatsappTemplateBehaviorsOptions {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function useWhatsappTemplateBehaviors(options: UseWhatsappTemplateBehaviorsOptions) {
|
|
16
|
-
const { messages } = options
|
|
17
|
-
|
|
18
|
-
// Watch for category changes
|
|
19
|
-
// watch(
|
|
20
|
-
// () => category.value,
|
|
21
|
-
// (newCategory, oldCategory) => {
|
|
22
|
-
// // Only add unsubscribe button if category changed to "marketing"
|
|
23
|
-
// if (newCategory === 'marketing' && oldCategory !== 'marketing') {
|
|
24
|
-
// addUnsubscribeButtonIfNotExists()
|
|
25
|
-
// }
|
|
26
|
-
// },
|
|
27
|
-
// { immediate: false },
|
|
28
|
-
// )
|
|
16
|
+
const { category, messages } = options
|
|
29
17
|
|
|
30
18
|
async function addUnsubscribeButtonIfNotExists() {
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
// Only marketing templates get an unsubscribe button
|
|
20
|
+
if (category.value !== 'marketing') return
|
|
21
|
+
|
|
22
|
+
const whatsappMessages = Object.values(messages.value).filter(
|
|
23
|
+
(message) => message.render_type === 'whatsapp_v1',
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// One id across all languages: button removal is synced to translations by id
|
|
27
|
+
const unsubscribeId =
|
|
28
|
+
whatsappMessages
|
|
29
|
+
.flatMap((message) => message.body.buttons.buttons)
|
|
30
|
+
.find((button) => button.type === 'unsubscribe')?.id ?? crypto.randomUUID()
|
|
31
|
+
|
|
32
|
+
for (const message of whatsappMessages) {
|
|
33
|
+
const buttons = message.body.buttons.buttons
|
|
34
|
+
const hasUnsubscribeButton = buttons.some((button) => button.type === 'unsubscribe')
|
|
35
|
+
|
|
36
|
+
// Add unsubscribe button if it doesn't exist
|
|
37
|
+
if (!hasUnsubscribeButton) {
|
|
38
|
+
const unsubscribeButton: WaButtonV1 = {
|
|
39
|
+
id: unsubscribeId,
|
|
40
|
+
type: 'unsubscribe',
|
|
41
|
+
text: await extractFromLocale(
|
|
42
|
+
'editor.whatsapp.buttons.default_text.unsubscribe',
|
|
43
|
+
message.language_id,
|
|
44
|
+
),
|
|
49
45
|
}
|
|
46
|
+
|
|
47
|
+
buttons.push(unsubscribeButton)
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev.smartpricing/message-composer-layer",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"vue-router": "^5.0.7",
|
|
36
36
|
"vue3-emoji-picker": "^1.1.8",
|
|
37
37
|
"zod": "^4.4.3",
|
|
38
|
-
"@dev.smartpricing/message-composer-utils": "5.0.
|
|
38
|
+
"@dev.smartpricing/message-composer-utils": "5.0.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@dev.smartpricing/platform-layer": "^0.0.23",
|