Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11 - Driver [NotificationChannels\Twilio\TwilioChannel] not supported #153

Open
mattrosenblatt opened this issue Dec 21, 2024 · 1 comment

Comments

@mattrosenblatt
Copy link

mattrosenblatt commented Dec 21, 2024

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}.");
        }
        
    }


}

@mattrosenblatt
Copy link
Author

I've added more relevant information to help debug this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant