dantofema/mogotes-laravel

This is my package mogotes-laravel

Fund package maintenance!
dantofema

Installs: 16

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/dantofema/mogotes-laravel

v1.0.0 2026-01-13 18:11 UTC

This package is auto-updated.

Last update: 2026-01-13 20:00:49 UTC


README

Latest Version on Packagist Total Downloads License

Cliente Laravel para interactuar con los servicios de Mogotes - Feature Flags, Notificaciones y Logs.

Instalaci贸n

composer require dantofema/mogotes-laravel

Publica el archivo de configuraci贸n:

php artisan vendor:publish --tag="mogotes-laravel-config"

Configura las variables de entorno en tu .env:

MOGOTES_API_KEY=tu_api_key_aqui
MOGOTES_SERVER_URL=https://api.mogotes.com
MOGOTES_WEBHOOK_SECRET=tu_webhook_secret

Uso

馃摟 Notificaciones

Env铆a notificaciones por email o WhatsApp usando plantillas configuradas en Mogotes.

use Dantofema\MogotesLaravel\Facades\Mogotes;

// Email
Mogotes::email(
    template: 'welcome-email',
    to: 'user@example.com',
    data: ['name' => 'Juan', 'code' => '12345']
);

// WhatsApp
Mogotes::whatsapp(
    template: 'order-confirmation',
    to: '+5491112345678',
    data: ['order_id' => '12345', 'total' => '$100']
);

// Notificaci贸n gen茅rica (cualquier canal)
Mogotes::notifications()->send(
    channel: 'email',
    template: 'custom-template',
    to: 'recipient@example.com',
    data: ['key' => 'value'],
    idempotencyKey: 'unique-key-123' // Opcional
);

馃搳 Logs

Env铆a logs estructurados a Mogotes para centralizar el monitoreo de tu aplicaci贸n.

use Dantofema\MogotesLaravel\Facades\Mogotes;

// Log de informaci贸n
Mogotes::log()->info('Usuario creado', [
    'user_id' => 123,
    'email' => 'user@example.com'
]);

// Log de error
Mogotes::log()->error('Fall贸 el pago', [
    'payment_id' => 456,
    'error' => 'Tarjeta rechazada'
]);

// Otros niveles disponibles
Mogotes::log()->warning('Advertencia', ['context' => 'value']);
Mogotes::log()->debug('Debug info', ['data' => [...]]);

// Listar logs con filtros
$logs = Mogotes::log()->list([
    'level' => 'error',
    'from_date' => '2024-01-01',
    'to_date' => '2024-01-31',
    'per_page' => 50
]);

馃毄 Feature Flags

Controla funcionalidades de tu aplicaci贸n de forma din谩mica sin redesplegar c贸digo.

use Dantofema\MogotesLaravel\Facades\Mogotes;

// Verificar si un flag est谩 activo
if (Mogotes::feature()->IsActive('nueva-funcionalidad')) {
    // C贸digo para la nueva funcionalidad
}

// Con scope (por usuario, tenant, etc.)
if (Mogotes::feature()->IsActive('beta-feature', scopeId: 'user-123')) {
    // Funcionalidad beta para usuario espec铆fico
}

Integraci贸n con Laravel Pennant:

El paquete tambi茅n registra autom谩ticamente un driver de Pennant para usar Feature Flags nativamente:

use Laravel\Pennant\Feature;

// Verificar flag
if (Feature::active('nueva-funcionalidad')) {
    // ...
}

// Con scope
Feature::for($user)->active('beta-feature');

馃攼 Webhooks

Recibe eventos de Mogotes en tu aplicaci贸n de forma segura.

Configuraci贸n autom谩tica

El paquete registra autom谩ticamente la ruta /mogotes/webhook (configurable en .env):

MOGOTES_WEBHOOK_PATH=/mogotes/webhook
MOGOTES_WEBHOOK_REGISTER_ROUTE=true

Validaci贸n de firma

use Dantofema\MogotesLaravel\Services\WebhookSignatureValidator;

$validator = new WebhookSignatureValidator(
    secret: config('mogotes-laravel.webhooks.secret')
);

try {
    $validator->validate(
        rawBody: $request->getContent(),
        signature: $request->header('Mogotes-Signature'),
        timestamp: (int) $request->header('Mogotes-Timestamp')
    );
    
    // Webhook v谩lido, procesar evento
    $event = $request->json();
    
} catch (InvalidWebhookSignatureException $e) {
    // Firma inv谩lida o timestamp expirado
    return response()->json(['error' => 'Invalid signature'], 401);
}

Escuchar eventos

Crea listeners para los eventos de Mogotes:

use Dantofema\MogotesLaravel\Events\WebhookReceived;

Event::listen(WebhookReceived::class, function (WebhookReceived $event) {
    $payload = $event->payload;
    
    // Procesar evento seg煤n tipo
    match ($payload['event_type'] ?? null) {
        'notification.sent' => // Notificaci贸n enviada
        'notification.failed' => // Notificaci贸n fallida
        default => // Otro evento
    };
});

Configuraci贸n avanzada

// config/mogotes-laravel.php

return [
    'base_url' => env('MOGOTES_SERVER_URL', 'https://api.mogotes.com'),
    'api_key' => env('MOGOTES_API_KEY'),
    'timeout_seconds' => env('MOGOTES_TIMEOUT_SECONDS', 5),
    
    'feature_flags' => [
        'ttl_seconds' => env('MOGOTES_FEATURE_FLAGS_TTL_SECONDS', 300),
        'cache_enabled' => env('MOGOTES_FEATURE_FLAGS_CACHE_ENABLED', true),
    ],
    
    'webhooks' => [
        'register_route' => env('MOGOTES_WEBHOOK_REGISTER_ROUTE', true),
        'path' => env('MOGOTES_WEBHOOK_PATH', '/mogotes/webhook'),
        'secret' => env('MOGOTES_WEBHOOK_SECRET'),
    ],
];

Excepciones

El paquete lanza excepciones espec铆ficas para facilitar el manejo de errores:

  • MogotesUnauthorizedException - API key inv谩lida o expirada
  • MogotesApiException - Error gen茅rico de la API
  • MogotesConnectionException - No se pudo conectar al servidor
  • MogotesRateLimitException - L铆mite de requests excedido
  • MogotesIdempotencyConflictException - Conflicto de idempotencia
  • InvalidWebhookSignatureException - Firma de webhook inv谩lida

Testing

composer test

License

The MIT License (MIT). Ver License File para m谩s informaci贸n.