PHP code example of telehost / jarvis-client

1. Go to this page and download the library: Download telehost/jarvis-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

telehost / jarvis-client example snippets


return [
    'token' => env('JARVIS_TOKEN'),

    'metrics' => [
        'users_active' => fn () => \App\Models\User::where('suspended', false)->count(),
        'revenue_today' => fn () => \App\Models\Order::whereDate('created_at', today())->sum('total'),
        'queue' => fn () => [
            'pending' => \DB::table('jobs')->count(),
            'failed_1h' => \DB::table('failed_jobs')
                ->where('failed_at', '>=', now()->subHour())
                ->count(),
        ],
    ],

    'alerts' => [
        'disk_low' => fn () => disk_free_space('/') < 1_000_000_000
            ? ['severity' => 'critical', 'message' => 'Less than 1GB disk free']
            : null,
    ],
];

// config/jarvis.php
'auto_register_route' => false,

// routes/web.php
Route::get('/custom/health/path', \TeleHost\Jarvis\JarvisHealthController::class)
    ->middleware([\TeleHost\Jarvis\JarvisAuth::class]);

// config/jarvis.php
'middleware' => [
    'throttle:30,1', // 30 requests per minute from Jarvis
],

use TeleHost\Jarvis\JarvisManager;

app(JarvisManager::class)
    ->metric('stripe_balance', fn () => \Stripe\Balance::retrieve()->available[0]->amount / 100)
    ->alert('subscription_renewal', function () {
        $expiring = Subscription::whereDate('expires_at', today()->addDays(7))->count();
        return $expiring > 10
            ? ['severity' => 'warning', 'message' => "{$expiring} subs expire this week"]
            : null;
    });

  'whatsapp' => fn () => [
      'connected' => 15,
      'disconnected' => 2,
      'by_integration' => ['baileys' => 13, 'meta' => 4],
  ],
  

'metrics' => [
    // Business health
    'users_active' => fn () => User::where('last_login_at', '>=', now()->subWeek())->count(),
    'new_signups_24h' => fn () => User::where('created_at', '>=', now()->subDay())->count(),
    'revenue_today' => fn () => Transaction::whereDate('created_at', today())->sum('amount'),

    // Infrastructure
    'queue' => fn () => [
        'pending' => DB::table('jobs')->count(),
        'failed_1h' => DB::table('failed_jobs')->where('failed_at', '>=', now()->subHour())->count(),
    ],

    // External dependencies
    'db_latency_ms' => fn () => measureDbLatency(),
    'stripe_reachable' => fn () => pingStripe(),

    // Error rates
    'error_rate_pct' => fn () => calculateErrorRate(),
],
bash
php artisan vendor:publish --tag=jarvis-config