Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ class ExampleNotification extends Notification
```
You can also use `->params(["param1" => "val"])` to add extra parameters to the request and `->headers(["header1" => "val"])` to add extra headers to the request.

#### On-Demand Notifications
Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification:
```
Notification::route(\Gr8Shivam\SmsApi\Notifications\SmsApiChannel::class, 'TO')
->notify(new ExampleNotification());
```

### Getting Response
You can get response by using `->response()` or get the Response Code using `->getResponseCode()`. For example, `smsapi()->sendMessage("TO","MESSAGE")->response();`

Expand Down
9 changes: 8 additions & 1 deletion src/Notifications/SmsApiChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gr8Shivam\SmsApi\Notifications\SmsApiMessage;
use Gr8Shivam\SmsApi\SmsApi;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Notifications\Notification;

class SmsApiChannel
Expand All @@ -28,7 +29,13 @@ public function __construct(SmsApi $client) {
*/
public function send($notifiable, Notification $notification)
{
if (! $mobile = $notifiable->routeNotificationFor('sms_api')) {
if ($notifiable instanceof AnonymousNotifiable) {
$mobile = $notifiable->routes[SmsApiChannel::class];
} else {
$mobile = $notifiable->routeNotificationFor('sms_api');
}

if (!$mobile) {
return;
}

Expand Down