twilio
twilio copied to clipboard
Anonymous/On Demand: [HTTP 400] Unable to create record: A 'To' phone number is required.
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()
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;
}
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; }