@php use App\Services\WorkspaceEngine; $devices = $devices ?? collect(); $senders = $senders ?? collect(); $templates = $templates ?? collect(); $flows = $flows ?? collect(); $wsId = (int) (auth()->user()->current_workspace_id ?? 0); // Edit mode: AutoReplyController::create() loads $row when the // URL has ?id=N. The blade still renders the same defaults the // "new" path uses; the JS reads window.WA_AUTOREPLY_ROW on init // and re-applies the row's values (name, keyword chips, device // selection, match method, similarity, reply type, cooldown, // timeout, contents). On submit the JS detects row.id and // PATCHes /auto-reply/{id} instead of POSTing /auto-reply. $row = $row ?? null; $isEdit = (bool) $row; $editPayload = $row ? [ 'id' => $row->id, 'name' => (string) ($row->keyword ?? ''), // legacy: keyword field doubles as rule label 'keywords' => array_values(array_filter(array_map('trim', explode(',', (string) $row->keyword)))), 'device_id' => $row->device_id, // Composite sender key the unified picker uses to pre-tick the // saved sender on edit: re-derive from the row's provider (the // CHOSEN engine, stamped at save) + device_id. Falls back to the // workspace default engine for legacy rows with no provider. 'sender_key' => (($row->provider ?: WorkspaceEngine::for($wsId)) . ':' . $row->device_id), 'matching_method' => $row->matching_method ?? 'fuzzy', // "Any message" is stored as this flag, NOT a matching method — the JS // must restore the "Any" segment from it, otherwise edit falls back to // whatever filler matching_method was stored (exact) and the rule looks // like a keyword rule that demands keywords. 'is_catch_all' => (bool) $row->is_catch_all, 'fuzzy_similarity' => $row->fuzzy_similarity ?? 80, 'cooldown' => $row->cooldown, 'timeout' => $row->timeout, 'reply_type' => $row->reply_type ?? 'custom', 'flow_id' => $row->flow_id, 'target_contact_id' => $row->target_contact_id, 'target_catalog_id' => $row->target_catalog_id, 'message_type' => $row->message_type ?? 'text', 'contents' => $row->relationLoaded('contents') ? $row->contents ->where('variant_role', '!=', 'outside_hours') ->map( fn($c) => [ 'content_type' => $c->content_type, 'content' => (string) $c->content, 'template_id' => $c->template_id, ], ) ->values() : [], // Auto Responder / Welcome Message hydration. 'trigger_type' => $row->trigger_type ?? 'keyword', // Instagram-native trigger (null on WhatsApp rows). 'ig_trigger' => $row->ig_trigger, 'stop_on_agent_reply' => (bool) $row->stop_on_agent_reply, 'welcome_resend' => (bool) ($row->welcome_resend ?? false), // Seconds → value+unit for redisplay. intdiv() against the SAVED unit // truncated anything smaller than one unit to 0 — a 60s window reopened // as "0 hours", and saving the untouched form turned it into 24h. Pick // the largest unit that divides the stored seconds EXACTLY, so every // value round-trips unchanged. An explicit 0 is preserved as 0, not blank. 'resend_unit' => \App\Services\Inbox\AutoResponderEvaluator::displayUnit($row->cooldown, $row->resend_unit), 'resend_value' => \App\Services\Inbox\AutoResponderEvaluator::displayValue($row->cooldown, $row->resend_unit), 'resume_unit' => \App\Services\Inbox\AutoResponderEvaluator::displayUnit($row->resume_after, $row->resume_unit), 'resume_value' => \App\Services\Inbox\AutoResponderEvaluator::displayValue($row->resume_after, $row->resume_unit), 'working_hours' => is_array($row->working_hours) ? $row->working_hours : null, 'excluded_numbers' => is_array($row->excluded_numbers) ? $row->excluded_numbers : [], 'outside_message' => $row->relationLoaded('contents') ? (string) optional($row->contents->firstWhere('variant_role', 'outside_hours'))->content : '', ] : null; // Pre-tick the saved sender on edit (server-side, in addition to the // JS hydration). Wrapped in old() so a failed re-render keeps the // operator's last selection. $senderSelected = old('sender', $isEdit ? (!empty($selectedSenderKeys) ? $selectedSenderKeys : [$editPayload['sender_key']]) : []); @endphp
Auto Reply / {{ $isEdit ? 'Edit · #' . $row->id : 'New' }}
{{ $isEdit ? 'Edit auto' : 'Create new auto' }} {{ __('reply') }}
{{ __('Draft / unsaved') }}
1 {{ __('Trigger') }}
2 {{ __('Schedule') }}
3 {{ __('Reply type') }}
4 {{ __('Compose') }}
5 {{ __('Review') }}
01 {{ __('Trigger') }} {{ __('required') }}
{{-- Trigger type — Keyword (classic) vs Welcome Message (auto responder that greets on a NEW conversation, no keyword). --}}
{{-- WhatsApp trigger tiles — hidden automatically when the chosen sender is an Instagram account (JS swaps in #seg-igt). --}}
{{-- Instagram trigger tiles — shown only when the selected sender is an IG account. Each maps to a real Meta event (see KeywordReplyDispatcher / InstagramWebhookController). --}}
{{-- Priority — lower number wins when several auto-responder rules could reply to the same incoming message. --}}
{{ __('Lower number = higher priority when several rules could reply to the same message.') }}
{{ __("Internal label only — customers don't see this.") }}
{{-- Multi-engine: every connected sender across all enabled engines (Unofficial API + WABA + Twilio). Each ticked box becomes its OWN KeywordReply row on submit — the server fans out via sender[] composite keys (engine:id) and stamps each row's provider = the chosen engine (see AutoReplyController::store). Single-engine workspaces see the same flat list the legacy device picker showed. --}} @if ($senders->count() > 1)
{{ __('Each ticked sender gets its own row — toggle / delete each independently from the list later.') }}
@endif
hi {{ __('hello') }} {{ __('hey') }}
{{ __('Press') }} {{ __('Enter') }} or , to add. Group similar phrases in one rule.
{{-- The DEFAULT ROUTE. Not a matching method like the others — it is a separate, lower tier that runs only when no keyword rule matched, so it can never outrank one. Sits here because this is where an operator looks when asking "when does this fire?". --}}
{{ __('Fuzzy catches typos like "pricng" → "pricing".') }}
{{ __('loose') }}{{ __('strict') }}
{{-- ── WELCOME MESSAGE panel — shown only when trigger type = welcome ── --}}
{{ __('Step') }} 1 of 5
{{-- Edit-mode payload. Empty/null when creating a fresh rule. The page-module JS reads this to pre-fill the multi-step form and switch the submit handler from POST to PATCH. --}} {{-- Step-4 flow picker: search-by-name filter + visual selection state. The radio inside each card carries the flow_id the form submits; this script only handles UX (hide/show, highlight, edit-mode pre-select). --}} {{-- This page only: restore the app's fixed-height shell so a TALL step (Step 1 carries the full message-rules + working-hours fields) scrolls INSIDE the content area instead of growing the whole page and leaving a big blank area below. Scoped by data-page so no other screen is touched. The content area already has overflow-y-auto, so content stays reachable. --}} {{-- Build-free wiring for the "Re-greet returning customers" toggle. The auto-reply wizard builds a manual FormData and POSTs it via fetch to /auto-reply (create) or /auto-reply/{id} (edit). On installs that cannot rebuild the JS bundle, we inject the toggle value here instead: intercept that one fetch and append `welcome_resend` from the checkbox. Guarded with has() so it never double-adds when a full build already includes it. --}}