t1l3/slack-notifier-bundle

A simple wrapper for Slack notifications

0.1 2014-05-22 14:30 UTC

This package is auto-updated.

Last update: 2024-04-06 08:29:54 UTC


README

A simple wrapper for polem/slack-notifier to send Slack notifications.

Installation

Download T1l3SlackNotifier using composer

Add T1l3SlackNotifier in your composer.json:

{
    "require": {
        "t1l3/slack-notifier-bundle": "0.1"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update t1l3/slack-notifier-bundle

Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new T1l3\SlackNotifierBundle\T1l3SlackNotifierBundle(),
    );
}

Configure T1l3SlackNotifier

First you need to create an incoming-webhook in Slack to get your token. You can also set default Bot name and icon in the Integration Settings part.

Then add it to your config.yml

# app/config/config.yml
t1l3_slack_notifier:
    team: yourteam
    token: yOurT0ken

Usage

You just have to call t1l3_slack_notifier service and add a Slack\Message\Message to the notify method.

Here is a simple exemple of using it in a controller.

<?php

namespace Acme\DemoBundle\Controller;

// ...
use Slack\Message\Message;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $message = new Message('Hello World!');
        $message->setChannel('#your-chanel')
        ->setIconEmoji(':princess:')
        ->setUsername('Bot')
        ;

        $slackNotifier = $this->get('t1l3_slack_notifier');
        $slackNotifier->notify($message);

        // ...
    }
}