-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does this work with SMS/Nexmo? #147
Comments
Never tested it with SMS, but it uses Laravel's notification system, so it should be at least compatible with Nexmo. How are you configuring it?
|
I'm getting this error, L5.5.
|
I have managed to get around this but it has been a bit hacky. I updated config/health/config.php 'notifications' => [
...
'channels' => [
'mail',
'nexmo',
'nexmo' => [
'sender' => \App\Health\SMSNotification::class,
],
],
...
], Added a new class: <?php
namespace App\Health;
use Illuminate\Notifications\Messages\NexmoMessage;
class SMSNotification
{
public function send($notifiable, $item)
{
return (new NexmoMessage())
->content($item->getMessage());
}
} This provides the ability for the sending of SMS notifications. It will error on one of the channels, but there is no way around this due to the way it works. I also added my own listener so I can loop through the users in my database: <?php
namespace App\Health;
use Illuminate\Support\Facades\Notification;
use PragmaRX\Health\Events\RaiseHealthIssue;
use PragmaRX\Health\Notifications\HealthStatus;
class Listener
{
/**
* @return static
*/
private function getNotifiableUsers()
{
$users = $model = instantiate(
config('health.notifications.users.model')
)->all();
return $users;
}
/**
* Handle the event.
*
* @param RaiseHealthIssue $event
* @return void
*/
public function handle(RaiseHealthIssue $event)
{
try {
$event->failure->targets->each(function ($target) use ($event) {
if (! $target->result->healthy) {
Notification::send(
$this->getNotifiableUsers(),
new HealthStatus($target, $event->channel)
);
}
});
} catch (\Exception $exception) {
report($exception);
} catch (\Throwable $error) {
report($error);
}
}
} I think it would help a lot if the methods in the service provider were of protected visibility to make it easier to extend. |
Can this send SMS message notifications? I'm struggling to get it working.
The text was updated successfully, but these errors were encountered: