laravel-notification-channels / twilio

Twilio notifications channel for Laravel
https://laravel-notification-channels.com
226 stars 36 forks source link

Anonymous/On Demand: [HTTP 400] Unable to create record: A 'To' phone number is required. #132

Open alexc-wormhole opened 2 years ago

alexc-wormhole commented 2 years ago

Laravel 8 using "laravel-notification-channels/twilio": "^3.1",

.env file:

TWILIO_USERNAME=
TWILIO_PASSWORD=
TWILIO_AUTH_TOKEN=[redacted_but_valid]
TWILIO_ACCOUNT_SID=[redacted_but_valid]
TWILIO_FROM=[redacted_but_valid]
TWILIO_ALPHA_SENDER=
#TWILIO_SMS_SERVICE_SID=[redacted_but_valid]
TWILIO_DEBUG_TO=
TWILIO_PHONE_SID=[redacted_but_valid]

Notification class:

    public function via ($notifiable)
    {
        return [TwilioChannel::class];
    }

    public function toTwilio ($notifiable)
    {
        return (new TwilioSmsMessage())
            ->content("test message");
    }

Called using:

Notification::route ('twilio', $phone)->notify (new GuestCodeWasGenerated ($this->code, $this->web_url));

Trace:

Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: A 'To' phone number is required. in /var/www/html/vendor/twilio/sdk/src/Twilio/Version.php:88
Stack trace:
#0 /var/www/html/vendor/twilio/sdk/src/Twilio/Version.php(223): Twilio\Version->exception()
#1 /var/www/html/vendor/twilio/sdk/src/Twilio/Rest/Api/V2010/Account/MessageList.php(69): Twilio\Version->create()
#2 /var/www/html/vendor/laravel-notification-channels/twilio/src/Twilio.php(103): Twilio\Rest\Api\V2010\Account\MessageList->create()
#3 /var/www/html/vendor/laravel-notification-channels/twilio/src/Twilio.php(43): NotificationChannels\Twilio\Twilio->sendSmsMessage()
#4 /var/www/html/vendor/laravel-notification-channels/twilio/src/TwilioChannel.php(59): NotificationChannels\Twilio\Twilio->sendMessage()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(148): NotificationChannels\Twilio\TwilioChannel->send()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(106): Illuminate\Notifications\NotificationSender->sendToNotifiable()
broadstreetboy commented 2 years ago

Set TWILIO_DEBUG_TO= to: TWILIO_DEBUG_TO=null and you'll be good to go.

It's getting caught up here in the sendSmsMessage() method:

        $debugTo = $this->config->getDebugTo();

        if ($debugTo !== null) {
            $to = $debugTo;
        }
sawirricardo commented 2 years ago

is this only in debugging? What about in production? it seems we need to set it to null in production

Set TWILIO_DEBUG_TO= to: TWILIO_DEBUG_TO=null and you'll be good to go.

It's getting caught up here in the sendSmsMessage() method:

        $debugTo = $this->config->getDebugTo();

        if ($debugTo !== null) {
            $to = $debugTo;
        }