Skip to content

Commit

Permalink
feat: message media channel
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlewis committed Jan 16, 2025
1 parent 27d3f62 commit fa17c6b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public function createVonageDriver(): Channels\Vonage
{
return $this->createChannelDriver(Channels\Vonage::class);
}

/**
* Create the message media channel driver.
*/
public function createMessageMediaDriver(): Channels\MessageMedia
{
return $this->createChannelDriver(Channels\MessageMedia::class);
}

/**
* Create a new channel driver.
Expand Down
45 changes: 45 additions & 0 deletions src/Channels/MessageMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Foxhound\Channels;

use Foxhound\Data;
use RuntimeException;
use Foxhound\Manifest;
use Foxhound\Support\ChannelType;
use Illuminate\Mail\Events\MessageSending;
use Illuminate\Notifications\Events\NotificationSending;

class MessageMedia extends Vonage
{
/**
* {@inheritDoc}
*/
public function intercept(NotificationSending | MessageSending $event, Manifest $manifest): void
{
// Message Media can only be intercepted when sending a notification.
if (!($event instanceof NotificationSending)) {
return;
}

throw_unless(method_exists($event->notification, 'toMessageMedia'), new RuntimeException('Notification does not have a "toMessageMedia" method.'));

$message = $event->notification->toMessageMedia($event->notifiable);

$manifest->data('message', $message->message);
$manifest->data('to', $event->notifiable->routeNotificationFor('messagemedia', $event->notification));
$manifest->data('from', $message->from);
}

/**
* {@inheritDoc}
*/
public function data(): Data\Response\ChannelData
{
return Data\Response\ChannelData::from([
'key' => $this->key(),
'name' => 'Message Media',
'type' => ChannelType::Sms,
'unreadMessagesCount' => $this->storage->getUnreadMessagesCount($this),
]);
}
}

0 comments on commit fa17c6b

Please sign in to comment.