Skip to content

Commit 251c4fd

Browse files
committed
Add twiml() to readme
1 parent c9cc249 commit 251c4fd

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class AccountApproved extends Notification
131131
}
132132
```
133133

134-
Or create a Twilio call:
134+
Or create a Twilio call, using either an external TwiML url:
135135

136136
``` php
137137
use NotificationChannels\Twilio\TwilioChannel;
@@ -153,6 +153,32 @@ class AccountApproved extends Notification
153153
}
154154
```
155155

156+
Or create a Twilio call, and send a TwiML response directly:
157+
158+
``` php
159+
use NotificationChannels\Twilio\TwilioChannel;
160+
use NotificationChannels\Twilio\TwilioCallMessage;
161+
use Illuminate\Notifications\Notification;
162+
use Twilio\TwiML\VoiceResponse;
163+
164+
class AccountApproved extends Notification
165+
{
166+
public function via($notifiable)
167+
{
168+
return [TwilioChannel::class];
169+
}
170+
171+
public function toTwilio($notifiable)
172+
{
173+
return (new TwilioCallMessage())
174+
->twiml(
175+
(new VoiceResponse())
176+
->say('Hello world')
177+
);
178+
}
179+
}
180+
```
181+
156182
In order to let your Notification know which phone are you sending/calling to, the channel will look for the `phone_number` attribute of the Notifiable model. If you want to override this behaviour, add the `routeNotificationForTwilio` method to your Notifiable model.
157183

158184
```php
@@ -174,6 +200,9 @@ public function routeNotificationForTwilio()
174200

175201
- `from('')`: Accepts a phone to use as the notification sender.
176202
- `url('')`: Accepts an url for the call TwiML.
203+
- `twiml(VoiceResponse)`: Accepts a \Twilio\TwiML\VoiceResponse containing the call TwiML.
204+
205+
> You can use *either* url() *or* twiml() on a TwilioCallMessage object, not both.
177206
178207
## Changelog
179208

0 commit comments

Comments
 (0)