feat: welcome message, fix per_type save, add missing ciclos flows
- Show welcome_msg (button with "Ver menú") for all new sessions before category menu
- Fix saveConfig() AJAX to include per_type_menu DOM values so they survive individual saves
- Add welcome_menu field to General tab in admin (render + save)
- Add 'atras' command alias (→ show_main_menu)
- Add ciclos_plagas, ciclos_palm, ciclos_tratamientos flows to DB config
- Fix per_type in DB from [] to {} (proper JSON object)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e9bbf8efce
commit
b288b07ff5
@@ -2874,6 +2874,12 @@ HTML;
|
||||
$aiProviderVal = self::h($config['ai_provider'] ?? '');
|
||||
$approvalWebhookVal = self::h($config['approval_webhook'] ?? '');
|
||||
$ignoreVal = self::h(implode("\n", $config['ignore_prefixes'] ?? []));
|
||||
$welcomeMenuVal = self::h($config['welcome_menu'] ?? '');
|
||||
$welcomeMenuOpts = '';
|
||||
foreach (array_keys($menus) as $mk) {
|
||||
$s = ($config['welcome_menu'] ?? '') === $mk ? ' selected' : '';
|
||||
$welcomeMenuOpts .= '<option value="' . self::h($mk) . '"' . $s . '>' . self::h($mk) . '</option>';
|
||||
}
|
||||
$commands = $config['commands'] ?? [];
|
||||
$menus = $config['menus'] ?? [];
|
||||
$flows = $config['flows'] ?? [];
|
||||
@@ -3421,10 +3427,18 @@ HTML;
|
||||
<div class="card-h">⚙️ General</div>
|
||||
<div style="display:grid;grid-template-columns:1fr 300px;gap:24px;align-items:start">
|
||||
<div>
|
||||
<div class="form-group">
|
||||
<label>Menú de bienvenida (welcome_menu)</label>
|
||||
<select name="welcome_menu" style="width:100%;padding:9px 12px;border:1px solid #e2e5ea;border-radius:8px;font-size:13px">
|
||||
<option value="">— Ninguno —</option>
|
||||
{$welcomeMenuOpts}
|
||||
</select>
|
||||
<div style="font-size:11px;color:#7a8291;margin-top:3px">Menú que se muestra a TODOS los usuarios nuevos antes del menú principal</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Mensaje de bienvenida (greeting)</label>
|
||||
<textarea name="greeting" id="prevGreeting" rows="2" placeholder="¡Bienvenido! Escribe 'menu' para ver opciones..." oninput="updatePreview()" style="width:100%;padding:10px 14px;border:1px solid #e2e5ea;border-radius:8px;font-size:13px;outline:none;font-family:inherit;background:#fafbfc;resize:none">{$greetingVal}</textarea>
|
||||
<div style="font-size:11px;color:#7a8291;margin-top:3px">Primer mensaje que recibe un usuario nuevo</div>
|
||||
<div style="font-size:11px;color:#7a8291;margin-top:3px">Primer mensaje de texto que recibe un usuario nuevo (alternativo al welcome_menu)</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Mensaje por defecto (fallback)</label>
|
||||
@@ -4781,6 +4795,12 @@ function saveConfig() {
|
||||
fd.append('approval_webhook', fullConfig.approval_webhook || '');
|
||||
fd.append('ignore_prefixes', (fullConfig.ignore_prefixes || []).join('\\n'));
|
||||
|
||||
// Per-category menus — read from DOM so they're preserved on every AJAX save
|
||||
[1, 2, 3].forEach(cat => {
|
||||
const sel = document.querySelector('select[name="per_type_menu[' + cat + ']"]');
|
||||
if (sel) fd.append('per_type_menu[' + cat + ']', sel.value);
|
||||
});
|
||||
|
||||
fetch('/admin/bot-config/save', {
|
||||
method: 'POST',
|
||||
body: fd
|
||||
|
||||
@@ -562,6 +562,8 @@ $routes = [
|
||||
}
|
||||
$approvalWebhook = trim($_POST['approval_webhook'] ?? '');
|
||||
if ($approvalWebhook !== '') $config['approval_webhook'] = $approvalWebhook;
|
||||
$welcomeMenu = trim($_POST['welcome_menu'] ?? '');
|
||||
if ($welcomeMenu !== '') $config['welcome_menu'] = $welcomeMenu;
|
||||
|
||||
CompanyRepository::save(['id' => $companyId, 'config_json' => json_encode($config, JSON_UNESCAPED_UNICODE)]);
|
||||
header('Location: /admin/bot-config?id=' . $companyId . '&msg=saved');
|
||||
|
||||
@@ -76,7 +76,14 @@ class NormalBot
|
||||
return self::handleFlow($flows[$currentNode], $context, $company, $ctxId, $menus);
|
||||
}
|
||||
|
||||
// 4. Per-type greeting menu — only for brand-new sessions (currentNode === null)
|
||||
// 4. Welcome message — shown once for brand-new sessions before the category menu
|
||||
$welcomeMenuKey = $config['welcome_menu'] ?? null;
|
||||
if ($welcomeMenuKey && $currentNode === null && isset($menus[$welcomeMenuKey])) {
|
||||
ConversationContext::updateNode($ctxId, '__greeted');
|
||||
return self::buildMenuResponse($menus[$welcomeMenuKey], $context['from'], $company);
|
||||
}
|
||||
|
||||
// 4b. Per-type greeting menu — only for brand-new sessions (currentNode === null)
|
||||
$greetingMenuKey = $perType['greeting_menu'] ?? null;
|
||||
if ($greetingMenuKey !== null && $currentNode === null && isset($menus[$greetingMenuKey])) {
|
||||
ConversationContext::updateNode($ctxId, '__greeted'); // sentinel: evita re-envío del menú
|
||||
|
||||
Reference in New Issue
Block a user