roomies / nexmo-voice-channel
通过电话发送 Laravel 通知
6.1.0
2024-03-07 04:56 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/notifications: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- laravel/vonage-notification-channel: ^3.2
Requires (Dev)
- mockery/mockery: ^1.3.1
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-15 10:16:37 UTC
README
此包为 Laravel 框架提供了一个通知通道,可与 Vonage 语音 API 一起使用,实现文本到语音的电话通话。它还提供了一个流畅的接口来构建您的消息内容。
安装
您可以通过 Composer 安装此包
composer require roomies/vonage-voice-channel
在底层,我们使用 laravel/vonage-notification-channel
来配置 Vonage,因此请确保您已正确使用 Vonage 环境变量进行配置。然而,为了进行电话呼叫,您需要在您的环境中提供额外的凭证。请注意,私钥可以是字符串或密钥文件的路径。
VONAGE_APPLICATION_ID= VONAGE_PRIVATE_KEY=
然后,将您的呼叫号码和语音添加到 config/services.php
中的 vonage
键下。您可以在 Vonage 文档中查看 可用的语音。
'vonage' => [ 'call_from' => env('VONAGE_CALL_FROM'), 'call_language' => env('VONAGE_CALL_LANGUAGE', 'en-US'), 'call_style' => env('VONAGE_CALL_STYLE', 0), ],
用法
只需将通知通过 VoiceChannel
路由,并从 toVoice
方法返回一个格式化的消息。您可以使用包含您自己的 语音合成标记语言 (SSML) 的字符串,或使用包含的包装器 API 来构建您的消息。
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') ]), ]); }
标记
有几种不同的标记类型可供选择,以获取您所需的消息。以下是一些额外的示例,否则请浏览 src/Markup
以查看所有可用选项。
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'), ])
自定义
或者,您可以选择仅返回自己的 SSML 标记字符串。如果您需要更定制的内容或具有更复杂的要求,这将提供完全的控制。
/** * 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>'; }
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。