Giter Site home page Giter Site logo

roomies-com / vonage-voice-channel Goto Github PK

View Code? Open in Web Editor NEW
54.0 3.0 6.0 41 KB

Send Laravel notifications as a Nexmo phone call

Home Page: https://www.roomies.com/open-source

License: MIT License

PHP 100.00%
laravel laravel-notification-channels nexmo

vonage-voice-channel's Introduction

Vonage Voice Notification Channel for Laravel

Latest Version on Packagist GitHub Workflow Status Total Downloads

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

Installation

You can install the package via Composer:

composer require roomies/vonage-voice-channel

Under the hood we use laravel/vonage-notification-channel to configure Vonage, so make sure you have it properly configured using Vonage environment variables. However, in order to make voice calls you need to provide additional credentials in your environment. Note that the private key can be a string or path to the key file.

VONAGE_APPLICATION_ID=
VONAGE_PRIVATE_KEY=

Then add your call from number and voice to config/services.php under the vonage key. You can review the available voices in the Vonage documentation.

'vonage' => [
    'call_from' => env('VONAGE_CALL_FROM'),
    'call_language' => env('VONAGE_CALL_LANGUAGE', 'en-US'),
    'call_style' => env('VONAGE_CALL_STYLE', 0),
],

Usage

Simply route a notification through the VoiceChannel and return a formatted message from the toVoice method. You use a string with your own Speech Synthesis Markup Language (SSML) or use the the included wrapper API to build up your message.

use Roomies\VonageVoiceChannel\Markup\Message;
use Roomies\VonageVoiceChannel\Markup\SayAs;
use Roomies\VonageVoiceChannel\Markup\Sentence;
use Roomies\VonageVoiceChannel\VonageVoiceChannel;

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return [VonageVoiceChannel::class];
}

/**
 * Get the voice representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Roomies\VonageVoiceChannel\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')
        ]),
    ]);
}

Markup

There are a handful of different markup types available to get the right message you're after. Here are some additional examples, otherwise browse src/Markup to see all the available options.

new Paragraph([
    new Sentence('This is the first sentence of a paragraph.'),
]);

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

Custom

Alternatively, you're free to just return your own SSML markup as a string. This gives you complete control if you need something more custom or have more complex requirements.

/**
 * Get the voice representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return string
 */
public function toVoice($notifiable)
{
    return '<speak>
        <s>Hi, thanks for joining Roomies</s>
        <s>Your verification code is <say-as interpret-as="spell-out">ABC123</say-as></s>
    <speak>';
}

License

The MIT License (MIT). Please see License File for more information.

vonage-voice-channel's People

Contributors

ankurk91 avatar dwightwatson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vonage-voice-channel's Issues

Config services vs nexmo file

Hey thanks for providing this package.

What is the reason to not use the nexmo/nexmo-laravel config file for the from and voice config?

It feels a bit clunky to spread the configs for the same service ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.