Giant Update
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Notification\Adapters;
|
||||
|
||||
use App\Models\NotificationDelivery;
|
||||
use App\Services\Notification\Contracts\NotificationChannelAdapter;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class WhatsAppUnofficialAdapter implements NotificationChannelAdapter
|
||||
{
|
||||
public function send(NotificationDelivery $delivery): array
|
||||
{
|
||||
$config = $delivery->channelConfig;
|
||||
$credentials = $config?->credentials ?? [];
|
||||
$settings = $config?->settings ?? [];
|
||||
$url = $settings['send_url'] ?? null;
|
||||
if (! $url) {
|
||||
throw ValidationException::withMessages(['channel' => 'URL pengiriman gateway unofficial belum diatur.']);
|
||||
}
|
||||
$headers = [];
|
||||
if ($apiKey = $credentials['api_key'] ?? null) {
|
||||
$headers[$settings['api_key_header'] ?? 'X-API-Key'] = $apiKey;
|
||||
}
|
||||
$payload = [
|
||||
$settings['destination_field'] ?? 'number' => $delivery->destination,
|
||||
$settings['message_field'] ?? 'message' => $delivery->rendered_body,
|
||||
'instance_id' => $credentials['instance_id'] ?? null,
|
||||
];
|
||||
$response = Http::withHeaders($headers)->timeout(30)->post($url, $payload)->throw()->json();
|
||||
|
||||
return ['provider_message_id' => data_get($response, $settings['message_id_path'] ?? 'id'), 'response' => $response];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user