Send Laravel Notifications as a Phone Call

News

November 15th, 2019

nexmo-voice-notifications.png

Nexmo Voice Channel is a package that adds a notification channel to Laravel using Nexmo’s voice API:

This package provides a notification channel for the Laravel framework that works with Nexmo’s voice API, allowing text-to-speech phone calls. It also provides a fluent interface to construct your message content.

To use this notification channel, you route a notification through VoiceChannel and provide a toVoice() method. The readme documents an example so you can get a visual of using this package:

1use Roomies\NexmoVoiceChannel\Markup\Message;
2use Roomies\NexmoVoiceChannel\Markup\SayAs;
3use Roomies\NexmoVoiceChannel\Markup\Sentence;
4use Roomies\NexmoVoiceChannel\NexmoVoiceChannel;
5 
6/**
7 * Get the notification's delivery channels.
8 *
9 * @param mixed $notifiable
10 * @return array
11 */
12public function via($notifiable)
13{
14 return [NexmoVoiceChannel::class];
15}
16 
17/**
18 * Get the voice representation of the notification.
19 *
20 * @param mixed $notifiable
21 * @return \Roomies\NexmoVoiceChannel\Markup\Message
22 */
23public function toVoice($notifiable)
24{
25 return new Message([
26 new Sentence('Hi, thanks for joining Roomies.'),
27 new Sentence([
28 'Your verification code is',
29 new SayAs('ABC123')->interpretAs('spell-out')
30 ]),
31 ]);
32}

Here’s another example demonstrating the package’s markup types you can use to create a notification:

1new Sentence([
2 'Hey!',
3 (new Pause)->time('1s'),
4 (new Prosody('Wake up!'))->volume('loud'),
5 (new Substitution(
6 (new SayAs('US'))->interpretAs('spell-out'),
7 ))->alias('United States'),
8])

You can learn more about this package, get full installation instructions, and view the source code on GitHub at roomies-com/nexmo-voice-channel.

This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.