laraditz/twilio
最新稳定版本:1.0.1
Composer 安装命令:
composer require laraditz/twilio
包简介
Twilio SDk wrapper for Laravel
关键字:
README 文档
README
Twilio SDk wrapper for Laravel. Includes event for receiving messages and status updates.
Installation
You can install the package via composer:
composer require laraditz/twilio
Before Start
Configure your variables in your .env (recommended) or you can publish the config file and change it there.
TWILIO_ACCOUNT_SID=<your_account_sid>
TWILIO_AUTH_TOKEN=<your_auth_token>
TWILIO_FROM=<the_sender_number>
(Optional) You can publish the config file via this command:
php artisan vendor:publish --provider="Laraditz\Twilio\TwilioServiceProvider" --tag="config"
Run the migration command to create the necessary database table.
php artisan migrate
Add routeNotificationForTwilio method to your Notifiable model.
public function routeNotificationForTwilio($notification) { return $this->mobile_no; }
Usage
Now you can use the channel in your via() method inside the notification:
use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Laraditz\Twilio\TwilioChannel; use Laraditz\Twilio\TwilioWhatsappMessage; class TestNotification extends Notification { use Queueable; public function via($notifiable) { return [TwilioChannel::class]; } public function toTwilio($notifiable) { return (new TwilioWhatsappMessage()) ->content("Test Whatsapp message!") ->mediaUrl("https://news.tokunation.com/wp-content/uploads/sites/5/2022/07/Kamen-Rider-Geats-Teaser.jpeg"); } }
You can also send SMS:
use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Laraditz\Twilio\TwilioChannel; use Laraditz\Twilio\TwilioSmsMessage; class TestNotification extends Notification { use Queueable; public function via($notifiable) { return [TwilioChannel::class]; } public function toTwilio($notifiable) { return (new TwilioSmsMessage()) ->content("Test SMS message!"); } }
Event
This package also provide an event to allow your application to listen for Twilio message receive and status callback. You can create your listener and register it under event below.
| Event | Description |
|---|---|
| Laraditz\Twilio\Events\MessageReceived | When a message comes in. |
| Laraditz\Twilio\Events\StatusCallback | Receive status update. |
Webhook URL
You may setup the URLs below on Twilio dashboard so that Twilio will push new messages and status update to it and it will then trigger the MessageReceived and StatusCallback events above.
https://your-app-url/twilio/webhooks/receive //for message receive
https://your-app-url/twilio/webhooks/status //for status update
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email raditzfarhan@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-23