In this tutorial you will learn about the Laravel 7/6 Send Notifications as Voice Call and its application with practical example.
In this Laravel 7/6 Send Notifications as Voice Call tutorial I will show you how to Send notification as voice call in Laravel. In this tutorial, you will learn send notification as Voice or Phone call in laravel. In this example we will be using nexmo-voice-channel for the send voice notification. In this step by step guide I’ll demonstrate you how to send notification as voice call in Laravel.
Laravel 7/6 Send Notifications as Voice Call
1. Install notifcation package
In first step, we will install voice notification Package via the composer dependency manager. Use the following command to install voice notification Package.
1 |
composer require roomies/nexmo-voice-channel |
2. Configure nexmo credentials in .env
After installing nexmo-voice-channel voice notification Package we will set require application id and private key as following in .env file:
1 2 |
NEXMO_APPLICATION_ID= NEXMO_PRIVATE_KEY= |
Then add your call from number and voice to config/services.php under the nexmo key. You can review the available voices in the Nexmo documentation.
1 2 3 4 |
'nexmo' => [ 'call_from' => env('NEXMO_CALL_FROM'), 'call_voice' => env('NEXMO_CALL_VOICE', 'Kimberly'), ], |
3. Create a Notification channel
Now, in this step we will create notification channel as following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
use Roomies\NexmoVoiceChannel\Markup\Message; use Roomies\NexmoVoiceChannel\Markup\SayAs; use Roomies\NexmoVoiceChannel\Markup\Sentence; use Roomies\NexmoVoiceChannel\NexmoVoiceChannel; /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [NexmoVoiceChannel::class]; } /** * Get the voice representation of the notification. * * @param mixed $notifiable * @return \Roomies\NexmoVoiceChannel\Markup\Message */ public function toVoice($notifiable) { return new Message([ new Sentence('Hi, thanks for joining Roomies.'), new Sentence([ 'Your verification code is', new SayAs('ABC123')->interpretAs('spell-out') ]), ]); } |
In the below is another example demonstrating the package’s markup types you can use to create a notification:
1 2 3 4 5 6 7 8 |
new Sentence([ 'Hey!', (new Pause)->time('1s'), (new Prosody('Wake up!'))->volume('loud'), (new Substitution( (new SayAs('US'))->interpretAs('spell-out'), ))->alias('United States'), ]) |