# BearyChat notifications channel for Laravel

Latest Version on Packagist (opens new window) Software License (opens new window) Build Status (opens new window) StyleCI (opens new window) SensioLabsInsight (opens new window) Quality Score (opens new window) Code Coverage (opens new window) Total Downloads (opens new window)

This package makes it easy to send notifications using BearyChat (opens new window) with Laravel.

# Channel Deprecated

BearyChat was discontinued. As such, this channel will no longer receive updates and is being deprecated.

# Contents

# Installation

You can install the package via Composer (opens new window):

$ composer require laravel-notification-channels/bearychat

Once the package is installed, you need to register the service provider by adding the following to the providers array in config/app.php:

ElfSundae\BearyChat\Laravel\ServiceProvider::class,

This package is based on laravel-bearychat (opens new window), you may publish the config file if you have not done yet:

$ php artisan vendor:publish --tag=bearychat

# Setting up the BearyChat service

You may create an Incoming Robot in your BearyChat (opens new window) team account, and read the payload format (opens new window).

# Usage

# Basic Usage

You can now use the channel in the via() method inside the Notification class.

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use NotificationChannels\BearyChat\BearyChatChannel;
use ElfSundae\BearyChat\Message;

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

    public function toBearyChat($notifiable)
    {
        return (new Message)
            ->text('foo')
            ->add('bar');
    }
}

You can also use a BearyChat Client to create the message for notification, and the client's message defaults will be used for creating this new Message instance.

public function toBearyChat($notifiable)
{
    return bearychat('admin')->text('New VIP has been paid!');
}

# Routing Notifications

To route BearyChat notifications to the proper Robot, define a routeNotificationForBearyChat method on your notifiable entity.

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForBearyChat()
    {
        return 'https://hook.bearychat.com/...';
    }
}

You can also route the user, channel or configured client in the routeNotificationForBearyChat method.

  • '@Elf' will route the notification to user "Elf".
  • '#iOS-Dev' will route the notification to channel "iOS-Dev".
  • 'http://webhook/url' will route the notification to an Incoming Robot.
  • 'Server' will route the notification via a client which named "Server" in your config file config/bearychat.php, and the message defaults of this client will be applied to the outgoing notification message.

# Available Message Methods

  • text() : (string) Message content.
  • notification() : (string) Message notification.
  • markdown(true) : (boolean) Indicates the message should be parsed as markdown syntax.
  • add() : (mixed) Add an attachment to the message. The parameter can be an payload array that contains all of attachment's fields. The parameters can also be attachment's fields that in order of "text", "title", "images" and "color".
  • addImage() : ($image, $desc = null, $title = null) Add an image attachment to the message.
  • content() : ($text, $markdown, $notification) or ($text, $attachment_text, $attachment_title, $attachment_images, $attachment_color).
  • remove() : (mixed) Remove attachment(s), you can pass an integer of attachment index, or an array of indices.
  • channel() : (string) The channel that the message should be sent to.
  • user() : (string) The user that the message should be sent to.
  • to() : (string) The target (user or channel) that the message should be sent to. The target may be started with "@" for sending to an user, and the channel's starter mark "#" is optional.
$message = (new Message)
    ->text('message content')
    ->notification('notification for this message')
    ->add('attachment content', 'attachment title', 'http://path/to/image', '#FF0000')
    ->to('@Boss');

A notification uses the above Message instance will be sent with the following payload:

{
    "text": "message content",
    "notification": "notification for this message",
    "user": "Boss",
    "attachments": [
        {
            "text": "attachment content",
            "title": "attachment title",
            "images": [
                {
                    "url": "http://path/to/image"
                }
            ],
            "color": "#FF0000"
        }
    ]
}

# Changelog

Please see CHANGELOG (opens new window) for more information what has changed recently.

# Testing

$ composer test

# Security

If you discover any security related issues, please email elf.sundae@gmail.com instead of using the issue tracker.

# Contributing

Please see CONTRIBUTING (opens new window) for details.

# Credits

# License

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