PHP code example of ankurk91 / laravel-ses-webhooks

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

    

ankurk91 / laravel-ses-webhooks example snippets


protected $except = [
    '/webhooks/*',
];

 'ses' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
        'options' => [
            'ConfigurationSetName' => env('AWS_SES_CONFIGURATION_SET'),
        ],
    ],



namespace App\Jobs\Webhooks\SES;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Spatie\WebhookClient\Models\WebhookCall;

class BounceHandlerJob implements ShouldQueue
{
    use SerializesModels;

    public function __construct(protected WebhookCall $webhookCall)
    {
        //
    }

    public function handle()
    {
        $message = $this->webhookCall->payload['Message'];
        
        if (Arr::get($message, 'bounce.bounceType') !== 'Permanent') return;

        foreach ($message['bounce']['bouncedRecipients'] as $recipient) {
            // todo do something with $recipient['emailAddress']
        }
    }
}



return [
     'jobs' => [
          'bounce' => \App\Jobs\Webhooks\SES\BounceHandlerJob::class,
     ],
];

protected $listen = [
    'ses-webhooks::complaint' => [
        App\Listeners\SES\ComplaintListener::class,
    ],
];



namespace App\Listeners\SES;

use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;

class ComplaintListener implements ShouldQueue
{
    public function handle(WebhookCall $webhookCall)
    {
        $message = $webhookCall->payload['Message'];
        
        foreach ($message['complaint']['complainedRecipients'] as $recipient) {
            // todo do something with $recipient['emailAddress']
        }
    }
}

use Illuminate\Database\Console\PruneCommand;
use Spatie\WebhookClient\Models\WebhookCall;

$schedule->command(PruneCommand::class, [
            '--model' => [WebhookCall::class]
        ])
        ->onOneServer()
        ->daily()
        ->description('Prune webhook_calls.');
bash
php artisan vendor:publish --provider="Ankurk91\SesWebhooks\SesWebhooksServiceProvider"
bash
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-config"