clevyr / laravel-twilio-channel
Twilio的Laravel通知通道
v1.0.0
2023-06-27 16:09 UTC
Requires
- php: ^8.1
- spatie/laravel-package-tools: ^1.9.2
- twilio/sdk: ^6.40
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
- dev-main
- v1.0.0
- v0.2.0
- v0.1.1
- v0.1.0
- dev-renovate/configure
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-5
- dev-dependabot/github_actions/actions/checkout-4
- dev-laravel-10-upgrade
- dev-dependabot/github_actions/aglipanci/laravel-pint-action-2.3.0
- dev-dependabot/github_actions/ramsey/composer-install-2
This package is auto-updated.
Last update: 2024-09-15 03:55:12 UTC
README
使用Twilio发送短信消息的Laravel通知通道。
安装
您可以通过Composer安装此包
composer require clevyr/laravel-twilio-channel
在Twilio上配置一个账户,然后添加以下环境变量
TWILIO_SID=
TWILIO_AUTH_TOKEN=
TWILIO_PHONE_NUMBER=
接下来,使用以下命令发布配置文件
php artisan vendor:publish --provider="Clevyr\LaravelTwilioChannel\LaravelTwilioChannelServiceProvider"
这是发布配置文件的内容(不带描述性注释)
return [ 'sid' => env('TWILIO_SID'), 'auth_token' => env('TWILIO_AUTH_TOKEN'), 'phone_number' => env('TWILIO_PHONE_NUMBER'), ];
用法
在您的Laravel通知中
- 实现
TwilioNotification
接口 - 将
TwilioChannel
添加到您的via
返回数组值中 - 构建一个返回
TwilioMessage
对象的toTwilio
函数
默认情况下,Twilio通道将使用您的可通知对象的phone_number
字段发送电话号码,该号码必须以类似18884445555
的格式。下面是如何覆盖此设置。
<?php namespace App\Notifications; use Clevyr\LaravelTwilioChannel\Channels\TwilioChannel; use Clevyr\LaravelTwilioChannel\Contracts\TwilioNotification; use Clevyr\LaravelTwilioChannel\Messages\TwilioMessage; use Illuminate\Notifications\Notification; class MyNotification extends Notification implements TwilioNotification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [TwilioChannel::class]; } /** * Get the twilio representation of the notification. * * @param mixed $notifiable * @return \Clevyr\LaravelTwilioChannel\Messages\TwilioMessage */ public function toTwilio($notifiable) { return (new TwilioMessage) ->line('Your first line.') ->line('A second line, with a break between the last line.'); }
覆盖可通知电话号码字段
默认情况下,TwilioChannel
将使用您的可通知对象的phone_number
字段发送短信消息。要覆盖此设置并使用不同的字段,请在您的可通知类中设置twilioPhoneNumberField
实例变量。
class User extends Authenticatable { public $twilioPhoneNumberField = 'primary_phone_number'; // } Now if you generate a notification from a `User` object, `TwilioChannel` will use the user's `primary_phone_number` field to send messages.
测试
composer test
代码风格检查
composer analyse
使用Laravel Pint格式化
composer format
更新日志
请参阅更新日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请参阅我们的安全策略以了解如何报告安全漏洞。
鸣谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。