Skip to content

Commit

Permalink
fix: channel fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
atymic committed Feb 17, 2024
1 parent f39e903 commit 42d37f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 0 additions & 4 deletions src/Exceptions/CouldNotSendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@

class CouldNotSendNotification extends \Exception
{
public static function touchSmsError(string $message, int $code): self
{
return new static(sprintf('TouchSms responded with error %d, message: %s', $code, $message), $code);
}
}
18 changes: 9 additions & 9 deletions src/TouchSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function send($notifiable, Notification $notification): void
{
$to = $notifiable->routeNotificationFor('touchsms');

if (! $to) {
if (!$to) {
$to = $notifiable->routeNotificationFor(TouchSmsChannel::class);
}

if (! $to) {
if (!$to) {
return;
}

Expand All @@ -36,13 +36,13 @@ public function send($notifiable, Notification $notification): void
$message = new TouchSmsMessage($message);
}

if (! $message instanceof TouchSmsMessage) {
if (!$message instanceof TouchSmsMessage) {
return;
}

$apiMessage = (new OutboundMessage())
->setTo($to)
->setFrom($message->sender ?? config('services.touchsms.default_sender'))
->setFrom($message->sender ?? config('services.touchsms.default_sender') ?? 'SHARED_NUMBER')
->setBody($message->content)
->setReference($message->reference)
->setMetadata($message->metadata);
Expand All @@ -51,13 +51,13 @@ public function send($notifiable, Notification $notification): void
$apiMessage->setDate($message->sendAt->format(\DateTimeInterface::ATOM));
}

$response = $this->client->sendMessages(new SendMessageBody([
'messages' => [$apiMessage],
]));
$response = $this->client->sendMessages(
(new SendMessageBody())->setMessages([$apiMessage])
);

if (! $response || count($response->getData()->getErrors())) {
if (!$response || count($response->getData()->getErrors())) {
$error = $response->getData()->getErrors()[0];
throw CouldNotSendNotification::touchSmsError($error->getErrorCode().$error->getErrorHelp() ? ' - '.$error->getErrorHelp() : '', 400);
throw new CouldNotSendNotification($error->getErrorCode() . ($error->getErrorHelp() ? ' - ' . $error->getErrorHelp() : ''), 400);
}
}
}
10 changes: 5 additions & 5 deletions src/TouchSmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class TouchSmsMessage
public string $content;

/** @var string|null */
public ?string $sender;
public ?string $sender = null;

/** @var string|null */
public ?string $campaign;
public ?string $campaign = null;

/** @var string|null */
public ?string $reference;
public ?string $reference = null;

/** @var DateTimeInterface|null */
public ?DateTimeInterface $sendAt;
public ?DateTimeInterface $sendAt = null;

/** @var array|null */
public ?array $metadata;
public ?array $metadata = null;

public function __construct(string $content = '')
{
Expand Down
5 changes: 5 additions & 0 deletions src/TouchSmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function register(): void
);
});
}

public function provides(): array
{
return [Client::class];
}
}

0 comments on commit 42d37f7

Please sign in to comment.