Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

cybercog/laravel-notification-channel-rocket-chat

Repository files navigation

cog-laravel-notification-rocket-chat

Rocket.Chat notifications channel for Laravel 5.3+

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

WIP

Don't use it on production. It's initial release. Stable version will be available at https://github.com/laravel-notification-channels/rocket-chat

Introduction

This package makes it easy to send notifications using RocketChat with Laravel 5.3.

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/rocket-chat

You must install the service provider:

// config/app.php
'providers' => [
    ...
    NotificationChannels\RocketChat\RocketChatServiceProvider::class,
],

Setting up the RocketChat service

In order to send message to RocketChat channels, you need to obtain Webhook.

Add your RocketChat API server's base url, incoming Webhook Token and optionally the default room to your config/services.php:

// config/services.php
...
'rocketchat' => [
     // Base URL for RocketChat API server (https://your.rocketchat.server.com)
    'url' => env('ROCKETCHAT_URL'),
    'token' => env('ROCKETCHAT_TOKEN'),
    // Default room (optional)
    'room' => env('ROCKETCHAT_ROOM'),
],
...

Usage

You can use the channel in your via() method inside the notification:

use Illuminate\Notifications\Notification;
use NotificationChannels\RocketChat\RocketChatMessage;
use NotificationChannels\RocketChat\RocketChatChannel;

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

    public function toRocketChat($notifiable)
    {
        return RocketChatMessage::create("Test message")
            ->to('room_id') // optional if set in config
            ->from('webhook_token'); // optional if set in config
    }
}

In order to let your notification know which RocketChat room you are targeting, add the routeNotificationForRocketChat method to your Notifiable model:

public function routeNotificationForRocketChat()
{
    return 'room_id';
}

Available methods

from(): Sets the sender's access token.

to(): Specifies the room id to send the notification to (overridden by routeNotificationForRocketChat if empty).

content(): Sets a content of the notification message. Supports Github flavoured markdown.

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

Change log

Please see CHANGELOG for more information on what has changed recently.

License

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

About CyberCog

CyberCog is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion.

cybercog-logo