Code Monkey home page Code Monkey logo

pushover's Introduction

Pushover notifications channel for Laravel

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to send Pushover notifications with Laravel Notifications.

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/pushover

Setting up your Pushover account

To start sending messages via Pushover, you have to register an application. Add the generated Pushover application token to the services config file:

// config/services.php
'pushover' => [
    'token' => 'YOUR_APPLICATION_TOKEN',
],

Usage

Now you can use the channel in your via() method inside the notification as well as send a push notification:

use NotificationChannels\Pushover\PushoverChannel;
use NotificationChannels\Pushover\PushoverMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [PushoverChannel::class];
    }

    public function toPushover($notifiable)
    {
        return PushoverMessage::create('The invoice has been paid.')
            ->title('Invoice paid')
            ->sound('incoming')
            ->lowPriority()
            ->url('http://example.com/invoices', 'Go to your invoices');
    }
}

To send Pushover notifications to the notifiable entity, add the routeNotificationForPushover method to that model. Usually, this is the User model. The pushover_key could be a database field and editable by the user itself.

public function routeNotificationForPushover()
{
    return $this->pushover_key;
}

Advanced usage and configuration

If you want to specify specific devices, you can return a PushoverReceiver object.

public function routeNotificationForPushover() {
    return PushoverReceiver::withUserKey('pushover-key')
        ->toDevice('iphone')
        ->toDevice('desktop')
        // or, if you prefer:
        ->toDevice(['iphone', 'desktop']);
}

If you want to (dynamically) overrule the application token from the services config, e.g. because each user holds their own application token, return a PushoverReceiver object like this:

public function routeNotificationForPushover() {
    return PushoverReceiver::withUserKey('pushover-key')
        ->withApplicationToken('app-token');
}

You can also send a message to a Pushover group:

public function routeNotificationForPushover() {
    return PushoverReceiver::withGroupKey('pushover-group-key');
}

Available Message methods

Method Description
content($message) Accepts a string value for the message text.
html() Sets the message type to HTML.
monospace() Sets the message type to monospace.
plain() Sets the message type to plain text, this is the default.
title($title) Accepts a string value for the message title.
time($timestamp) Accepts either a Carbon object or a UNIX timestamp.
url($url[, $title]) Accepts a string value for a supplementary url and an optional string value for the title of the url.
sound($sound) Accepts a string value for the notification sound.
image($image) Accepts a string value for the image location (either full or relative server path or a URL). If there is any error with the file (too big, not an image) it will silently send the message without the image attachment.
priority($priority[, $retryTimeout, $expireAfter]) Accepts an integer value for the priority and, when the priority is set to emergency, also an integer value for the retry timeout and expiry time (in seconds). Priority values are available as constants
lowestPriority() Sets the priority to the lowest priority.
lowPriority() Sets the priority to low.
normalPriority() Sets the priority to normal.
highPriority() Sets the priority to high.
emergencyPriority($retryTimeout, $expireAfter) Sets the priority to emergency and accepts integer values for the retry timeout and expiry time (in seconds).

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] 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.

pushover's People

Contributors

atymic avatar boryn avatar cannonb4ll avatar casperboone avatar cmdrsharp avatar dyusha avatar freekmurze avatar hxnk avatar kapersoft avatar kovah avatar laravel-shift avatar mpociot avatar oyed avatar samuelnitsche avatar styxit avatar themsaid avatar vmitchell85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pushover's Issues

Laravel 9 Support

Laravel 9 has been released and we need to update this repo to support it.

Can't get this to work

My application doesn't throw errors, the e-mail is sent but I do not get a push notification on my phone. I can't find any logs anywhere, how should I proceed to fix this?

User.php (Added at the end of file)

    public function routeNotificationForPushover()
    {
        return env('PUSHOVER_USERKEY');
    }

App/Notifications/PaymentCompleted.php

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Pushover\PushoverChannel;
use NotificationChannels\Pushover\PushoverMessage;

class PaymentCompleted extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public function __construct()
    {
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     *
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail', PushoverChannel::class];
    }

    /**
     * Get the Pushover representation of the notification.
     *
     * @param mixed $notifiable
     *
     * @return \NotificationChannels\Pushover\PushoverMessage
     */
    public function toPushover($notifiable)
    {
        return PushoverMessage::create('The invoice has been paid.')
             ->title('Payments')
             ->sound('incoming')
             ->normalPriority();
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     *
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage())
                    ->greeting('Hello!')
                    ->line('Your payment has been successfully processed.')
                    ->action('View account', 'https://DOMAIN/profile')
                    ->line('tetstststststetst!');
    }
}

App/Http/Controllers/BlablaController.php

    public function notify()
    {
        $user = User::find(1);
        $user->notify(new PaymentCompleted());
    }

Cannot send a notification?

Hello,

I'm attempting to send a Pushover notification from a test route just to ensure I'm happy with the formatting.

$user = GrimeArchive\User::first();

\NotificationChannels\Pushover\PushoverMessage::create($user->name . ' registered for Grime Archive')
        ->title('New user registration: Grime Archive')
        ->sound('incoming')
        ->lowPriority()
        ->url(route('users.show', $user), 'Visit Profile');

dd('notified');

Simply getting the first user, and sending a message as per the documentation.

I've installed, added the service provided to my config/app.php and configured my token in config/serivces.php;

'pushover' => [
    'token' => env('PUSHOVER_TOKEN'), // this is obviously in my .env file
],

I've triple checked everything - I think I've got everything set up correctly but I'm not receiving any notifications at all (to neither of my 3 devices I have registered on Pushover).

I also don't receive any errors when I hit my test route, I see notified dd()'d as per my example above.

Hope you can help :)

Support for on-demand notofications?

Hi there! I am pretty new to Laravel Notifications so I may also have missed a point.

I saw that notifications can be sent on-demand and wanted to do this in my application with the Pushover channel. Thing is, that I do want to send myself a notification; a single user token is supplied via the .env file as I do not want to store one single key in the database or somewhere else.

So, I thought I could just do something like

Notification::route('pushover', config('services.pushover.user_token'))
    ->notify(new SomePushoverNotification($text, $message, $priority));

but I get the following error:

Illuminate\Contracts\Container\BindingResolutionException:
Unresolvable dependency resolving [Parameter #1 [ <required> $token ]] in class NotificationChannels\Pushover\Pushover

Sound like the token is not being handed to the Pushover Channel or something?

However, using the Pushover channel for the laravel-backup package works fine, which uses a custom notifiable class that has just a routeNotificationForPushover method:

public function routeNotificationForPushover()
{
    return PushoverReceiver::withUserKey(config('services.pushover.user_token'));
}

What am I doing wrong? :/

Laravel 5.8 support

Support should be added for Laravel 5.8. If no one else can, I'll try to take a look at it when I can find the time.

[Laravel 8] Issue with Guzzle dependency

Hi there!

Laravel requires Guzzle 7, but this package requires Guzzle 6. This is preventing me from updating to Laravel 8:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel-notification-channels/pushover ^2.1 -> satisfiable by laravel-notification-channels/pushover[2.1.0, 2.1.1, 2.1.2].
    - Can only install one of: guzzlehttp/guzzle[7.0.1, 6.5.x-dev].
    - Can only install one of: guzzlehttp/guzzle[7.0.x-dev, 6.5.x-dev].
    - Can only install one of: guzzlehttp/guzzle[7.1.x-dev, 6.5.x-dev].
    - Conclusion: install guzzlehttp/guzzle 6.5.x-dev
    - Installation request for guzzlehttp/guzzle ^7.0.1 -> satisfiable by guzzlehttp/guzzle[7.0.1, 7.0.x-dev, 7.1.x-dev].

I noticed the Laravel 8 PR has been merged without updating Guzzle.

Might I ask why Guzzle is still on 6?

How to debug Pushover?

Hi, I'm deploying my project from homestead on Ubuntu 16.04, ngnix, php7. Everything is working correct, but pushover doesn't send notifications. On local homestead server everything works. Please help me to solve this problem.

This is my Route:

Route::get('n', function () {
    $user = App\User::first();
    $bid = App\Bid::first();
    $user->notify(new NewBid($bid));
});

This is my Push:

namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Pushover\PushoverChannel;
use NotificationChannels\Pushover\PushoverMessage;
class NewBid extends Notification implements ShouldQueue
{
    use Queueable;

    protected $bid;

    public function __construct($bid)
    {
         $this->bid = $bid;
    }
    public function via($notifiable)
    {
        return [PushoverChannel::class];
    }
    public function toPushover($notifiable)
    {
        return PushoverMessage::create($this->bid->name .' โ„– ' .$this->bid->phone)
            ->title('example.com')
            ->sound('incoming')
            ->normalPriority()
            ->url('http://example.com/invoices', 'Go to Link');
    }
}

This is from my config/services.php:

    'pushover' => [
        'token' => 'Here I'm using my token for application',
    ],

Please help!

Driver [NotificationChannels\Pushover\PushoverChannel] not supported

Hi,

Upgraded to Laravel 6 a while ago and suddenly noticed my notifications arent working. I cannot figure out why. The classes are imported in my Notificaton:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Pushover\PushoverChannel;
use NotificationChannels\Pushover\PushoverMessage;

class PaymentCompleted extends Notification implements ShouldQueue

Error:
Driver [NotificationChannels\Pushover\PushoverChannel] not supported.

I can't figure out why the hell it's throwing this error suddenly. Any ideas?

Dependency issue in Laravel 5.8

I'm using Laravel 5.8 and the installation fails:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove symfony/translation v4.3.3
    - Conclusion: don't install symfony/translation v4.3.3
    - .............................

Please help.

Send Multiple Push Notifications

I'm in need of a way to send multiple notifications for a single notifiable. I am familiar with Group notifications but that will not work for my use case.

I've accomplished this by making some modifications to the PushoverChannel@send method but I'm not too good with writing tests (Still working through Adam's Test Driven Laravel).

Basically I'm converting the routeNotificationFor response to an array and then looping over them and sending a notification to each one. The details section below shows the code for the send method.

I wasn't sure if I should create a PR, since it wouldn't have tests.

Thanks for taking a look.

public function send($notifiable, Notification $notification)
    {
        if (! $pushoverReceivers = $notifiable->routeNotificationFor('pushover')) {
            return;
        }

        $pushoverReceivers = is_array($pushoverReceivers) ? $pushoverReceivers : [$pushoverReceivers];

        foreach( $pushoverReceivers as $pushoverReceiver ){
            if (is_string($pushoverReceiver)) {
                $pushoverReceiver = PushoverReceiver::withUserKey($pushoverReceiver);
            }

            $message = $notification->toPushover($notifiable);

            try {
                $this->pushover->send(array_merge($message->toArray(), $pushoverReceiver->toArray()));
            } catch (ServiceCommunicationError $serviceCommunicationError) {
                $this->fireFailedEvent($notifiable, $notification, $serviceCommunicationError->getMessage());
            }
        }

    }

Laravel 10 Support

Laravel 10 has recently been released, it would be great if this package could be updated to support this. Note that we appear to currently have no support for Laravel 9.:(

Wrong version installed

When running composer require laravel-notification-channels/pushover version 1.1.0 gets installed which does not support Laravel 5.5

The latest release which does support Laravel 5.5 has a lower version (1.0.2). Manually installing this version does off course works. Probably something went wrong naming this release.

Illuminate\Events\Dispatcher::fire() error, removed in Laravel 5.8?

In src/PushoverChannel.php the $this->events->fire() call seems to have been deprecated and removed in Laravel 5.8.

Not sure if it was added later again at some point, as this package I think was working in a Laravel 7.x app, but it is currently failing with laravel Method Illuminate\Events\Dispatcher::fire does not exist. in 7.25.0 at least.

Not sure if there is any reason not to change this to dispatch(), since older 5.x appears to longer be supported. The change done manually works for me at the moment.

Removal Reference: laravel/framework#26392

Thanks!

toArray error and not using the token

According to the api docs you must send both the user and the token parameters. https://pushover.net/api

This code only appears to require the token which is then past as the user parameter.

If I change my routeNotificationForPushover to

public function routeNotificationForPushover() { return ['user' => $this->pushover_user, 'token' => $this->pushover_token]; }

It does appear to put the correct params into the url that is past to pushover. However doing this then gives me the error

FatalThrowableError in PushoverChannel.php line 50: Call to a member function toArray() on array

I have an empty to array function on the notification call which appears not to get used. The code looks for toArray on the PushoverChannel class.

Laravel 5.4

Are you planning to release this for Laravel 5.4?

Tag Laravel 7 release

Hi,

Can you please tag a release on the newest laravel version? I'm currently using dev-master but prefer to have versions.

Composer: but these conflict with your requirements or minimum-stability.

Using Laravel 5.8 I get this when trying to install:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel-notification-channels/pushover 1.2.3 requires nesbot/carbon ^1.21 -> satisfiable by nesbot/carbon[1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4] but these conflict with your requirements or minimum-stability.
    - laravel-notification-channels/pushover 1.2.2 requires nesbot/carbon ^1.21 -> satisfiable by nesbot/carbon[1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4] but these conflict with your requirements or minimum-stability.
    - laravel-notification-channels/pushover 1.2.1 requires nesbot/carbon ^1.21 -> satisfiable by nesbot/carbon[1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4] but these conflict with your requirements or minimum-stability.
    - laravel-notification-channels/pushover 1.2.0 requires nesbot/carbon ^1.21 -> satisfiable by nesbot/carbon[1.21.0, 1.22.0, 1.22.1, 1.23.0, 1.24.0, 1.24.1, 1.24.2, 1.25.0, 1.25.1, 1.25.3, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.26.6, 1.27.0, 1.28.0, 1.29.0, 1.29.1, 1.29.2, 1.30.0, 1.31.0, 1.31.1, 1.32.0, 1.33.0, 1.34.0, 1.34.1, 1.34.2, 1.34.3, 1.34.4, 1.35.0, 1.35.1, 1.36.0, 1.36.1, 1.36.2, 1.37.0, 1.37.1, 1.38.0, 1.38.1, 1.38.2, 1.38.3, 1.38.4] but these conflict with your requirements or minimum-stability.
    - Installation request for laravel-notification-channels/pushover ^1.2 -> satisfiable by laravel-notification-channels/pushover[1.2.0, 1.2.1, 1.2.2, 1.2.3].


Installation failed, reverting ./composer.json to its original content.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.