forked from brayancruces/twilio
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Good day,
[2024-12-21 17:05:17] production.ERROR: Driver [NotificationChannels\Twilio\TwilioChannel] not supported. {"exception":"[object] (InvalidArgumentException(code: 0): Driver [NotificationChannels\\Twilio\\TwilioChannel] not supported. at /home/forge/my.test.com/vendor/laravel/framework/src/Illuminate/Support/Manager.php:109)
I receive the above error when using laravel-notification-channels/twilio on Queued items using ShouldQueue.
$user = User::where('email','[email protected]')->first();
$channels = [
'database',
'mail',
TwilioChannel::class,
];
$user->notify(new TestNotification( $user , $channels ) );
The above works perfectly fine when run from CLI manually, but when executed from within another script, everything starts to fail and break. It works perfectly in Laravel 10, but not in Laravel 11. Below is the notification itself.
<?php
namespace App\Notifications\Hosts;
use App\Models\User;
use App\Models\Generator;
use App\Models\Hosts\Host;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioSmsMessage;
class HostOffline extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct( public User $user, public $channels, public Host $host )
{
$this->channels = $channels ? $channels : ['database','mail'];
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via($notifiable)
{
/*
This is because Twilios implementation of their service provider
is stupid and won't serialize properly otherwise.
*/
$methods = [];
foreach ($this->channels as $key) {
if ($key == 'sms') {
$methods[] = TwilioChannel::class;
} else {
$methods[] = $key;
}
}
return $methods;
}
/*
Write the Twilio notification
*/
public function toTwilio($notifiable)
{
if( $this->user->sms->verified_at )
{
return (new TwilioSmsMessage())
->content("A message goes here {$this->host->name}.");
}
}
}
promatik
Metadata
Metadata
Assignees
Labels
No labels