hafael/totalvoice-notification-channel

TotalVoice Notification Channels for Laravel 5.3+

v1.1.0 2019-09-28 21:38 UTC

This package is auto-updated.

Last update: 2024-10-29 04:53:42 UTC


README

Latest Version on Packagist Software License Build Status StyleCI SymfonyInsight Quality Score Code Coverage Total Downloads

This package makes it easy to send TotalVoice Notifications with Laravel 5.3+.

Contents

Installation

You can install the package via composer:

composer require hafael/totalvoice-notification-channel

Add the service provider (only required on Laravel 5.4 or lower):

// config/app.php
'providers' => [
    ...
    NotificationChannels\TotalVoice\TotalVoiceServiceProvider::class,
],

Setting up the TotalVoice service

Add your TotalVoice Access Token to your config/services.php:

// config/services.php
...
'totalvoice' => [
    'access_token' => env('TOTALVOICE_ACCESS_TOKEN'),
],
...

Usage

Now you can use the channel in your via() method inside the notification:

use NotificationChannels\TotalVoice\TotalVoiceChannel;
use NotificationChannels\TotalVoice\TotalVoiceSmsMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [TotalVoiceChannel::class];
    }

    public function toTotalVoice($notifiable)
    {
        return (new TotalVoiceSmsMessage())
            ->content("Your {$notifiable->service} account was approved!");
    }
}

You can also send an TTS (text-to-speech) audio call:

use NotificationChannels\TotalVoice\TotalVoiceChannel;
use NotificationChannels\TotalVoice\TotalVoiceTtsMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [TotalVoiceChannel::class];
    }

    public function toTotalVoice($notifiable)
    {
        return (new TotalVoiceTtsMessage())
            ->content("Your {$notifiable->service} account was approved!");
    }
}

Or create a TotalVoice audio call from .mp3 file url:

use NotificationChannels\TotalVoice\TotalVoiceChannel;
use NotificationChannels\TotalVoice\TotalVoiceAudioMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [TotalVoiceChannel::class];
    }

    public function toTotalVoice($notifiable)
    {
        return (new TotalVoiceAudioMessage())
            ->content("http://foooo.bar/audio.mp3");
    }
}

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 routeNotificationForTotalVoice method to your Notifiable model.

public function routeNotificationForTotalVoice()
{
    return '+5521999999999';
}

Available Message methods

TotalVoiceSmsMessage (SMS)

  • provideFeedback(false): Wait for recipient feedback.
  • multipart(false): Supports SMS with > 160 < 16,000 char. Sends multiple sms up to 160char to the same number.
  • scheledule(new \DateTime()): date and time to schedule the sms delivery. null as default sends immediately.
  • content(''): Accepts a string value for the notification body.

TotalVoiceTtsMessage (Text-to-speech audio call)

  • provideFeedback(false): Wait for recipient feedback.
  • fakeNumber(null): Accepts a phone to use as the notification sender.
  • recordAudio(false): Save the call.
  • detectCallbox(false): Automatically disconnects within 3 seconds if it falls into the mailbox (vivo, claro, tim, oi).
  • speed(0): From -10 to 10. When -10=very slow, 0=normal and 10=very fast.
  • voiceType('br-Vitoria'): language-Character acronym who will speak.
  • content(''): Accepts a string value for the notification body.

TotalVoiceAudioMessage (.mp3 audio call)

  • provideFeedback(false): Wait for recipient feedback.
  • fakeNumber('+5521999999999'): Accepts a phone to use as the notification sender.
  • recordAudio(false): Save the call.
  • detectCallbox(false): Automatically disconnects within 3 seconds if it falls into the mailbox (vivo, claro, tim, oi).
  • content('http://foooo.bar/audio.mp3'): Accepts an .mp3 file url for the call.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email villa655321verde@gmail.com instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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