@vicacha-devs/medusa-plugin-notifications 0.0.0-stage → 0.1.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/.medusa/server/src/admin/index.cjs +4215 -0
- package/.medusa/server/src/admin/index.js +4193 -0
- package/.medusa/server/src/api/admin/mpn/broadcasts/route.js +99 -0
- package/.medusa/server/src/api/admin/mpn/channels/route.js +109 -0
- package/.medusa/server/src/api/admin/mpn/logs/route.js +33 -0
- package/.medusa/server/src/api/admin/mpn/mappings/[id]/route.js +33 -0
- package/.medusa/server/src/api/admin/mpn/mappings/route.js +51 -0
- package/.medusa/server/src/api/admin/mpn/render-template/route.js +37 -0
- package/.medusa/server/src/api/admin/mpn/sandbox/route.js +36 -0
- package/.medusa/server/src/api/admin/mpn/send/route.js +135 -0
- package/.medusa/server/src/api/admin/mpn/templates/[id]/route.js +77 -0
- package/.medusa/server/src/api/admin/mpn/templates/route.js +71 -0
- package/.medusa/server/src/api/admin/plugin/route.js +4 -0
- package/.medusa/server/src/api/middlewares.js +28 -0
- package/.medusa/server/src/api/store/mpn/consent/route.js +37 -0
- package/.medusa/server/src/api/store/mpn/webhooks/[provider]/route.js +97 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/api/validators.js +118 -0
- package/.medusa/server/src/hooks/index.js +7 -0
- package/.medusa/server/src/hooks/use-mpn-channels.js +13 -0
- package/.medusa/server/src/hooks/use-mpn-dispatch.js +45 -0
- package/.medusa/server/src/hooks/use-mpn-mappings.js +21 -0
- package/.medusa/server/src/hooks/use-mpn-templates.js +34 -0
- package/.medusa/server/src/hooks/use-order-notifications-widget-state.js +79 -0
- package/.medusa/server/src/hooks/use-sdk-primitives.js +113 -0
- package/.medusa/server/src/index.js +14 -0
- package/.medusa/server/src/integrations/automations-action-handler.js +112 -0
- package/.medusa/server/src/jobs/abandoned-cart-recovery.js +123 -0
- package/.medusa/server/src/jobs/log-retention-and-broadcasts.js +15 -0
- package/.medusa/server/src/modules/notifications/i18n/index.js +65 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/ar.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/de.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/en.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/es.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/fr.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/it.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/nl.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/pl.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/pt.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/tr.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/types.js +2 -0
- package/.medusa/server/src/modules/notifications/index.js +9 -0
- package/.medusa/server/src/modules/notifications/integrations/documents-and-b2b-resolver.js +129 -0
- package/.medusa/server/src/modules/notifications/migrations/Migration20261010000000.js +184 -0
- package/.medusa/server/src/modules/notifications/models/index.js +118 -0
- package/.medusa/server/src/modules/notifications/renderer/block-helpers.js +36 -0
- package/.medusa/server/src/modules/notifications/renderer/email.js +161 -0
- package/.medusa/server/src/modules/notifications/renderer/index.js +240 -0
- package/.medusa/server/src/modules/notifications/renderer/slack.js +114 -0
- package/.medusa/server/src/modules/notifications/renderer/telegram.js +99 -0
- package/.medusa/server/src/modules/notifications/renderer/whatsapp.js +91 -0
- package/.medusa/server/src/modules/notifications/service-helpers/channel-config.js +45 -0
- package/.medusa/server/src/modules/notifications/service-helpers/consent.js +65 -0
- package/.medusa/server/src/modules/notifications/service-helpers/delivery-log.js +29 -0
- package/.medusa/server/src/modules/notifications/service-helpers/event-conditions.js +46 -0
- package/.medusa/server/src/modules/notifications/service-helpers/external-templates.js +80 -0
- package/.medusa/server/src/modules/notifications/service-helpers/recipient-resolution.js +85 -0
- package/.medusa/server/src/modules/notifications/service-helpers/sender-profiles.js +29 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-blocks.js +81 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-catalog.js +129 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-render.js +65 -0
- package/.medusa/server/src/modules/notifications/service.js +339 -0
- package/.medusa/server/src/modules/notifications/types.js +2 -0
- package/.medusa/server/src/modules/notifications/utils/auth-presets.js +140 -0
- package/.medusa/server/src/modules/notifications/utils/interpolation.js +178 -0
- package/.medusa/server/src/modules/notifications/utils/security.js +312 -0
- package/.medusa/server/src/modules/notifications/utils/system-presets.js +651 -0
- package/.medusa/server/src/modules/notifications/utils/transformers.js +358 -0
- package/.medusa/server/src/providers/dummy-sandbox/index.js +96 -0
- package/.medusa/server/src/providers/email-smtp/index.js +187 -0
- package/.medusa/server/src/providers/index.js +7 -0
- package/.medusa/server/src/providers/slack/index.js +54 -0
- package/.medusa/server/src/providers/sms/index.js +254 -0
- package/.medusa/server/src/providers/telegram/index.js +119 -0
- package/.medusa/server/src/providers/whatsapp/index.js +371 -0
- package/.medusa/server/src/rbac.js +109 -0
- package/.medusa/server/src/sdk/client.js +186 -0
- package/.medusa/server/src/sdk/index.js +3 -0
- package/.medusa/server/src/sdk/query-keys.js +61 -0
- package/.medusa/server/src/subscribers/customer-and-document-events.js +33 -0
- package/.medusa/server/src/subscribers/fulfillment-and-inventory-events.js +30 -0
- package/.medusa/server/src/subscribers/order-events.js +28 -0
- package/.medusa/server/src/types/constants.js +129 -0
- package/.medusa/server/src/types/core.js +2 -0
- package/.medusa/server/src/types/domain.js +2 -0
- package/.medusa/server/src/types/enums.js +53 -0
- package/.medusa/server/src/types/errors.js +28 -0
- package/.medusa/server/src/types/hooks.js +2 -0
- package/.medusa/server/src/types/index.js +12 -0
- package/.medusa/server/src/types/providers.js +2 -0
- package/.medusa/server/src/types/records.js +2 -0
- package/.medusa/server/src/types/render.js +2 -0
- package/.medusa/server/src/types/sdk-api.js +2 -0
- package/.medusa/server/src/types/translations.js +2 -0
- package/.medusa/server/src/workflows/index.js +461 -0
- package/LICENSE +21 -0
- package/README.md +389 -2
- package/package.json +138 -3
- package/src/admin/README.md +123 -0
- package/src/admin/components/mpn/broadcast-consent-section.tsx +62 -0
- package/src/admin/components/mpn/broadcasts-tab.tsx +208 -0
- package/src/admin/components/mpn/channels-main-section.tsx +205 -0
- package/src/admin/components/mpn/channels-side-section.tsx +88 -0
- package/src/admin/components/mpn/channels-tab.tsx +130 -0
- package/src/admin/components/mpn/constants.ts +8 -0
- package/src/admin/components/mpn/delivery-logs-tab.tsx +70 -0
- package/src/admin/components/mpn/event-mapping-form.tsx +191 -0
- package/src/admin/components/mpn/event-mappings-tab.tsx +165 -0
- package/src/admin/components/mpn/header-bar.tsx +35 -0
- package/src/admin/components/mpn/index.ts +17 -0
- package/src/admin/components/mpn/overview-cards.tsx +103 -0
- package/src/admin/components/mpn/sandbox-tab.tsx +93 -0
- package/src/admin/components/mpn/template-editor-section.tsx +203 -0
- package/src/admin/components/mpn/template-preview-section.tsx +122 -0
- package/src/admin/components/mpn/templates-list-section.tsx +115 -0
- package/src/admin/components/mpn/templates-tab.tsx +188 -0
- package/src/admin/components/mpn/use-notification-studio.ts +84 -0
- package/src/admin/components/rbac-guard.tsx +153 -0
- package/src/admin/i18n/README.md +134 -0
- package/src/admin/i18n/index.ts +23 -0
- package/src/admin/i18n/json/ar.json +157 -0
- package/src/admin/i18n/json/de.json +157 -0
- package/src/admin/i18n/json/en.json +157 -0
- package/src/admin/i18n/json/es.json +157 -0
- package/src/admin/i18n/json/fr.json +157 -0
- package/src/admin/i18n/json/it.json +157 -0
- package/src/admin/i18n/json/nl.json +157 -0
- package/src/admin/i18n/json/pl.json +157 -0
- package/src/admin/i18n/json/pt.json +157 -0
- package/src/admin/i18n/json/tr.json +157 -0
- package/src/admin/routes/mpn/broadcasts/page.tsx +75 -0
- package/src/admin/routes/mpn/channels/page.tsx +66 -0
- package/src/admin/routes/mpn/logs/page.tsx +50 -0
- package/src/admin/routes/mpn/mappings/page.tsx +62 -0
- package/src/admin/routes/mpn/page.tsx +200 -0
- package/src/admin/routes/mpn/sandbox/page.tsx +53 -0
- package/src/admin/routes/mpn/templates/page.tsx +55 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/order-notifications-widget.tsx +178 -0
- package/src/api/README.md +98 -0
- package/src/api/admin/mpn/broadcasts/route.ts +130 -0
- package/src/api/admin/mpn/channels/route.ts +143 -0
- package/src/api/admin/mpn/logs/route.ts +41 -0
- package/src/api/admin/mpn/mappings/[id]/route.ts +45 -0
- package/src/api/admin/mpn/mappings/route.ts +68 -0
- package/src/api/admin/mpn/render-template/route.ts +46 -0
- package/src/api/admin/mpn/sandbox/route.ts +51 -0
- package/src/api/admin/mpn/send/route.ts +163 -0
- package/src/api/admin/mpn/templates/[id]/route.ts +101 -0
- package/src/api/admin/mpn/templates/route.ts +99 -0
- package/src/api/admin/plugin/route.ts +5 -0
- package/src/api/middlewares.ts +42 -0
- package/src/api/store/mpn/consent/route.ts +45 -0
- package/src/api/store/mpn/webhooks/[provider]/route.ts +119 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/api/validators.ts +149 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/use-mpn-channels.ts +43 -0
- package/src/hooks/use-mpn-dispatch.ts +149 -0
- package/src/hooks/use-mpn-mappings.ts +75 -0
- package/src/hooks/use-mpn-templates.ts +120 -0
- package/src/hooks/use-order-notifications-widget-state.ts +103 -0
- package/src/hooks/use-sdk-primitives.ts +157 -0
- package/src/index.ts +16 -0
- package/src/integrations/automations-action-handler.ts +156 -0
- package/src/jobs/README.md +41 -0
- package/src/jobs/abandoned-cart-recovery.ts +152 -0
- package/src/jobs/log-retention-and-broadcasts.ts +23 -0
- package/src/links/README.md +52 -0
- package/src/modules/README.md +99 -0
- package/src/modules/notifications/i18n/index.ts +83 -0
- package/src/modules/notifications/i18n/locales/ar.ts +84 -0
- package/src/modules/notifications/i18n/locales/de.ts +83 -0
- package/src/modules/notifications/i18n/locales/en.ts +84 -0
- package/src/modules/notifications/i18n/locales/es.ts +84 -0
- package/src/modules/notifications/i18n/locales/fr.ts +82 -0
- package/src/modules/notifications/i18n/locales/it.ts +82 -0
- package/src/modules/notifications/i18n/locales/nl.ts +83 -0
- package/src/modules/notifications/i18n/locales/pl.ts +84 -0
- package/src/modules/notifications/i18n/locales/pt.ts +82 -0
- package/src/modules/notifications/i18n/locales/tr.ts +86 -0
- package/src/modules/notifications/i18n/types.ts +1 -0
- package/src/modules/notifications/index.ts +10 -0
- package/src/modules/notifications/integrations/documents-and-b2b-resolver.ts +168 -0
- package/src/modules/notifications/migrations/Migration20261010000000.ts +185 -0
- package/src/modules/notifications/models/index.ts +125 -0
- package/src/modules/notifications/renderer/block-helpers.ts +51 -0
- package/src/modules/notifications/renderer/email.ts +281 -0
- package/src/modules/notifications/renderer/index.ts +301 -0
- package/src/modules/notifications/renderer/slack.ts +168 -0
- package/src/modules/notifications/renderer/telegram.ts +161 -0
- package/src/modules/notifications/renderer/whatsapp.ts +156 -0
- package/src/modules/notifications/service-helpers/channel-config.ts +65 -0
- package/src/modules/notifications/service-helpers/consent.ts +88 -0
- package/src/modules/notifications/service-helpers/delivery-log.ts +56 -0
- package/src/modules/notifications/service-helpers/event-conditions.ts +66 -0
- package/src/modules/notifications/service-helpers/external-templates.ts +127 -0
- package/src/modules/notifications/service-helpers/recipient-resolution.ts +124 -0
- package/src/modules/notifications/service-helpers/sender-profiles.ts +34 -0
- package/src/modules/notifications/service-helpers/template-blocks.ts +116 -0
- package/src/modules/notifications/service-helpers/template-catalog.ts +170 -0
- package/src/modules/notifications/service-helpers/template-render.ts +113 -0
- package/src/modules/notifications/service.ts +588 -0
- package/src/modules/notifications/types.ts +1 -0
- package/src/modules/notifications/utils/auth-presets.ts +145 -0
- package/src/modules/notifications/utils/interpolation.ts +231 -0
- package/src/modules/notifications/utils/security.ts +378 -0
- package/src/modules/notifications/utils/system-presets.ts +695 -0
- package/src/modules/notifications/utils/transformers.ts +456 -0
- package/src/providers/README.md +92 -0
- package/src/providers/dummy-sandbox/index.ts +143 -0
- package/src/providers/email-smtp/index.ts +257 -0
- package/src/providers/index.ts +38 -0
- package/src/providers/slack/index.ts +82 -0
- package/src/providers/sms/index.ts +342 -0
- package/src/providers/telegram/index.ts +181 -0
- package/src/providers/whatsapp/index.ts +505 -0
- package/src/rbac.ts +123 -0
- package/src/sdk/client.ts +319 -0
- package/src/sdk/index.ts +48 -0
- package/src/sdk/query-keys.ts +89 -0
- package/src/subscribers/README.md +50 -0
- package/src/subscribers/customer-and-document-events.ts +36 -0
- package/src/subscribers/fulfillment-and-inventory-events.ts +35 -0
- package/src/subscribers/order-events.ts +31 -0
- package/src/types/constants.ts +143 -0
- package/src/types/core.ts +96 -0
- package/src/types/domain.ts +84 -0
- package/src/types/enums.ts +73 -0
- package/src/types/errors.ts +32 -0
- package/src/types/hooks.ts +48 -0
- package/src/types/index.ts +11 -0
- package/src/types/providers.ts +96 -0
- package/src/types/records.ts +100 -0
- package/src/types/render.ts +74 -0
- package/src/types/sdk-api.ts +228 -0
- package/src/types/translations.ts +75 -0
- package/src/workflows/README.md +67 -0
- package/src/workflows/index.ts +619 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { TemplateBlockNode } from "../../../types"
|
|
2
|
+
|
|
3
|
+
export function isEmptyInterpolatedValue(value: unknown): boolean {
|
|
4
|
+
return (
|
|
5
|
+
value === undefined ||
|
|
6
|
+
value === null ||
|
|
7
|
+
(typeof value === "string" && value.trim() === "")
|
|
8
|
+
)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getBlockMeta(
|
|
12
|
+
node: TemplateBlockNode | Record<string, any>
|
|
13
|
+
): Record<string, any> {
|
|
14
|
+
return (node as any).metadata || (node as any).props || {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getBlockChildren(
|
|
18
|
+
node: TemplateBlockNode | Record<string, any>,
|
|
19
|
+
meta: Record<string, any>
|
|
20
|
+
): TemplateBlockNode[] {
|
|
21
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
22
|
+
return node.children
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(meta.itemBlocks) && meta.itemBlocks.length > 0) {
|
|
25
|
+
return meta.itemBlocks
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(meta.blocks) && meta.blocks.length > 0) {
|
|
28
|
+
return meta.blocks
|
|
29
|
+
}
|
|
30
|
+
return []
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function buildRepeaterItemContext(
|
|
34
|
+
data: Record<string, any>,
|
|
35
|
+
item: any,
|
|
36
|
+
arrayKey: string
|
|
37
|
+
): Record<string, any> {
|
|
38
|
+
if (item && typeof item === "object") {
|
|
39
|
+
return {
|
|
40
|
+
...data,
|
|
41
|
+
...item,
|
|
42
|
+
item,
|
|
43
|
+
...(arrayKey ? { [arrayKey]: item } : {}),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...data,
|
|
48
|
+
item,
|
|
49
|
+
...(arrayKey ? { [arrayKey]: item } : {}),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import type { TemplateBlockNode } from "../../../types"
|
|
2
|
+
import { getNestedValue, multiInterpolateString } from "../utils/interpolation"
|
|
3
|
+
import { escapeHtml } from "../utils/security"
|
|
4
|
+
import {
|
|
5
|
+
buildRepeaterItemContext,
|
|
6
|
+
getBlockChildren,
|
|
7
|
+
getBlockMeta,
|
|
8
|
+
isEmptyInterpolatedValue,
|
|
9
|
+
} from "./block-helpers"
|
|
10
|
+
|
|
11
|
+
export function renderEmailBlockNodes(
|
|
12
|
+
nodes: TemplateBlockNode[],
|
|
13
|
+
data: Record<string, any>,
|
|
14
|
+
translations: Record<string, any>,
|
|
15
|
+
primaryColor: string,
|
|
16
|
+
arrayPath?: string
|
|
17
|
+
): { htmlParts: string[]; textParts: string[] } {
|
|
18
|
+
const htmlParts: string[] = []
|
|
19
|
+
const textParts: string[] = []
|
|
20
|
+
|
|
21
|
+
for (const node of nodes) {
|
|
22
|
+
const meta = getBlockMeta(node)
|
|
23
|
+
const children = getBlockChildren(node, meta)
|
|
24
|
+
switch (node.type) {
|
|
25
|
+
case "heading": {
|
|
26
|
+
const rawText = String(meta.text ?? meta.value ?? "")
|
|
27
|
+
const plain = multiInterpolateString(
|
|
28
|
+
rawText,
|
|
29
|
+
{ data, translations },
|
|
30
|
+
{ arrayPath }
|
|
31
|
+
)
|
|
32
|
+
if (isEmptyInterpolatedValue(plain)) {
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
const level = Math.min(3, Math.max(1, Number(meta.level || 1)))
|
|
36
|
+
const align =
|
|
37
|
+
meta.align === "center" || meta.align === "right"
|
|
38
|
+
? meta.align
|
|
39
|
+
: "left"
|
|
40
|
+
const text = multiInterpolateString(
|
|
41
|
+
rawText,
|
|
42
|
+
{ data, translations },
|
|
43
|
+
{ escapeHtmlValues: true, arrayPath }
|
|
44
|
+
)
|
|
45
|
+
const fontSize = level === 1 ? "24px" : level === 2 ? "18px" : "15px"
|
|
46
|
+
htmlParts.push(
|
|
47
|
+
`<h${level} style="margin: 12px 0 8px; font-size: ${fontSize}; font-weight: 700; color: #111827; text-align: ${align};">${text}</h${level}>`
|
|
48
|
+
)
|
|
49
|
+
textParts.push(plain.toUpperCase())
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
case "text":
|
|
54
|
+
case "section": {
|
|
55
|
+
const rawText = String(meta.text ?? meta.value ?? "")
|
|
56
|
+
const plain = multiInterpolateString(
|
|
57
|
+
rawText,
|
|
58
|
+
{ data, translations },
|
|
59
|
+
{ arrayPath }
|
|
60
|
+
)
|
|
61
|
+
if (!isEmptyInterpolatedValue(plain)) {
|
|
62
|
+
const align =
|
|
63
|
+
meta.align === "center" || meta.align === "right"
|
|
64
|
+
? meta.align
|
|
65
|
+
: "left"
|
|
66
|
+
const text = multiInterpolateString(
|
|
67
|
+
rawText,
|
|
68
|
+
{ data, translations },
|
|
69
|
+
{ escapeHtmlValues: true, arrayPath }
|
|
70
|
+
).replace(/\n/g, "<br/>")
|
|
71
|
+
htmlParts.push(
|
|
72
|
+
`<p style="margin: 8px 0; font-size: 14px; line-height: 1.6; color: #374151; text-align: ${align};">${text}</p>`
|
|
73
|
+
)
|
|
74
|
+
textParts.push(plain)
|
|
75
|
+
}
|
|
76
|
+
if (children.length > 0) {
|
|
77
|
+
const childRendered = renderEmailBlockNodes(
|
|
78
|
+
children,
|
|
79
|
+
data,
|
|
80
|
+
translations,
|
|
81
|
+
primaryColor,
|
|
82
|
+
arrayPath
|
|
83
|
+
)
|
|
84
|
+
htmlParts.push(...childRendered.htmlParts)
|
|
85
|
+
textParts.push(...childRendered.textParts)
|
|
86
|
+
}
|
|
87
|
+
break
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
case "separator":
|
|
91
|
+
case "divider": {
|
|
92
|
+
htmlParts.push(
|
|
93
|
+
`<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />`
|
|
94
|
+
)
|
|
95
|
+
textParts.push("----------------------------------------")
|
|
96
|
+
break
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
case "row": {
|
|
100
|
+
const rawLabel = String(meta.label ?? "")
|
|
101
|
+
const rawValue = String(meta.value ?? "")
|
|
102
|
+
const plainValue = multiInterpolateString(
|
|
103
|
+
rawValue,
|
|
104
|
+
{ data, translations },
|
|
105
|
+
{ arrayPath }
|
|
106
|
+
)
|
|
107
|
+
if (isEmptyInterpolatedValue(plainValue)) {
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
const label = multiInterpolateString(
|
|
111
|
+
rawLabel,
|
|
112
|
+
{ data, translations },
|
|
113
|
+
{ escapeHtmlValues: true, arrayPath }
|
|
114
|
+
)
|
|
115
|
+
const value = multiInterpolateString(
|
|
116
|
+
rawValue,
|
|
117
|
+
{ data, translations },
|
|
118
|
+
{ escapeHtmlValues: true, arrayPath }
|
|
119
|
+
)
|
|
120
|
+
const weight = meta.bold ? "700" : "400"
|
|
121
|
+
const fontSize = meta.bold ? "15px" : "14px"
|
|
122
|
+
htmlParts.push(
|
|
123
|
+
`<table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="margin: 4px 0;"><tr><td style="font-size: ${fontSize}; font-weight: ${weight}; color: #4b5563; padding: 4px 0;">${label}</td><td align="right" style="font-size: ${fontSize}; font-weight: ${weight}; color: #111827; padding: 4px 0;">${value}</td></tr></table>`
|
|
124
|
+
)
|
|
125
|
+
textParts.push(
|
|
126
|
+
`${multiInterpolateString(rawLabel, { data, translations }, { arrayPath })}: ${plainValue}`
|
|
127
|
+
)
|
|
128
|
+
break
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
case "group": {
|
|
132
|
+
const contextKey = String(meta.contextKey || "").trim()
|
|
133
|
+
const scopedData = contextKey
|
|
134
|
+
? (getNestedValue(data, contextKey) as Record<string, any>) || data
|
|
135
|
+
: data
|
|
136
|
+
if (children.length > 0) {
|
|
137
|
+
const childRendered = renderEmailBlockNodes(
|
|
138
|
+
children,
|
|
139
|
+
scopedData,
|
|
140
|
+
translations,
|
|
141
|
+
primaryColor,
|
|
142
|
+
arrayPath
|
|
143
|
+
)
|
|
144
|
+
if (childRendered.htmlParts.length > 0) {
|
|
145
|
+
htmlParts.push(
|
|
146
|
+
`<div style="padding: 8px 12px; background: #f9fafb; border-radius: 6px; margin: 8px 0;">${childRendered.htmlParts.join("\n")}</div>`
|
|
147
|
+
)
|
|
148
|
+
textParts.push(...childRendered.textParts)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
break
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
case "repeater": {
|
|
155
|
+
const arrayKey = String(
|
|
156
|
+
meta.arrayKey || meta.arrayPath || "items"
|
|
157
|
+
).trim()
|
|
158
|
+
const list = getNestedValue(data, arrayKey)
|
|
159
|
+
if (Array.isArray(list) && list.length > 0 && children.length > 0) {
|
|
160
|
+
for (const item of list) {
|
|
161
|
+
const itemContext = buildRepeaterItemContext(data, item, arrayKey)
|
|
162
|
+
const childRendered = renderEmailBlockNodes(
|
|
163
|
+
children,
|
|
164
|
+
itemContext,
|
|
165
|
+
translations,
|
|
166
|
+
primaryColor,
|
|
167
|
+
arrayKey
|
|
168
|
+
)
|
|
169
|
+
htmlParts.push(...childRendered.htmlParts)
|
|
170
|
+
textParts.push(...childRendered.textParts)
|
|
171
|
+
}
|
|
172
|
+
} else if (
|
|
173
|
+
Array.isArray(meta.emptyBlocks) &&
|
|
174
|
+
meta.emptyBlocks.length > 0
|
|
175
|
+
) {
|
|
176
|
+
const emptyRendered = renderEmailBlockNodes(
|
|
177
|
+
meta.emptyBlocks,
|
|
178
|
+
data,
|
|
179
|
+
translations,
|
|
180
|
+
primaryColor,
|
|
181
|
+
arrayPath
|
|
182
|
+
)
|
|
183
|
+
htmlParts.push(...emptyRendered.htmlParts)
|
|
184
|
+
textParts.push(...emptyRendered.textParts)
|
|
185
|
+
}
|
|
186
|
+
break
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
case "product-item": {
|
|
190
|
+
if (meta.variant === "inventory_item") {
|
|
191
|
+
const sku = escapeHtml(data.sku || "N/A")
|
|
192
|
+
const title = escapeHtml(data.title || "Item")
|
|
193
|
+
const locationName = escapeHtml(data.location_name || "Warehouse")
|
|
194
|
+
const stocked = escapeHtml(data.stocked_quantity ?? 0)
|
|
195
|
+
const available = escapeHtml(data.available_quantity ?? 0)
|
|
196
|
+
htmlParts.push(
|
|
197
|
+
`<div style="padding: 12px; border: 1px solid #fecaca; background: #fef2f2; border-radius: 6px; margin: 8px 0;">
|
|
198
|
+
<div style="font-weight: 700; color: #991b1b; font-size: 14px;">${title} (SKU: ${sku})</div>
|
|
199
|
+
<div style="font-size: 13px; color: #7f1d1d; margin-top: 4px;">Location: ${locationName} | Available: <strong>${available}</strong> (Stocked: ${stocked})</div>
|
|
200
|
+
</div>`
|
|
201
|
+
)
|
|
202
|
+
textParts.push(
|
|
203
|
+
`[Inventory] ${data.title || "Item"} (SKU: ${data.sku || "N/A"}) - Location: ${data.location_name || "Warehouse"} | Available: ${data.available_quantity ?? 0}`
|
|
204
|
+
)
|
|
205
|
+
} else {
|
|
206
|
+
const title = escapeHtml(data.title || "Item")
|
|
207
|
+
const variantTitle = data.variant_title
|
|
208
|
+
? ` - ${escapeHtml(data.variant_title)}`
|
|
209
|
+
: ""
|
|
210
|
+
const sku =
|
|
211
|
+
meta.showSku && data.sku
|
|
212
|
+
? `<div style="font-size: 12px; color: #6b7280;">SKU: ${escapeHtml(data.sku)}</div>`
|
|
213
|
+
: ""
|
|
214
|
+
const qty = escapeHtml(data.quantity ?? 1)
|
|
215
|
+
const totalFormatted = escapeHtml(
|
|
216
|
+
data.total_formatted || data.unit_price_formatted || ""
|
|
217
|
+
)
|
|
218
|
+
htmlParts.push(
|
|
219
|
+
`<table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="border-bottom: 1px solid #f3f4f6; padding: 8px 0;">
|
|
220
|
+
<tr>
|
|
221
|
+
<td style="font-size: 14px; color: #111827; font-weight: 600;">${title}${variantTitle}${sku}</td>
|
|
222
|
+
<td align="right" style="font-size: 13px; color: #4b5563; white-space: nowrap;">x${qty} · <strong style="color: #111827;">${totalFormatted}</strong></td>
|
|
223
|
+
</tr>
|
|
224
|
+
</table>`
|
|
225
|
+
)
|
|
226
|
+
textParts.push(
|
|
227
|
+
`- ${data.title || "Item"}${data.variant_title ? ` (${data.variant_title})` : ""} x${data.quantity ?? 1}: ${data.total_formatted || ""}`
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
break
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
case "button":
|
|
234
|
+
case "actions": {
|
|
235
|
+
const buttons: Array<{ text?: string; title?: string; url?: string }> =
|
|
236
|
+
Array.isArray(meta.buttons)
|
|
237
|
+
? meta.buttons
|
|
238
|
+
: [{ text: meta.text, url: meta.url }]
|
|
239
|
+
const btnHtml: string[] = []
|
|
240
|
+
for (const b of buttons) {
|
|
241
|
+
const label = multiInterpolateString(
|
|
242
|
+
String(b.text || b.title || "Open"),
|
|
243
|
+
{ data, translations },
|
|
244
|
+
{ escapeHtmlValues: true, arrayPath }
|
|
245
|
+
)
|
|
246
|
+
const rawUrl = multiInterpolateString(
|
|
247
|
+
String(b.url || "#"),
|
|
248
|
+
{ data, translations },
|
|
249
|
+
{ arrayPath }
|
|
250
|
+
)
|
|
251
|
+
const safeUrl = /^https?:\/\//i.test(rawUrl)
|
|
252
|
+
? escapeHtml(rawUrl)
|
|
253
|
+
: "#"
|
|
254
|
+
btnHtml.push(
|
|
255
|
+
`<a href="${safeUrl}" style="display: inline-block; background: ${escapeHtml(primaryColor)}; color: #ffffff; text-decoration: none; padding: 10px 20px; border-radius: 6px; font-weight: 600; font-size: 14px; margin: 6px 4px;">${label}</a>`
|
|
256
|
+
)
|
|
257
|
+
textParts.push(`${label}: ${rawUrl}`)
|
|
258
|
+
}
|
|
259
|
+
htmlParts.push(
|
|
260
|
+
`<div style="text-align: ${meta.align === "left" ? "left" : "center"}; margin: 16px 0;">${btnHtml.join(" ")}</div>`
|
|
261
|
+
)
|
|
262
|
+
break
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
case "attachment": {
|
|
266
|
+
const desc = multiInterpolateString(
|
|
267
|
+
String(meta.description || "Attached PDF Document"),
|
|
268
|
+
{ data, translations },
|
|
269
|
+
{ escapeHtmlValues: true, arrayPath }
|
|
270
|
+
)
|
|
271
|
+
htmlParts.push(
|
|
272
|
+
`<div style="padding: 10px 14px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px; font-size: 13px; color: #1e40af; margin: 12px 0;">📎 ${desc}</div>`
|
|
273
|
+
)
|
|
274
|
+
textParts.push(`[Attachment: ${desc}]`)
|
|
275
|
+
break
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return { htmlParts, textParts }
|
|
281
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getNotificationTranslations,
|
|
3
|
+
isRtlLocale,
|
|
4
|
+
normalizeLocale,
|
|
5
|
+
} from "../i18n"
|
|
6
|
+
import type {
|
|
7
|
+
RenderedNotificationPayload,
|
|
8
|
+
RenderTemplateInput,
|
|
9
|
+
SupportedLocale,
|
|
10
|
+
TelegramInlineButton,
|
|
11
|
+
WhatsAppInteractiveButton,
|
|
12
|
+
} from "../../../types"
|
|
13
|
+
import {
|
|
14
|
+
applyVariableMap,
|
|
15
|
+
getNestedValue,
|
|
16
|
+
multiInterpolateObject,
|
|
17
|
+
multiInterpolateString,
|
|
18
|
+
} from "../utils/interpolation"
|
|
19
|
+
import {
|
|
20
|
+
calculateSmsSegments,
|
|
21
|
+
escapeHtml,
|
|
22
|
+
sanitizeNotificationHtml,
|
|
23
|
+
sanitizeTelegramHtml,
|
|
24
|
+
} from "../utils/security"
|
|
25
|
+
import { renderEmailBlockNodes } from "./email"
|
|
26
|
+
import { renderSlackBlocks } from "./slack"
|
|
27
|
+
import { renderTelegramNodes } from "./telegram"
|
|
28
|
+
import { renderWhatsAppNodes } from "./whatsapp"
|
|
29
|
+
|
|
30
|
+
export type { RenderTemplateInput } from "../../../types"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Unified Multi-Channel Notification Renderer.
|
|
34
|
+
* Compiles either a Hierarchical Block Tree (`mode === "blocks"`) or a Raw Template (`mode === "raw"`)
|
|
35
|
+
* into a channel-specific `RenderedNotificationPayload`.
|
|
36
|
+
*/
|
|
37
|
+
export function renderNotificationTemplate(
|
|
38
|
+
input: RenderTemplateInput
|
|
39
|
+
): RenderedNotificationPayload {
|
|
40
|
+
const locale: SupportedLocale = normalizeLocale(
|
|
41
|
+
input.locale || input.pluginOptions?.defaultLocale || "en"
|
|
42
|
+
)
|
|
43
|
+
const translations =
|
|
44
|
+
input.translations ||
|
|
45
|
+
getNotificationTranslations(locale, input.pluginOptions?.customTranslations)
|
|
46
|
+
|
|
47
|
+
const enrichedData = applyVariableMap(input.data || {}, input.variable_map)
|
|
48
|
+
const primaryColor = String(input.styles?.primary_color || "#111827")
|
|
49
|
+
const blocks = input.blocks || []
|
|
50
|
+
|
|
51
|
+
const interpolatedSubject = input.subject
|
|
52
|
+
? multiInterpolateString(input.subject, {
|
|
53
|
+
data: enrichedData,
|
|
54
|
+
translations,
|
|
55
|
+
})
|
|
56
|
+
: undefined
|
|
57
|
+
|
|
58
|
+
// 1. EMAIL CHANNEL
|
|
59
|
+
if (input.channel === "email") {
|
|
60
|
+
let htmlBody = ""
|
|
61
|
+
let plainText = ""
|
|
62
|
+
|
|
63
|
+
if (input.mode === "raw" && input.raw_content) {
|
|
64
|
+
const interpolatedRaw = multiInterpolateString(
|
|
65
|
+
input.raw_content,
|
|
66
|
+
{ data: enrichedData, translations },
|
|
67
|
+
{ escapeHtmlValues: true }
|
|
68
|
+
)
|
|
69
|
+
htmlBody = sanitizeNotificationHtml(interpolatedRaw)
|
|
70
|
+
plainText = htmlBody
|
|
71
|
+
.replace(/<[^>]+>/g, " ")
|
|
72
|
+
.replace(/\s+/g, " ")
|
|
73
|
+
.trim()
|
|
74
|
+
} else {
|
|
75
|
+
const { htmlParts, textParts } = renderEmailBlockNodes(
|
|
76
|
+
blocks,
|
|
77
|
+
enrichedData,
|
|
78
|
+
translations,
|
|
79
|
+
primaryColor
|
|
80
|
+
)
|
|
81
|
+
const storeName = escapeHtml(enrichedData.store_name || "Medusa Store")
|
|
82
|
+
const footerText = escapeHtml(
|
|
83
|
+
translations.general?.questionsContact || ""
|
|
84
|
+
)
|
|
85
|
+
htmlBody = `<!DOCTYPE html>
|
|
86
|
+
<html lang="${escapeHtml(locale)}" dir="${isRtlLocale(locale) ? "rtl" : "ltr"}">
|
|
87
|
+
<head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /></head>
|
|
88
|
+
<body style="margin: 0; padding: 24px; background-color: #f3f4f6; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;">
|
|
89
|
+
<table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="max-width: 600px; margin: 0 auto; background-color: #ffffff; border-radius: 8px; overflow: hidden; border: 1px solid #e5e7eb;">
|
|
90
|
+
<tr>
|
|
91
|
+
<td style="padding: 20px 24px; background-color: ${escapeHtml(primaryColor)}; color: #ffffff; font-weight: 700; font-size: 16px;">
|
|
92
|
+
${storeName}
|
|
93
|
+
</td>
|
|
94
|
+
</tr>
|
|
95
|
+
<tr>
|
|
96
|
+
<td style="padding: 24px;">
|
|
97
|
+
${htmlParts.join("\n ")}
|
|
98
|
+
</td>
|
|
99
|
+
</tr>
|
|
100
|
+
<tr>
|
|
101
|
+
<td style="padding: 16px 24px; background-color: #f9fafb; border-top: 1px solid #e5e7eb; font-size: 12px; color: #6b7280; text-align: center;">
|
|
102
|
+
${footerText}
|
|
103
|
+
</td>
|
|
104
|
+
</tr>
|
|
105
|
+
</table>
|
|
106
|
+
</body>
|
|
107
|
+
</html>`
|
|
108
|
+
plainText = textParts.join("\n\n")
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
channel: "email",
|
|
113
|
+
template_id: input.template_id,
|
|
114
|
+
template_name: input.template_name,
|
|
115
|
+
locale,
|
|
116
|
+
subject:
|
|
117
|
+
interpolatedSubject ||
|
|
118
|
+
`${enrichedData.store_name || "Store"} Notification`,
|
|
119
|
+
html: htmlBody,
|
|
120
|
+
text: plainText,
|
|
121
|
+
attachments: input.attachments || [],
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 2. WHATSAPP / OPENWA CHANNEL
|
|
126
|
+
if (input.channel === "whatsapp") {
|
|
127
|
+
let text = ""
|
|
128
|
+
let buttons: WhatsAppInteractiveButton[] = []
|
|
129
|
+
|
|
130
|
+
if (input.mode === "raw" && input.raw_content) {
|
|
131
|
+
text = multiInterpolateString(input.raw_content, {
|
|
132
|
+
data: enrichedData,
|
|
133
|
+
translations,
|
|
134
|
+
})
|
|
135
|
+
} else {
|
|
136
|
+
const rendered = renderWhatsAppNodes(blocks, enrichedData, translations)
|
|
137
|
+
text = rendered.lines.join("\n\n")
|
|
138
|
+
buttons = rendered.buttons
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Build Meta Cloud API template parameters from variable_map
|
|
142
|
+
const metaBodyParams: Array<{ type: "text"; text: string }> = []
|
|
143
|
+
if (input.variable_map && typeof input.variable_map === "object") {
|
|
144
|
+
for (const dataPath of Object.values(input.variable_map)) {
|
|
145
|
+
const val = getNestedValue(enrichedData, dataPath)
|
|
146
|
+
metaBodyParams.push({
|
|
147
|
+
type: "text",
|
|
148
|
+
text: val !== undefined && val !== null ? String(val) : "",
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const hasAttachments = Boolean(
|
|
154
|
+
input.attachments && input.attachments.length > 0
|
|
155
|
+
)
|
|
156
|
+
const messageType = hasAttachments
|
|
157
|
+
? "document"
|
|
158
|
+
: input.meta_template_name
|
|
159
|
+
? "template"
|
|
160
|
+
: buttons.length > 0
|
|
161
|
+
? "interactive"
|
|
162
|
+
: "text"
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
channel: "whatsapp",
|
|
166
|
+
template_id: input.template_id,
|
|
167
|
+
template_name: input.template_name,
|
|
168
|
+
locale,
|
|
169
|
+
text,
|
|
170
|
+
whatsapp_options: {
|
|
171
|
+
message_type: messageType,
|
|
172
|
+
meta_template_name: input.meta_template_name ?? null,
|
|
173
|
+
meta_language_code: input.meta_language_code || locale,
|
|
174
|
+
meta_components:
|
|
175
|
+
metaBodyParams.length > 0
|
|
176
|
+
? [{ type: "body", parameters: metaBodyParams }]
|
|
177
|
+
: [],
|
|
178
|
+
buttons,
|
|
179
|
+
},
|
|
180
|
+
attachments: input.attachments || [],
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 3. TELEGRAM CHANNEL
|
|
185
|
+
if (input.channel === "telegram") {
|
|
186
|
+
let htmlText = ""
|
|
187
|
+
let inlineKeyboard: TelegramInlineButton[][] = []
|
|
188
|
+
|
|
189
|
+
if (input.mode === "raw" && input.raw_content) {
|
|
190
|
+
const rawInterpolated = multiInterpolateString(input.raw_content, {
|
|
191
|
+
data: enrichedData,
|
|
192
|
+
translations,
|
|
193
|
+
})
|
|
194
|
+
htmlText = sanitizeTelegramHtml(rawInterpolated)
|
|
195
|
+
} else {
|
|
196
|
+
const rendered = renderTelegramNodes(blocks, enrichedData, translations)
|
|
197
|
+
htmlText = rendered.lines.join("\n\n")
|
|
198
|
+
inlineKeyboard = rendered.inlineKeyboard
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
channel: "telegram",
|
|
203
|
+
template_id: input.template_id,
|
|
204
|
+
template_name: input.template_name,
|
|
205
|
+
locale,
|
|
206
|
+
html: htmlText,
|
|
207
|
+
text: htmlText,
|
|
208
|
+
telegram_options: {
|
|
209
|
+
parse_mode: "HTML",
|
|
210
|
+
message_thread_id: input.telegram_thread_id ?? null,
|
|
211
|
+
inline_keyboard: inlineKeyboard,
|
|
212
|
+
disable_web_page_preview: true,
|
|
213
|
+
},
|
|
214
|
+
attachments: input.attachments || [],
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 4. SLACK CHANNEL
|
|
219
|
+
if (input.channel === "slack") {
|
|
220
|
+
let blocksJson: Array<Record<string, any>> = []
|
|
221
|
+
let fallbackText = ""
|
|
222
|
+
|
|
223
|
+
if (input.mode === "raw" && input.raw_content) {
|
|
224
|
+
try {
|
|
225
|
+
const parsed = JSON.parse(input.raw_content)
|
|
226
|
+
blocksJson = multiInterpolateObject(
|
|
227
|
+
Array.isArray(parsed) ? parsed : parsed.blocks || [],
|
|
228
|
+
{ data: enrichedData, translations }
|
|
229
|
+
)
|
|
230
|
+
fallbackText = interpolatedSubject || "Medusa Store Notification"
|
|
231
|
+
} catch {
|
|
232
|
+
fallbackText = multiInterpolateString(input.raw_content, {
|
|
233
|
+
data: enrichedData,
|
|
234
|
+
translations,
|
|
235
|
+
})
|
|
236
|
+
blocksJson = [
|
|
237
|
+
{
|
|
238
|
+
type: "section",
|
|
239
|
+
text: { type: "mrkdwn", text: fallbackText },
|
|
240
|
+
},
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
const rendered = renderSlackBlocks(blocks, enrichedData, translations)
|
|
245
|
+
blocksJson = rendered.blocks
|
|
246
|
+
fallbackText = rendered.fallbackText
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
channel: "slack",
|
|
251
|
+
template_id: input.template_id,
|
|
252
|
+
template_name: input.template_name,
|
|
253
|
+
locale,
|
|
254
|
+
text: fallbackText,
|
|
255
|
+
blocks_json: blocksJson,
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 5. SMS & DUMMY SANDBOX CHANNEL
|
|
260
|
+
let smsText = ""
|
|
261
|
+
if (input.mode === "raw" && input.raw_content) {
|
|
262
|
+
smsText = multiInterpolateString(input.raw_content, {
|
|
263
|
+
data: enrichedData,
|
|
264
|
+
translations,
|
|
265
|
+
})
|
|
266
|
+
} else {
|
|
267
|
+
const rendered = renderWhatsAppNodes(blocks, enrichedData, translations)
|
|
268
|
+
smsText = rendered.lines
|
|
269
|
+
.join(" ")
|
|
270
|
+
.replace(/[*_`]/g, "")
|
|
271
|
+
.replace(/\s+/g, " ")
|
|
272
|
+
.trim()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let consentFooterAppended = false
|
|
276
|
+
if (input.append_sms_consent_footer) {
|
|
277
|
+
const unsubscribeFooter =
|
|
278
|
+
translations.general?.unsubscribeSms || "Reply STOP to opt out."
|
|
279
|
+
if (!smsText.toLowerCase().includes("stop")) {
|
|
280
|
+
smsText = `${smsText.trim()} ${unsubscribeFooter}`
|
|
281
|
+
consentFooterAppended = true
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const segStats = calculateSmsSegments(smsText)
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
channel: input.channel,
|
|
289
|
+
template_id: input.template_id,
|
|
290
|
+
template_name: input.template_name,
|
|
291
|
+
locale,
|
|
292
|
+
subject: interpolatedSubject,
|
|
293
|
+
text: smsText,
|
|
294
|
+
sms_options: {
|
|
295
|
+
encoding: segStats.encoding,
|
|
296
|
+
segments: segStats.segments,
|
|
297
|
+
character_count: segStats.character_count,
|
|
298
|
+
consent_footer_appended: consentFooterAppended,
|
|
299
|
+
},
|
|
300
|
+
}
|
|
301
|
+
}
|