coreproc/laravel-notification-channel-telerivet 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coreproc/laravel-notification-channel-telerivet

Composer 安装命令:

composer require coreproc/laravel-notification-channel-telerivet

包简介

This package makes it easy to send notifications using Telerivet with Laravel 5.5+

README 文档

README

Latest Version on Packagist Software License StyleCI Quality Score Total Downloads

This package makes it easy to send notifications using Telerivet with Laravel 5.5+ and 6.0

Contents

Upgrading from v1.x to v2.x

In v2.x, we've moved the configuration settings of Telerivet from config/broadcasting.php to config/telerivet.php.

To migrate to v2.x, simply run the following command to get the configuration file:

php artisan vendor:publish --provider="CoreProc\NotificationChannels\Telerivet\TelerivetServiceProvider"

Installation

Install this package with Composer:

composer require coreproc/laravel-notification-channel-telerivet

Register the ServiceProvider in your config/app.php (Skip this step if you are using Laravel 5.5):

CoreProc\NotificationChannels\Telerivet\TelerivetServiceProvider::class,

Setting up the Telerivet service

You need to register for an API key and a number for outgoing SMS here: https://telerivet.com

Once you've registered and set up your project and numbers, get the configuration file by running the following command:

php artisan vendor:publish --provider="CoreProc\NotificationChannels\Telerivet\TelerivetServiceProvider"

Add the API key and project ID to your configuration in config/telerivet.php. You can set the credentials in your .env file with the following variables: TELERIVET_API_KEY and TELERIVET_PROJECT_ID.

Optionally, you can also override these configurations by calling the setApiKey() and setProjectId() methods in your TelerivetMessage object.

Usage

You can now send SMS via Telerivet by creating a TelerivetMessage:

use CoreProc\NotificationChannels\Telerivet\TelerivetChannel;
use CoreProc\NotificationChannels\Telerivet\TelerivetMessage;
use Illuminate\Notifications\Notification;

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

    public function toTelerivet($notifiable)
    {
        return (new TelerivetMessage())
            ->setContent('Hello this is a test message');
    }
}

You will have to set a routeNotificationForTelerivet() method in your notifiable model. For example:

class User extends Authenticatable
{
    use Notifiable;

    ....

    /**
     * Specifies the user's mobile number for use in Telerivet
     *
     * @return string
     */
    public function routeNotificationForTelerivet()
    {
        return $this->mobile_number;
    }
}

Once you have that in place, you can simply send an SMS notification to the user via

$user->notify(new AccountActivated);

Events

You can listen to these event when sending a Telerivet SMS message:

Before an SMS is sent:

TelerivetSmsSending::class

When an SMS is sent (this means that the API call to Telerivet was successful):

TelerivetSmsSent::class

When an SMS fails to send (this means the API call to Telerivet has failed):

TelerivetSmsFailed::class

Available Message methods

All the parameters that can be used for a Telerivet message can be applied through the TelerivetMessage object. The documentation from Telerivet can be found here here.

setMessageType(?string $messageType)

[Optional] Type of message to send. If text, will use the default text message type for the selected route.

Possible Values: sms, mms, ussd, call, text

Default: text

setContent(?string $content)

[Required if sending SMS message] Content of the message to send (if message_type is call, the text will be spoken during a text-to-speech call)

setToNumber(?string $toNumber)

[Required if contact_id not set] Phone number to send the message to. This is automatically set if you have defined the routeNotificationForTelerivet() method in your notifiable object.

setContactId(?string $contactId)

[Required if to_number not set] ID of the contact to send the message to. This can be automatically set if you have defined a routeNotificationForTelerivetContactId() method in your notifiable object.

setRouteId(?string $routeId)

[Optional] ID of the phone or route to send the message from

Default: default sender route ID for your project

setStatusUrl(?string $statusUrl)

[Optional] Webhook callback URL to be notified when message status changes

setStatusSecret(?string $statusSecret)

[Optional] POST parameter 'secret' passed to status_url

setIsTemplate(?bool $isTemplate)

[Optional] Set to true to evaluate variables like [[contact.name]] in message content.

(See available variables here)

Default: false

setTrackClicks(?bool $trackClicks)

[Optional] If true, URLs in the message content will automatically be replaced with unique short URLs.

Default: false

setMediaUrls(?array $mediaUrls)

[Optional] URLs of media files to attach to the text message. If message_type is sms, short links to each media

URL will be appended to the end of the content (separated by a new line).

setLabelIds(?array $labelIds)

[Optional] Array string IDs of Label

List of IDs of labels to add to this message

setVars(?object $vars)

[Optional] Custom variables to store with the message

setPriority(?int $priority)

[Optional] Priority of the message. Telerivet will attempt to send messages with higher priority numbers first (for example, so you can prioritize an auto-reply ahead of a bulk message to a large group).

Possible Values: 1, 2

Default: 1

setSimulated(?bool $simulated)

[Optional] Set to true to test the Telerivet API without actually sending a message from the route

Default: false

setServiceId(?string $serviceId)

[Optional] string ID of Service

Service that defines the call flow of the voice call (when message_type is call)

setAudioUrl(?string $audioUrl)

[Optional] The URL of an MP3 file to play when the contact answers the call (when message_type is call).

If audio_url is provided, the text-to-speech voice is not used to say content, although you can optionally use content to indicate the script for the audio.

For best results, use an MP3 file containing only speech. Music is not recommended because the audio quality will be low when played over a phone line.

setTtsLang(?string $ttsLang)

[Optional] The language of the text-to-speech voice (when message_type is call)

Possible Values: en-US, en-GB, en-GB-WLS, en-AU, en-IN, da-DK, nl-NL, fr-FR, fr-CA, de-DE, is-IS, it-IT, pl-PL, pt-BR, pt-PT, ru-RU, es-ES, es-US, sv-SE

Default: en-US

setTtsVoice(?string $ttsVoice)

[Optional] The name of the text-to-speech voice (when message_type=call)

Possible Values: female, male

Default: female

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email to chris.bautista@coreproc.ph 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.

coreproc/laravel-notification-channel-telerivet 适用场景与选型建议

coreproc/laravel-notification-channel-telerivet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 coreproc/laravel-notification-channel-telerivet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 coreproc/laravel-notification-channel-telerivet 我们能提供哪些服务?
定制开发 / 二次开发

基于 coreproc/laravel-notification-channel-telerivet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-28