'¡Bienvenido a Palmas360! Escribe *menu* para ver las opciones disponibles.', 'fallback' => 'No entendí. Escribe *menu* para ver las opciones disponibles.', 'commands' => [ 'menu' => 'show_main_menu', 'informes' => 'descargar_informes', 'info' => 'enviar_informacion', 'inicio' => 'show_main_menu', 'volver' => 'show_main_menu', ], // ── Menus globales ────────────────────────────────────────────────────── 'menus' => [ // Menú modo trabajo (para per_type=3 tras seleccionar finca) 'menu_modo_trabajo' => [ 'type' => 'list', 'header' => '🌴 Palmas360', 'body' => '¿Qué deseas hacer?', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Opciones', 'rows' => [ ['id' => 'descargar_informes', 'title' => '📥 Descargar informes', 'description' => 'Ciclos, Producción, Ausentismos'], ['id' => 'enviar_informacion', 'title' => '📤 Enviar información', 'description' => 'Subir ciclos y datos'], ], ], ], ], // Menú cat2 (descargar informes) — accesible globalmente 'show_menu_cat2' => [ 'type' => 'list', 'header' => '📋 Informes', 'body' => '¿Qué informe deseas?', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Informes', 'rows' => [ ['id' => 'submenu_produccion', 'title' => '🌿 Producción', 'description' => 'Informes de producción'], ['id' => 'submenu_ciclos', 'title' => '🔄 Ciclos', 'description' => 'Ciclos de campo'], ['id' => 'submenu_ausentismos', 'title' => '👥 Ausentismos', 'description' => 'Faltas y novedades'], ], ], ], ], // Submenú producción 'submenu_produccion' => [ 'type' => 'list', 'header' => '🌿 Producción', 'body' => 'Selecciona el informe:', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Producción', 'rows' => [ ['id' => 'produccion_total', 'title' => '📊 Total del mes', 'description' => 'Resumen y PDF del mes'], ['id' => 'produccion_lotes', 'title' => '📋 Por lotes (Excel)', 'description' => 'Detalle por lote'], ], ], ], ], // Submenú ciclos 'submenu_ciclos' => [ 'type' => 'list', 'header' => '🔄 Ciclos', 'body' => 'Selecciona el ciclo:', 'footer' => 'Palmas360', 'button' => 'Ver ciclos', 'sections' => [ [ 'title' => 'Ciclos', 'rows' => [ ['id' => 'ciclo_cosecha', 'title' => '🌾 Cosecha', 'description' => 'Ciclos de cosecha'], ['id' => 'ciclo_polinizacion', 'title' => '🌸 Polinización', 'description' => 'Ciclos de polinización'], ['id' => 'ciclo_censo', 'title' => '📝 Censo', 'description' => 'Ciclos de censo'], ['id' => 'ciclo_plagas', 'title' => '🐛 Plagas', 'description' => 'Ciclos de plagas'], ], ], [ 'title' => 'Más ciclos', 'rows' => [ ['id' => 'ciclo_palm', 'title' => '🌴 Palm', 'description' => 'Ciclos palm'], ['id' => 'ciclo_tratamiento', 'title' => '💊 Tratamiento', 'description' => 'Ciclos de tratamiento'], ['id' => 'ciclo_mantenimiento', 'title' => '🔧 Mantenimiento', 'description' => 'Ciclos de mantenimiento'], ], ], ], ], // Submenú ausentismos 'submenu_ausentismos' => [ 'type' => 'list', 'header' => '👥 Ausentismos', 'body' => 'Selecciona el período:', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Período', 'rows' => [ ['id' => 'ausentismos_hoy', 'title' => '📅 Hoy', 'description' => '¿Quién faltó hoy?'], ['id' => 'ausentismos_semana', 'title' => '📆 Esta semana', 'description' => '¿Quién faltó esta semana?'], ['id' => 'ausentismos_mes', 'title' => '📋 Mes (PDF)', 'description' => 'Reporte mensual PDF'], ], ], ], ], // Submenú subir ciclos (para per_type=3) 'submenu_subir_ciclos' => [ 'type' => 'list', 'header' => '📤 Enviar información', 'body' => 'Selecciona qué deseas enviar:', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Opciones', 'rows' => [ ['id' => 'subir_ciclo_cosecha', 'title' => '🌾 Ciclo cosecha', 'description' => 'Subir ciclo de cosecha'], ], ], ], ], ], // ── Flows globales ────────────────────────────────────────────────────── 'flows' => [ // Selección de finca (dynamic_list — guarda finca_id en meta) 'ask_finca' => [ 'type' => 'dynamic_list', 'source_endpoint_key' => 'fincas_dn', 'value_field' => 'id', 'label_field' => 'label', 'header' => '🌴 Palmas360', 'body' => '¿En qué finca trabajas?', 'section_title' => 'Fincas disponibles', 'meta_group' => 'finca', 'meta_key' => 'finca_id', 'next_node' => 'show_main_menu', ], // Producción (texto del mes + PDF encadenado) 'produccion_total' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'produccion_total_bot_dn', 'date_mode' => 'current_month', 'next_endpoint_key' => 'produccion_total_pdf_bot_dn', 'next_caption' => '📊 Producción del mes (PDF)', 'next_filename' => 'produccion_mes.pdf', ]], 'produccion_lotes' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'produccion_lotes_bot_dn', 'filename' => 'produccion_lotes.xlsx', 'caption' => 'Producción por lotes del año', ]], // Ausentismos 'ausentismos_hoy' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'ausentismos_bot_texto_dn', 'date_mode' => 'today', ]], 'ausentismos_semana' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'ausentismos_bot_texto_dn', 'date_mode' => 'last_7', ]], 'ausentismos_mes' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'ausentismos_bot_pdf_dn', 'date_mode' => 'current_month', 'filename' => 'ausentismos_mes.pdf', 'caption' => 'Ausentismos del mes', ]], // Menus de sección 'submenu_produccion' => ['type' => 'menu', 'menu' => 'submenu_produccion'], 'submenu_ciclos' => ['type' => 'menu', 'menu' => 'submenu_ciclos'], 'submenu_ausentismos' => ['type' => 'menu', 'menu' => 'submenu_ausentismos'], // Ciclos (texto top + PDF histórico 30 días encadenado) 'ciclo_cosecha' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'cosecha_top_texto_bot_dn', 'date_mode' => 'last_30', 'next_endpoint_key' => 'cosecha_historico_bot_dn', 'next_caption' => '📋 Histórico cosecha 30 días', 'next_filename' => 'cosecha_historico.pdf', ]], 'ciclo_polinizacion' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'polinizacion_top_texto_bot_dn', 'date_mode' => 'last_30', 'next_endpoint_key' => 'polinizacion_historico_bot_dn', 'next_caption' => '📋 Histórico polinización 30 días', 'next_filename' => 'polinizacion_historico.pdf', ]], 'ciclo_censo' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'censo_top_texto_bot_dn', 'date_mode' => 'last_30', 'next_endpoint_key' => 'censo_historico_bot_dn', 'next_caption' => '📋 Histórico censo 30 días', 'next_filename' => 'censo_historico.pdf', ]], 'ciclo_plagas' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'plagas_top_texto_bot_dn', 'date_mode' => 'last_30', 'next_endpoint_key' => 'plagas_historico_bot_dn', 'next_caption' => '📋 Histórico plagas 30 días', 'next_filename' => 'plagas_historico.pdf', ]], 'ciclo_palm' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'palm_top_texto_bot_dn', 'date_mode' => 'last_30', 'next_endpoint_key' => 'palm_historico_bot_dn', 'next_caption' => '📋 Histórico palm 30 días', 'next_filename' => 'palm_historico.pdf', ]], 'ciclo_tratamiento' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'tratamiento_top_texto_bot_dn', 'date_mode' => 'last_30', 'next_endpoint_key' => 'tratamiento_historico_bot_dn', 'next_caption' => '📋 Histórico tratamiento 30 días', 'next_filename' => 'tratamiento_historico.pdf', ]], 'ciclo_mantenimiento' => ['type' => 'function', 'function' => 'api_report', 'params' => [ 'endpoint_key' => 'mantenimiento_top_texto_bot_dn', 'date_mode' => 'last_30', ]], // Upload 'enviar_informacion' => ['type' => 'menu', 'menu' => 'submenu_subir_ciclos'], 'subir_ciclo_cosecha' => ['type' => 'function', 'function' => 'upload_ciclo', 'params' => ['ciclo' => 'cosecha']], // Alias globales 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], 'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], ], // ── Per-type config ───────────────────────────────────────────────────── 'per_type' => [ // Cat 1: solo reporta (envía info, no descarga) '1' => [ 'greeting_flow' => 'show_menu_cat1', 'fallback_flow' => 'show_menu_cat1', 'greeting' => null, 'fallback' => null, 'commands' => ['menu' => 'show_menu_cat1'], 'menus' => [ 'show_menu_cat1' => [ 'type' => 'list', 'header' => '🌴 Palmas360', 'body' => '¿Qué deseas hacer?', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Opciones', 'rows' => [ ['id' => 'subir_ciclo_cosecha', 'title' => '🌾 Subir cosecha', 'description' => 'Enviar ciclo de cosecha'], ], ], ], ], ], 'flows' => [ 'show_menu_cat1' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], 'subir_ciclo_cosecha' => ['type' => 'function', 'function' => 'upload_ciclo', 'params' => ['ciclo' => 'cosecha']], ], ], // Cat 2: solo descarga '2' => [ 'greeting_flow' => 'ask_finca', 'fallback_flow' => 'show_menu_cat2', 'greeting' => null, 'fallback' => null, 'commands' => ['menu' => 'show_menu_cat2'], 'menus' => [ 'show_menu_cat2' => [ 'type' => 'list', 'header' => '📋 Informes', 'body' => '¿Qué informe deseas?', 'footer' => 'Palmas360', 'button' => 'Ver opciones', 'sections' => [ [ 'title' => 'Informes', 'rows' => [ ['id' => 'submenu_produccion', 'title' => '🌿 Producción', 'description' => 'Informes de producción'], ['id' => 'submenu_ciclos', 'title' => '🔄 Ciclos', 'description' => 'Ciclos de campo'], ['id' => 'submenu_ausentismos', 'title' => '👥 Ausentismos', 'description' => 'Faltas y novedades'], ], ], ], ], ], 'flows' => [ 'show_menu_cat2' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], 'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], ], ], // Cat 3: descarga + envío '3' => [ 'greeting_flow' => 'ask_finca', 'fallback_flow' => 'show_main_menu', 'greeting' => null, 'fallback' => null, 'commands' => ['menu' => 'show_main_menu'], 'menus' => [], 'flows' => [ 'show_main_menu' => ['type' => 'menu', 'menu' => 'menu_modo_trabajo'], 'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], 'enviar_informacion' => ['type' => 'menu', 'menu' => 'submenu_subir_ciclos'], ], ], ], ]; // ─── Endpoints ───────────────────────────────────────────────────────────────── $BASE = 'https://app.palmas360.com/rosablanca/php/controller/controller_api_externa.php'; $endpoints = [ ['key' => 'produccion_total_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_total_bot&finca_id={finca_id}'], ['key' => 'produccion_total_pdf_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_total_pdf_bot&finca_id={finca_id}'], ['key' => 'produccion_lotes_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_lotes_bot&finca_id={finca_id}'], ['key' => 'ausentismos_bot_texto_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ausentismos_bot_texto'], ['key' => 'ausentismos_bot_pdf_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ausentismos_bot_pdf'], ['key' => 'cosecha_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=cosecha_top_texto_bot&finca_id={finca_id}'], ['key' => 'polinizacion_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=polinizacion_top_texto_bot&finca_id={finca_id}'], ['key' => 'censo_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=censo_top_texto_bot&finca_id={finca_id}'], ['key' => 'plagas_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=plagas_top_texto_bot&finca_id={finca_id}'], ['key' => 'palm_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=palm_top_texto_bot&finca_id={finca_id}'], ['key' => 'tratamiento_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=tratamiento_top_texto_bot&finca_id={finca_id}'], ['key' => 'mantenimiento_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=mantenimiento_top_texto_bot&grupo=0&finca_id={finca_id}'], ['key' => 'cosecha_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=cosecha_historico_bot&finca_id={finca_id}'], ['key' => 'polinizacion_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=polinizacion_historico_bot&finca_id={finca_id}'], ['key' => 'censo_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=censo_historico_bot&finca_id={finca_id}'], ['key' => 'plagas_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=plagas_historico_bot&finca_id={finca_id}'], ['key' => 'palm_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=palm_historico_bot&finca_id={finca_id}'], ['key' => 'tratamiento_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=tratamiento_historico_bot&finca_id={finca_id}'], ['key' => 'fincas_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=fincas'], ['key' => 'numeros_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=whatsapp_numeros&estado=1'], ]; // ─── Companies ───────────────────────────────────────────────────────────────── $companies = [ [ 'id' => 2, 'name' => 'rosablanca', 'display_name' => 'Rosa Blanca', 'phone_number_id' => '1168511569675820', 'display_phone' => '', 'api_base_url' => 'https://graph.facebook.com/v22.0', 'api_key' => 'EAAqbNQQekwUBRm8ZAAfCvXZAsxcM1BTkiHjVJYeOfXYCg5t4qYtBL7ap2IdHGa1iXclZBO47gZBshYZBAlQRuUvgSib2Owh7gPnAWfNlHXZAT61ccElXoihuXuEuy0qLiB95tDhLMWPqoKYuDwAHCU78RQxoi1nzz1OsOY40EK7U2tKZBVuZABQZCJctZBrLK7rRiC7AZDZD', 'bot_type' => 'normal', 'requires_approval' => 0, 'is_active' => 1, ], [ 'id' => 3, 'name' => 'palmas360_test', 'display_name' => 'Palmas360 Test', 'phone_number_id' => '1168511569675820', 'display_phone' => '', 'api_base_url' => 'https://graph.facebook.com/v22.0', 'api_key' => 'EAAqbNQQekwUBRm8ZAAfCvXZAsxcM1BTkiHjVJYeOfXYCg5t4qYtBL7ap2IdHGa1iXclZBO47gZBshYZBAlQRuUvgSib2Owh7gPnAWfNlHXZAT61ccElXoihuXuEuy0qLiB95tDhLMWPqoKYuDwAHCU78RQxoi1nzz1OsOY40EK7U2tKZBVuZABQZCJctZBrLK7rRiC7AZDZD', 'bot_type' => 'normal', 'requires_approval' => 0, 'is_active' => 1, ], ]; $configJsonStr = json_encode($configJson, JSON_UNESCAPED_UNICODE); // ─── Insert / update companies ──────────────────────────────────────────────── $stmtCo = $db->prepare(" INSERT INTO companies (id, name, display_name, phone_number_id, display_phone, api_base_url, api_key, bot_type, requires_approval, is_active, config_json) VALUES (:id, :name, :display_name, :phone_number_id, :display_phone, :api_base_url, :api_key, :bot_type, :requires_approval, :is_active, :config_json) ON DUPLICATE KEY UPDATE display_name = VALUES(display_name), phone_number_id = VALUES(phone_number_id), api_base_url = VALUES(api_base_url), api_key = VALUES(api_key), bot_type = VALUES(bot_type), is_active = VALUES(is_active), config_json = VALUES(config_json) "); foreach ($companies as $co) { $stmtCo->execute([ ':id' => $co['id'], ':name' => $co['name'], ':display_name' => $co['display_name'], ':phone_number_id' => $co['phone_number_id'], ':display_phone' => $co['display_phone'], ':api_base_url' => $co['api_base_url'], ':api_key' => $co['api_key'], ':bot_type' => $co['bot_type'], ':requires_approval'=> $co['requires_approval'], ':is_active' => $co['is_active'], ':config_json' => $configJsonStr, ]); echo "✔ Company {$co['id']} ({$co['display_name']}) OK\n"; } // ─── Insert / update endpoints ──────────────────────────────────────────────── $stmtEp = $db->prepare(" INSERT INTO company_endpoints (company_id, endpoint_key, direction, url) VALUES (:company_id, :endpoint_key, :direction, :url) ON DUPLICATE KEY UPDATE url = VALUES(url), direction = VALUES(direction) "); foreach ($companies as $co) { foreach ($endpoints as $ep) { $stmtEp->execute([ ':company_id' => $co['id'], ':endpoint_key' => $ep['key'], ':direction' => $ep['dir'], ':url' => $ep['url'], ]); } echo "✔ " . count($endpoints) . " endpoints OK para company {$co['id']}\n"; } echo "\n✅ Seed completo.\n";