{{-- Instagram templates are local reusable DMs — no Meta category/language, no header/footer, and no "submit for review". When the channel is Instagram (chosen on the New-template modal) we hide those Meta-only sections so the form shows only what Instagram actually supports: name, body, media, and buttons. --}} @php $isIg = ($defaultChannel ?? '') === 'instagram'; // Facebook mirrors Instagram: a LOCAL reusable Messenger DM (no Meta // approval). Both hide the Meta-only category/language/header/attachment/ // footer sections and swap the submit label + preview chrome for the DM // look — $isLocalDm gates everything the two channels share. $isFb = ($defaultChannel ?? '') === 'facebook'; // Telegram mirrors Instagram/Facebook: a LOCAL reusable bot message (no // Meta approval). Same hidden Meta-only sections + DM chrome. $isTg = ($defaultChannel ?? '') === 'telegram'; $isLocalDm = $isIg || $isFb || $isTg; // Catalog templates are WhatsApp Cloud API (Meta official) ONLY. When the // format chooser opened this page with ?type=catalog we lock the whole // form to WABA — the send-channel picker below is filtered to WABA so the // only sender/device the form can resolve is a WhatsApp Business number. $isCatalog = request()->query('type') === 'catalog'; $catalogHasWaba = in_array('waba', $channels ?? [], true); // Built here (raw PHP) rather than inline in the textarea's Blade echo — // a literal {{name}} inside a {{ }} echo makes the Blade compiler choke // ("Unclosed '(' does not match '}'"). $bodyPlaceholder = $isTg ? __('Type your Telegram bot message. Press / to insert a variable like {{name}}.') : ($isFb ? __('Type your Messenger DM. Press / to insert a variable like {{name}}.') : ($isIg ? __('Type your Instagram DM. Press / to insert a variable like {{name}}.') : 'Type your message. Press / to insert a variable. Meta requires positional placeholders like {{1}} {{2}}.')); // Pre-built template prefill. $prefill is the admin blueprint (WaTemplate, // is_prebuilt) when the operator arrived via "Use this template" // (?from_prebuilt=…). Everything below falls back to old() first so a // validation round-trip still wins, then the blueprint, then the default. $prefill = $prefill ?? null; $pfId = $prefill->id ?? null; $pfMetaCat = strtolower((string) old('meta_category', $prefill->meta_category ?? ($prefill->category ?? 'utility'))); if (!in_array($pfMetaCat, ['marketing', 'utility', 'authentication'], true)) { $pfMetaCat = 'utility'; } $pfAttach = (string) old('attachment_type', $prefill->attachment_type ?? 'none'); // Blueprint buttons → the create form's button rows. Blueprint stores // {type: quick_reply|url|phone_number}; the form uses visit_website / // call_phone / quick_reply (copy_code unused by blueprints). $pfButtons = []; if ($prefill && is_array($prefill->buttons)) { $btnMap = ['url' => 'visit_website', 'phone_number' => 'call_phone', 'quick_reply' => 'quick_reply']; foreach ($prefill->buttons as $b) { $ft = $btnMap[$b['type'] ?? ''] ?? null; if (!$ft) continue; $pfButtons[] = [ 'type' => $ft, 'text' => (string) ($b['text'] ?? ''), 'value' => $ft === 'quick_reply' ? '' : (string) ($b['value'] ?? ''), ]; } } $pfMediaUrl = ($prefill && $prefill->attachment_file && str_contains((string) $prefill->attachment_type, 'image')) ? media_url($prefill->attachment_file) : ''; @endphp
{{ __('Templates / New') }}
{{ __('Create message') }} {{ __('template') }}
{{ __('Standard') }} {{ __('Draft / unsaved') }}
@if ($errors->any())
{{ __('Could not save the template:') }}
    @foreach ($errors->all() as $msg)
  • {{ $msg }}
  • @endforeach
@endif
@csrf {{-- Carries the pre-built blueprint id so store() can reuse its sample media when the operator didn't upload a replacement. --}} @if ($pfId) @endif @if ($isCatalog && ! $catalogHasWaba) {{-- Catalog is WABA-only. With no WhatsApp Business number connected the form can't resolve a sender, so warn up front (the server also rejects a non-WABA catalog submit as defence-in-depth). --}}
{{ __('Connect a WhatsApp Business (Meta) number first') }}
{{ __('Catalog templates are WhatsApp official only — they need a connected WABA number with a product catalog. Connect one, then create the catalog template.') }}
@endif
01 {{ __('Identity') }} {{ __('required') }}
{{ __('a-z, 0-9, _ only / max 60.') }}
{{-- Meta-approved category drives the review path. The separate `category` (industry tag, default utility) is sent as a hidden input so the controller's validate('in:travel,…,utility') still passes without the operator picking. --}}
{{ __('Determines Meta review path.') }}
{{ __('One locale per template.') }}
{{-- Send channel (multi-engine): which engine this template is for. Only WABA is submitted to Meta for approval; Unofficial API + Twilio are saved locally and ready to send. Hidden when only one engine is available (single-engine workspaces are unchanged). --}} @php // Instagram is chosen via the "New template" modal's Instagram // card (?channel=instagram) — it is NOT a WhatsApp send channel, // so drop it from the picker on the normal (WhatsApp) create page. // In IG mode we keep it (checked, section hidden) so submit still // sees channel=instagram. $pickerChannels = $isLocalDm ? ($channels ?? []) : array_values(array_filter($channels ?? [], fn ($c) => !in_array($c, ['instagram', 'facebook', 'telegram', 'line', 'wechat', 'viber', 'sms'], true))); // Catalog = WABA-only: strip every non-WABA sender so the // channel picker (and therefore the resolved device/number) // can only ever be a WhatsApp Business number. if ($isCatalog) { $pickerChannels = array_values(array_filter($pickerChannels, fn ($c) => $c === 'waba')); } @endphp @if (count($pickerChannels) > 1) {{-- When the channel was already chosen on the "New template" modal (Instagram card → ?channel=instagram), the picker is redundant. Keep the radios in the DOM (instagram stays checked, so the field-toggling JS + submit still see the channel) but hide the whole section. --}}
@foreach ($pickerChannels as $ck) @php $cmeta = [ 'baileys' => [__('Unofficial API'), __('Ready instantly — sent as text + buttons. No Meta approval.')], 'waba' => [__('Meta (WABA)'), __('Submitted to Meta for approval before it can send.')], 'twilio' => [__('Twilio'), __('Uses the Twilio Content SID below.')], 'instagram' => [__('Instagram'), __('A reusable Instagram DM — ready instantly, no Meta approval.')], 'facebook' => [__('Facebook'), __('A reusable Messenger DM — ready instantly, no Meta approval.')], 'telegram' => [__('Telegram'), __('A reusable Telegram bot message — ready instantly, no Meta approval.')], 'sms' => [__('SMS'), __('A plain-text SMS — ready instantly, no Meta approval.')], ][$ck] ?? [$ck, '']; @endphp @endforeach
{{ __('Pick which channel this template is for. Only WABA goes to Meta for approval.') }}
@else @endif {{-- WABA account picker (multi-WABA). When more than one WhatsApp Business account is connected, the operator chooses WHICH one this template is built on. The header/carousel media upload AND the Meta submit both use THIS account — using different ones makes Meta reject the carousel with "Bad parameter: Invalid parameter" (a media handle minted on WABA A is not valid on WABA B). Hidden with 0/1 WABA connected, where it uses the workspace's primary WABA as before. --}} @if (($wabaConfigs ?? collect())->count() > 1)
{{ __('You have more than one WABA connected — the template and its images are created on the account you pick here.') }}
@endif {{-- Twilio ContentSid: optional per-template pointer to a Twilio Content Builder template (HX...). When set, Twilio sends use the approved-template path (compliant for MARKETING / UTILITY / AUTHENTICATION categories) instead of plain Body text. Leave blank for Baileys-only / WABA-only workspaces. Only shown when the workspace's active engine is Twilio. --}} @if (in_array('twilio', $channels ?? [])) {{-- Only relevant for the Twilio channel — hidden by default, JS reveals it when the Twilio radio is picked. --}}
{{ __('Paste the HX… ContentSid from Twilio Content Builder. Required for compliant Twilio sends of MARKETING / UTILITY / AUTHENTICATION templates.') }}
{{-- For Twilio the content (header/body/buttons/carousel) is built in Twilio's Content Template Builder, not here — only the SID is sent. The builder sections below apply to Unofficial API + WABA. --}}
{{ __('Twilio templates are built in Twilio\'s Content Template Builder — only the Content SID above is sent. The Header / Body / Buttons / Carousel fields below apply to Unofficial API & WABA templates only.') }}
@endif
{{-- Content builder (Header / Body / Buttons / Carousel) — used for Unofficial API + WABA. Hidden by JS for the Twilio channel, whose content is defined in Twilio's Content Template Builder (sent by SID). --}}
02 {{ __('Header') }} {{ __('optional') }}
03 {{ __('Body') }} {{ __('required') }} / 0/1024
B I S ‹› {{-- Named-only authoring: this pill opens the `/` attribute picker on the body so the operator inserts a NAMED token ({{name}}) — the server normalizes it to positional {{1}} on save. (Replaces the old {{1}}–{{4}} numbered chips.) --}} {{ __('Variable') }} 0/1024
{{-- Empty by default — the example used to live inside the textarea, which meant submitting without any edits silently sent that placeholder copy. Moved to the `placeholder` attr so the body is real. --}}
{{-- Variable mapping — records WHICH attribute each positional placeholder ({{1}}, {{2}}, …) resolves to at send time. The hidden `variable_map_json` field carries the { slot: attribute_key } object the controller turns into `variable_map`. The attribute-picker (`/` in the body) writes here too via the `data-attr-map` wrapper. The visible panel below is populated by user-templates-create.js from the placeholders currently in the body. --}} {{-- Panel hidden: named tokens ({{company}}) already name their attribute, so a manual slot→attribute map is redundant (and its auto-guess could show a wrong attribute). The server derives variable_map from the token names on save. The hidden field above is kept for the legacy positional path. --}}
{{ __('Variable mapping') }} {{ __('which attribute fills each slot') }}
No variables yet. Add a placeholder like @{{ 1 }} above (or press / in the body) to map it to an attribute.
{{ __('Markdown:') }} *bold* _italic_ ~strike~ ```code```
04 {{ __('Attachment') }} {{ __('optional / image, video, or PDF') }}
{{-- File picker (image / video / document) --}}
@if ($pfMediaUrl) @else @endif
{{ $pfMediaUrl ? __('Sample image from the template') : __('Choose sample file') }}
{{ $pfMediaUrl ? __('Browse to replace it') : __('required by Meta for media templates') }}
{{ __('Browse') }}
{{-- Location inputs (shown when Attachment type = Location) --}}
05 {{ __('Footer') }} {{ __('optional / max 60') }}
{{ __('Plain text under the body. No variables.') }}
{{-- Hidden until the operator picks the Authentication category — OTP expiry is meaningless for Marketing / Utility. Shown by user-templates-create.js watching #tpl-category. --}}
06 {{ __('Buttons') }} {{ __('optional / up to 10') }}
{{ __('Call to action') }} {{ __('Quick reply') }} {{ __('Mix') }}
{{-- Static seed row — operators usually want at least one CTA. Names match the controller's processButtons() input arrays. When the builder is opened from a pre-built template we render its buttons here instead (same markup, so removeBtn/the type sync JS still works). --}} @forelse ($pfButtons as $pfBtn)
@empty
@endforelse
{{-- 07c Catalog (Meta official, WABA-only) — the "View catalog" button + which product image is the template thumbnail. Hidden by default; user-templates-create.js reveals it for ?type=catalog and hides the Header / Attachment / Buttons sections above (a CATALOG button can't share a template with other buttons or a media header). --}} {{-- The "Interactive (List menu / Poll)" section that lived here was removed — those controls aren't part of the WhatsApp Business template surface and were confusing operators. Buttons + Quick replies remain in section 06 above and cover every interactive option that's actually supported. --}}
{{-- /data-builder-sections --}}
{{-- Build-with-AI modal — vanilla Tailwind, same overlay/panel pattern as /templates#type-modal so the visual language stays consistent. Opened by #open-ai-modal in the sticky bar above. POST submission lives in user-templates-create.js. --}}