2017 © Pedro Peláez
 

library hipchat

HipChat Notifications Channel for Laravel

image

laravel-notification-channels/hipchat

HipChat Notifications Channel for Laravel

  • Friday, July 6, 2018
  • by laravel-notification-channels
  • Repository
  • 5 Watchers
  • 16 Stars
  • 21,040 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 1 Open issues
  • 10 Versions
  • 12 % Grown

The README.md

HipChat Notifications Channel for Laravel

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads, (*1)

This package makes it easy to send HipChat notifications with Laravel., (*2)

Channel Deprecated

Hipchat was discontinued in early 2019. As such, this channel will no longer receive updates and is being deprecated., (*3)

Contents

Installation

You can install the package via composer:, (*4)

``` bash composer require laravel-notification-channels/hipchat, (*5)


If you're using Laravel < 5.5 or if you have package auto-discovery turned off you have to manually register the service provider: ```php // config/app.php 'providers' => [ ... NotificationChannels\HipChat\HipChatServiceProvider::class, ],

Setting up the HipChat service

Add your HipChat Account Token and optionally the default room and Hipchat API server's base url to your config/services.php:, (*6)

// 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',
],
...

Usage

Sending a simple room notification

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., (*7)

``` php use NotificationChannels\HipChat\HipChatChannel; use NotificationChannels\HipChat\HipChatMessage; use Illuminate\Notifications\Notification;, (*8)

class UserRegistered extends Notification { public function via($notifiable) { return [HipChatChannel::class]; }, (*9)

public function toHipChat($notifiable)
{
    return HipChatMessage::create()
        ->room('New Registrations')
        ->html("<strong>A new user has registered!</strong>")
        ->success()
        ->notify();
}

}, (*10)


### Sending a room notification with a card Read more about HipChat notification cards [here](https://developer.atlassian.com/hipchat/guide/sending-messages#SendingMessages-UsingCards). ```php public function toHipChat($notifiable) { return HipChatMessage::create() ->text('Laravel 5.3 has arrived!') ->notify(true) ->card(Card::create() ->title('Laravel') ->style(CardStyles::APPLICATION) ->url('http://laravel.com') ->html('Laravel 5.3 has arrived! The best release ever!') ->cardFormat(CardFormats::MEDIUM) ->icon('http://bit.ly/2c7ntiF') ->activity('Laravel 5.3 has arrived!', 'http://bit.ly/2c7ntiF') ->addAttribute(CardAttribute::create() ->label('Laravel Scout') ->icon('http://bit.ly/2c7ntiF') ->value('Driver based full-text search.') ->url('https://laravel.com/docs/5.3/scout') ) ->addAttribute(CardAttribute::create() ->label('Laravel Echo') ->icon('http://bit.ly/2c7ntiF') ->value('Event broadcasting, evolved.') ->url('https://laravel.com/docs/5.3/broadcasting') ) ->addAttribute(CardAttribute::create() ->label('Laravel Passport') ->icon('http://bit.ly/2c7ntiF') ->value('API authentication.') ->url('https://laravel.com/docs/5.3/passport') ) ); }

Sharing a file in a HipChat room

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., (*11)

In majority of cases all you need is just a path to an exisiting file you want to share, (*12)

``` php public function toHipChat($notifiable) { return HipChatFile::create($this->user->photo); }, (*13)


You can optionally send a text message along the way ``` php public function toHipChat($notifiable) { return 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, (*14)

``` php public function toHipChat($notifiable) { return 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!"); }, (*15)


### Available methods #### `HipChatMessage` - `create()`: Creates a new `HipChatMessage` instance. - `room()`: Sets the id or name of the HipChat room to send the notification to. - `from()`: Sets the optional label to be shown in addition to the sender's name. - `content()`: Sets the 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 of the message. See `MessageColors` for allowec values. - `notify()`: Specifies if a message should trigger a user notification in a Hipchat client. - `info()`: Sets notification level to `info` and color to `MessageColors::GRAY`. - `success()`: Sets notification level to `success` and color to `MessageColors::GREEN`. - `error()`: Sets notification level to `info` and color to `MessageColors::RED`. #### `Card` - `create()`: Creates a new `Card` instance. - `title()`: Sets the title of the card. - `id()`: Sets the id of the card. - `style()`: Sets the style of the card. See `CardStyles` for allowed values. - `text()`: Sets the format to plain text and optionally the content. - `html()`: Sets the format to html and optionally the content. - `cardFormat()`: Sets the format of the card. See `CardFormats` for allowed values. - `url()`: Sets the url of the card. - `thumbnail()`: Sets the thumbnail of the card. - `activity()`: Sets the activity info of the card. - `icon()`: Sets the icon of the card. - `addAttribute()`: Adds a `CardAttribute` to the card. #### `CardAttribute` - `create()`: Creates a new `CardAttribute` instance. - `value()`: Sets the textual value of the attribute. - `label()`: Sets the label of the attribute. - `url()`: Sets the url of the attribute. - `style()`: Sets the style of the attribute. See `CardAttributeStyles` for allowed values. - `icon()`: Sets the icon of the attribute. #### `HipChatFile` - `create()`: Creates a new `HipChatFile` instance. - `room()`: Sets the id or name of the HipChat room to share the file in. - `path()`: Sets the `fileContent` to the resource of the existing file and tries to detect and set the `fileName` and `fileType` 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 the `fileType` 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. ## Testing ``` bash $ composer test

Security

If you discover any security related issues, please email pmatseykanets@gmail.com instead of using the issue tracker., (*16)

Changelog

Please see CHANGELOG for more information what has changed recently., (*17)

Contributing

Please see CONTRIBUTING for details., (*18)

Credits

Special thanks to Jerry Price for his help., (*19)

License

The MIT License (MIT). Please see License File for more information., (*20)

The Versions