Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | 98x 2x 2x 2x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 14x 14x 14x 18x 18x 18x 18x 14x 6x 6x 6x 6x 6x 6x 6x 14x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 14x 14x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 29x 29x 29x 98x 98x 24x 24x 24x 24x 10x 10x 10x 10x 10x 24x 24x 29x 24x 24x 5x 5x 5x 5x 24x 24x 24x 24x 24x 24x 98x 15x 15x 15x 15x 15x 15x 15x 15x 15x 16x 16x 15x 15x 26x 26x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 2x 2x 15x 15x 15x 2x 2x 2x 2x 2x 2x 2x 15x 98x 98x 1x 1x 1x 1x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x | import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, SendBroadcast } from '../../store/flow-definition';
import {
renderMixedList,
renderClamped,
renderHighlightedText
} from '../utils';
import { Icon } from '../../Icons';
import { CustomEventType } from '../../interfaces';
export const send_broadcast: ActionConfig = {
name: 'Send Broadcast',
group: ACTION_GROUPS.broadcast,
flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
render: (_node: Node, action: SendBroadcast) => {
const recipients = [
...(action.groups || []).map((g) => ({
name: g.name,
icon: Icon.group,
uuid: g.uuid,
eventType: CustomEventType.GroupClicked
})),
...(action.contacts || []).map((c) => ({
name: c.name,
icon: Icon.contacts,
uuid: c.uuid,
eventType: CustomEventType.ContactClicked
})),
...(action.legacy_vars || []).map((v) => ({
name: v,
icon: Icon.contacts,
content: renderHighlightedText(v, true)
}))
];
return html`<div>
<div>${renderMixedList(recipients)}</div>
<div style="margin-top: 0.5em">
${action.template
? html`<div
style="border: 1px solid #7dc8bc;padding: 0.5em;margin-bottom: 0.5em;border-radius: 4px; display:flex;align-items: flex-start;background: #f0faf7;color: #128C7E;font-size: 0.85em;"
>
<temba-icon
name="channel_wac"
style="--icon-size: 14px;"
></temba-icon>
<div style="margin-left:0.4em">${action.template.name}</div>
</div>`
: null}
${renderClamped(renderHighlightedText(action.text, true), action.text)}
</div>
</div>`;
},
form: {
recipients: {
type: 'select',
label: 'Recipients',
helpText: 'Select the contacts or groups to receive the broadcast',
multi: true,
searchable: true,
endpoint: '/contact/omnibox/?types=gc',
queryParam: 'search',
valueKey: 'id',
nameKey: 'name',
placeholder: 'Search for contacts or groups...',
required: true,
expressions: 'session'
},
text: {
type: 'message-editor',
label: 'Message',
helpText:
'Enter the message to send with optional attachments. You can use expressions like @contact.name',
required: true,
evaluated: true,
placeholder: 'Type your message here...',
maxLength: 640,
maxAttachments: 10,
accept: '',
endpoint: '/api/v2/media.json',
counter: 'temba-charcount',
gsm: true,
autogrow: true
},
template: {
type: 'template-editor',
endpoint: '/api/internal/templates.json'
}
},
layout: [
'recipients',
'text',
{
type: 'accordion',
sections: [
{
label: 'WhatsApp Template',
collapsed: true,
localizable: false,
getValueCount: (formData: FormData) => {
return !!formData.template;
},
items: ['template']
}
]
}
],
toFormData: (action: SendBroadcast) => {
return {
uuid: action.uuid,
recipients: [
...(action.contacts || []).map((c) => ({
id: c.uuid,
name: c.name,
type: 'contact'
})),
...(action.groups || []).map((g) => ({
id: g.uuid,
name: g.name,
type: 'group'
})),
...(action.legacy_vars || []).map((v) => ({
id: v,
name: v,
type: 'expression'
}))
],
text: action.text || '',
attachments: action.attachments || [],
template: action.template || null,
template_variables: action.template_variables || []
};
},
fromFormData: (formData: FormData): SendBroadcast => {
const recipients = formData.recipients || [];
const contacts = recipients
.filter(
(r: any) => r.type === 'contact' || (!r.type && !r.expression && r.id)
)
.map((c: any) => ({ uuid: c.id, name: c.name }));
const groups = recipients
.filter((r: any) => r.type === 'group')
.map((g: any) => ({ uuid: g.id, name: g.name }));
const legacy_vars = recipients
.filter((r: any) => r.type === 'expression' || r.expression)
.map((e: any) => e.value || e.name || e.id);
const result: SendBroadcast = {
uuid: formData.uuid,
type: 'send_broadcast',
text: formData.text || '',
contacts,
groups,
attachments: formData.attachments || []
};
if (legacy_vars.length > 0) {
result.legacy_vars = legacy_vars;
}
// Remove empty attachments array to match original format
if (result.attachments.length === 0) {
delete result.attachments;
}
// Add template and template_variables if a template is selected
if (formData.template) {
result.template = formData.template;
result.template_variables = formData.template_variables || [];
}
return result;
},
sanitize: (formData: FormData): void => {
if (formData.text && typeof formData.text === 'string') {
formData.text = formData.text.trim();
}
},
localizable: ['text', 'attachments'],
toLocalizationFormData: (
action: SendBroadcast,
localization: Record<string, any>
) => {
const formData: FormData = {
uuid: action.uuid
};
if (localization.text && Array.isArray(localization.text)) {
formData.text = localization.text[0] || '';
} else {
formData.text = '';
}
if (localization.attachments && Array.isArray(localization.attachments)) {
formData.attachments = localization.attachments;
} else {
formData.attachments = [];
}
return formData;
},
fromLocalizationFormData: (formData: FormData, action: SendBroadcast) => {
const localization: Record<string, any> = {};
if (formData.text && formData.text.trim() !== '') {
if (formData.text !== action.text) {
localization.text = [formData.text];
}
}
const attachments = (formData.attachments || []).filter(
(att: string) => att && att.trim() !== ''
);
if (attachments.length > 0) {
if (
JSON.stringify(attachments) !== JSON.stringify(action.attachments || [])
) {
localization.attachments = attachments;
}
}
return localization;
}
};
|