PHP code example of ohdearapp / laravel-ohdear-webhooks

1. Go to this page and download the library: Download ohdearapp/laravel-ohdear-webhooks 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/ */

    

ohdearapp / laravel-ohdear-webhooks example snippets


return [

    /*
     * Oh dear will sign webhooks using a secret. You can find the secret used at the webhook
     * configuration settings:  echo config('app.url'); 

Route::ohDearWebhooks('webhook-route-configured-at-the-ohdear-dashboard');

protected $except = [
    'webhook-route-configured-at-the-ohdear-dashboard',
];

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use OhDear\LaravelWebhooks\OhDearWebhookCall;

class HandleFailedUptimeCheck implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /** @var \OhDear\LaravelWebhooks\OhDearWebhookCall */
    public $webhookCall;

    public function __construct(OhDearWebhookCall $webhookCall)
    {
        $this->webhookCall = $webhookCall;
    }

    public function handle()
    {
        // do your work here

        // you can access the payload of the webhook call with $this->webhookCall->payload
    }
}

// config/ohdear-webhooks.php

'jobs' => [
    'uptimeCheckFailed' => \App\Jobs\ohdearWebhooks\HandleFailedUptimeCheck::class,
    'uptimeCheckRecovered' => \App\Jobs\ohdearWebhooks\HandleRecoveredUptimeCheck::class,
],

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'ohdear-webhooks::uptimeCheckFailed' => [
        App\Listeners\MailOperators::class,
    ],
];

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use OhDear\LaravelWebhooks\OhDearWebhookCall;

class MailOperators implements ShouldQueue
{
    public function handle(OhDearWebhookCall $webhookCall)
    {
        // do your work here

        // you can access the payload of the webhook call with `$webhookCall->payload`
    }
}

$ohDearWebhookCall->payload; // returns an array;

$ohDearWebhookCall->type(); // returns the type of the webhook (eg: 'uptimeCheckFailed');
$ohDearWebhookCall->site(); // returns an array with all the attribute of the site;
$ohDearWebhookCall->run(); // returns an array with all the attribute of the run;
$ohDearWebhookCall->dateTime(); // returns an string with a dateTime (Ymdhis) when Oh Dear generated this webhook call;