Laravel 7/6 Send Notifications as Voice Call

Send notification as voice call in Laravel. In this tutorial, we will learn how to use send notification as Voice or Phone call in laravel.

Here we will discuss nexmo-voice-channel for the send voice notification.

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.

1. Install notifcation package

Now open your command prompt and go to your project root directory and type the below command for install the package via Composer:

 composer require roomies/nexmo-voice-channel 

2. Configure nexmo credentials in .env

Go to your project root directory and set the nexmo credentials in .env file:

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.

'nexmo' => [
    'call_from' => env('NEXMO_CALL_FROM'),
    'call_voice' => env('NEXMO_CALL_VOICE', 'Kimberly'),
],

3. Create a Notification channel

In this step, create a notification channel and put the update the below methods in your channel:

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:

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

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

You may like

  1. Php Artisan Serve Not Working Properly – Laravel Command
  2. Laravel Clear Cache Using Artisan Command CLI
  3. Make Auth (Artisan Command) in Laravel 6
  4. Laravel 6 Artisan Console Command Cheat Sheet ( List )
  5. Check Laravel Version Command-Line (cmd) and File
  6. How to Create a Controller And Model Laravel 6 Using cmd
  7. Laravel create and use middleware command
  8. Laravel clear cache shared hosting using artisan command

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *