This package makes it easy to send HipChat notifications with Laravel 5.3.
You can install the package via composer:
composer require laravel-notification-channels/hipchat
You must install the service provider:
// config/app.php
'providers' => [
...
NotificationChannels\HipChat\HipChatProvider::class,
],
Add your HipChat Account Token and optionally the default room and Hipchat API server's base url to your config/services.php
:
// config/services.php
...
'hipchat' => [
'token' => env('HIPCHAT_TOKEN'),
// Default room (optional)
'room' => 'Notifications',
// Base URL for Hipchat API server (optional)
'url' => 'https://api.your.hipchat.server.com',
],
...
Note: In order to be able to send room notifications you would need an auth token (both personal and room tokens will work) with the send_notification scope.
use NotificationChannels\HipChat\HipChatChannel;
use NotificationChannels\HipChat\HipChatMessage;
use Illuminate\Notifications\Notification;
class UserRegistered extends Notification
{
public function via($notifiable)
{
return [HipChatChannel::class];
}
public function toHipChat($notifiable)
{
return new HipChatMessage::create()
->room('New Registrations')
->html("<strong>A new user has registered!</strong>")
->sucess()
->notify();
}
}
Note: In order to be able to share files you would need an auth token (i.e. personal token) with the send_message scope. You can create such token by visiting HipChat -> Account Setting -> API Access.
In majority of cases all you need is just a path to an exisiting file you want to share
public function toHipChat($notifiable)
{
return new HipChatFile::create($this->user->photo);
}
You can optionally send a text message along the way
public function toHipChat($notifiable)
{
return new HipChatFile::create($this->user->photo);
->text("Look we've got a new user!");
}
If you need more control and/or you're creating the content of the file on the fly
public function toHipChat($notifiable)
{
return new HipChatFile::create()
->fileName('user_photo.png')
->fileType('image/png')
->fileContent(fopen('http://example.com/user/photo/johndoe', 'r'))
->text("Look we've got a new user!");
}
room()
: Specifies the room (id or name) to send the notification to.from()
: Sets the optional label to be shown in addition to the sender's name.content()
: Sets a content of the notification message.text()
: Sets the format to plain text and optionally the content.html()
: Sets the format to html and optionally the content. Allowed HTML tags: a, b, i, strong, em, br, img, pre, code, lists, tables.color()
: Sets the color for the message. Allowed values: yellow, green, red, purple, gray, random.notify()
: Specifies if a message should trigger a user notification in a Hipchat client.info()
: Sets notification level toinfo
and color togray
.success()
: Sets notification level tosuccess
and color togreen
.error()
: Sets notification level toinfo
and color tored
.
room()
: Specifies the room (id or name) to share the file in.path()
: Sets thefileContent
to the resource of the existing file and tries to detect and set thefileName
andfileType
if they weren't explicitely set.fileName
: Sets the name of the file.fileContent
: Explicitely sets the content of the file. It can be a string, stream or a file resource. If a resource was passed it tries to detect and set thefileType
if it wasn't explicitely set.fileType
: Explicitely sets the content (mime) type of the file.text()
: Sets a text message to be sent along with the file.
$ composer test
If you discover any security related issues, please email pmatseykanets@gmail.com instead of using the issue tracker.
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
Special thanks to Jerry Price for his help.
The MIT License (MIT). Please see License File for more information.