swiftsmsgh-laravel-notification-channels/swiftsmsgh
最新稳定版本:v1.0.3
Composer 安装命令:
composer require swiftsmsgh-laravel-notification-channels/swiftsmsgh
包简介
swiftsms-GH SMS Notification Channel For Laravel
README 文档
README
📲 Swiftsmsgh Notifications Channel for Laravel.
This package makes it easy to send SMS notifications with Swiftsms-GH using the official swiftsmsgh-api-sdk.
Contents
Installation
You can install the package via composer:
composer require laravel-notification-channels/swiftsmsgh
Configuration
Add your Swiftsmsgh SENDER_ID and API_TOKEN to your .env
SWIFTSMSGH_API_TOKEN=100|yourapitoken # always required SWIFTSMSGH_SENDER_ID=Demo # always required
Add the configuration to your services.php config file:
'swiftsmsgh' => [ 'sender_id' => env('SWIFTSMSGH_SENDER_ID', 'sender_id'), 'api_token' => env('SWIFTSMSGH_API_TOKEN', 'api_token'), ]
Setting up the Swiftsmsgh service
You'll need a Swiftsms-GH account. Head over to their website and create or login to your account.
Navigate to API Integration and then API Token in the sidebar to copy existing one or generate an API Token.
Usage
You can use the channel in your via() method inside the notification:
use Illuminate\Notifications\Notification; use NotificationChannels\Swiftsmsgh\SwiftsmsghMessage; use NotificationChannels\Swiftsmsgh\SwiftsmsghChannel; class InvoicePaid extends Notification { public function via($notifiable) { return [SwiftsmsghChannel::class]; } public function toSwiftsmsgh($notifiable) { return (new SwiftsmsghMessage) ->content("Your invoice has been paid! Amount: {$this->amount}") ->from('MyApp'); } }
In your notifiable model, make sure to include a routeNotificationForSwiftsmsgh() method, which returns a phone number including country code.
public function routeNotificationForSwiftsmsgh() { return $this->phone; // 233200000000 }
Basic SMS
public function toSwiftsmsgh($notifiable) { return SwiftsmsghMessage::create("Hello there!"); }
Scheduled SMS
You can schedule messages to be sent at a later time:
public function toSwiftsmsgh($notifiable) { return (new SwiftsmsghMessage("Happy Birthday!")) ->from('MyCompany') ->schedule(now()->addDay()) ->campaign('BirthdayBlast') ->callbackUrl('https://example.com/delivery-report'); }
Voice Call
Send a text-to-speech voice call:
public function toSwiftsmsgh($notifiable) { return SwiftsmsghMessage::createVoice("Your verification code is 1234"); }
MMS Message
Send a multimedia message (requires a public media URL):
public function toSwiftsmsgh($notifiable) { return SwiftsmsghMessage::createMms( "Check out this image!", "https://example.com/image.jpg" ); }
Whatsapp Message
public function toSwiftsmsgh($notifiable) { return SwiftsmsghMessage::createWhatsapp("Hello from Whatsapp API!"); }
Available methods
content(string $content): Set the message content.from(string $sender)orsender(string $sender): Set the sender ID.schedule(DateTimeInterface $time): Schedule the message for a future time.campaign(string $name): Set a campaign name for reporting.callbackUrl(string $url): Set a callback URL for delivery reports.reference(string $ref): Set a custom reference ID.
Error Handling
If the API request fails (e.g. invalid credentials, insufficient balance), the channel will throw a NotificationChannels\Swiftsmsgh\Exceptions\CouldNotSendNotification exception.
This allows you to leverage Laravel's built-in notification retry mechanism or handle failures gracefully.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email support@swiftsmsgh.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.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-09