# Axynia Gateway Webchat

Gateway WebSocket persistente para transportar mensajes entre Deep Chat y la plataforma Axynia. La versión actual implementa únicamente la **Fase A de eco** definida en la especificación v0.02.

## Alcance actual

- Laravel 13 como contenedor, configuración y logging.
- Workerman 5.2 como servidor WebSocket y event loop.
- Escucha exclusiva en `127.0.0.1:3100` y path `/ws`.
- Validación sintáctica de un único `chatbot_id` UUID.
- Recepción del Request nativo de Deep Chat.
- Respuesta `{"role":"ai","text":"Recibido: ..."}`.
- Límites de frame, texto y profundidad JSON.
- Heartbeat WebSocket nativo mediante un timer global.
- Contexto efímero y limpieza de conexiones.
- Logs técnicos sin contenido conversacional.

Esta fase **no** valida `Origin`, crea sesiones, accede a bases de datos ni utiliza MQTT.

El `composer.lock` actual requiere PHP 8.4.1 o superior, con las extensiones `json`, `mbstring`, `pcntl` y `posix` en el servidor Linux.

## Configuración

```dotenv
GATEWAY_ID=gateway-01
GATEWAY_HOST=127.0.0.1
GATEWAY_PORT=3100
GATEWAY_PATH=/ws
GATEWAY_WORKERS=1
GATEWAY_LOG_PAYLOADS=false

HEARTBEAT_INTERVAL_MS=25000
MAX_FRAME_BYTES=65536
MAX_MESSAGE_CHARS=8000
MAX_JSON_DEPTH=32
```

## Ejecución y pruebas

```bash
php gateway.php start
php artisan test
```

El proceso permanece en foreground y escribe su actividad técnica en pantalla.
La ejecución como servicio, supervisión, rotación y recolección externa de logs
pertenecen al equipo de infraestructura y quedan fuera del alcance del proyecto.

Los eventos del Gateway se escriben simultáneamente en el log diario de Laravel y
en `stderr`, por lo que aparecen directamente al ejecutar `php gateway.php start`.

Por cada mensaje se registran `ws.message.received` y `ws.message.echoed`, con sus
identificadores, cantidad de bytes y duración. En desarrollo puede establecerse
`GATEWAY_LOG_PAYLOADS=true` para incluir completos el payload recibido y la
respuesta enviada como bloques JSON indentados y coloreados en consola. Las claves,
textos, números, booleanos y valores nulos utilizan colores diferentes. Las entradas
que no sean UTF-8 se representan en Base64.

Solicitud:

```json
{"messages":[{"role":"user","text":"Hola"}]}
```

Respuesta:

```json
{"role":"ai","text":"Recibido: Hola"}
```

## Framework base

<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>

<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>

## About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).

Laravel is accessible, powerful, and provides tools required for large, robust applications.

## Learning Laravel

Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.

In addition, [Laracasts](https://laracasts.com) contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

You can also watch bite-sized lessons with real-world projects on [Laravel Learn](https://laravel.com/learn), where you will be guided through building a Laravel application from scratch while learning PHP fundamentals.

## Agentic Development

Laravel's predictable structure and conventions make it ideal for AI coding agents like Claude Code, Cursor, and GitHub Copilot. Install [Laravel Boost](https://laravel.com/docs/ai) to supercharge your AI workflow:

```bash
composer require laravel/boost --dev

php artisan boost:install
```

Boost provides your agent 15+ tools and skills that help agents build Laravel applications while following best practices.

## Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).

## Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

## Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.

## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
