diff --git a/admin/v1/WpWebhook.php b/admin/v1/WpWebhook.php index eb367ed..7ae675a 100644 --- a/admin/v1/WpWebhook.php +++ b/admin/v1/WpWebhook.php @@ -209,9 +209,27 @@ class WpWebhook $company['_permission_type'] = self::getPermissionType($companies, $selectedId); self::$currentCompany = $company; $displayName = $company['display_name'] ?: $company['name']; - WhatsAppSender::sendText($from, "✅ Conectado con *{$displayName}*.\nEscribe tu consulta o *menú* para ver las opciones.", $phoneNumberId); + + // Mensaje 1: confirmación + WhatsAppSender::sendText($from, "✅ Conectado con *{$displayName}*.", $phoneNumberId); + + // Mensaje 2: greeting del bot — reset contexto y disparar con mensaje vacío + $botCtx = ConversationContext::getOrCreate((int)$selectedId, $from, 'normal'); + ConversationContext::reset((int)$botCtx['id']); + $synthCtx = [ + 'from' => $from, + 'name' => $name, + 'message_id' => 'mc_' . uniqid(), + 'type' => 'text', + 'timestamp' => time(), + 'phone_number_id' => $phoneNumberId, + 'display_phone' => '', + 'permission_type' => self::getPermissionType($companies, $selectedId), + ]; + BotRouter::route($company, $synthCtx, '', 'text'); + self::log('INFO', "Multi-empresa: {$from} seleccionó empresa #{$selectedId} ({$displayName})"); - return false; // el clic en botón no se procesa como comando del bot + return false; } // 2. Keyword de reinicio → borrar sesión y mostrar pre-menú