SlackMessenger
This bundle allows you to receive and publish messages from Slack mapped to Message
objects., (*1)
, (*2)
Extending
To receive messages you need to create an EventListener which will be listening to the event slack.message_received
, (*3)
Example:, (*4)
namespace PP\AwesomeBundle\EventListener;
use XTeam\SlackMessengerBundle\Event\MessageEvent;
class AwesomeWorkListener
{
public function doYourJob(MessageEvent $event)
{
$message = $event->getMessage();
/** Do the right job **/
}
}
And register this in services.yml
, (*5)
;PP/AwesomeBundle/Resources/config/service.yml
services:
pp_awesome.awesome.listener:
class: %pp_awesome.awesome.listener.class%
tags:
- { name: kernel.event_listener, event: slack.message_received, method: doYourJob }
Installation
Step 1: Composer require
``` bash
$ php composer.phar require xteam/slackmessengerbundle "dev-master", (*6)
### Step 2: Enable the bundle
Enable the bundle in the kernel:
``` php
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new XTeam\SlackMessengerBundle\XTeamSlackMessengerBundle(),
);
}
Step 3: Add options to parameters.yml
#app/config/parameters.yml
parameters:
# ...
slack.token: Your SLack token
Step 4: Add routes
#app/congig/routes.yml
x_team_slack_messenger:
resource: "@XTeamSlackMessengerBundle/Resources/config/routing.yml"
prefix: /
Notes
This bundle requires a Symfony in version higher or equal 2.7, (*7)
Usage example
curl -X POST --data 'token=XXXXXXXXXXXXXXXXXX&team_id=T0001&team_domain=example&channel_id=C2147483705&channel_name=test×tamp=1355517523.000005&user_id=U2147483697&user_name=Steve&text=googlebot: What is the air-speed velocity of an unladen swallow?&trigger_word=googlebot' http://localhost/app_dev.php/v1/message/post
curl -X POST --data 'token=XXXXXXXXXXXXXXXXXX&team_id=T0001&team_domain=example&channel_id=C2147483705&channel_name=test×tamp=1355517523.000005&user_id=U2147483697&user_name=Steve&text=googlebot: What is the air-speed velocity of an unladen swallow? /five <@U07E9557H> and <@U07HSHYAU>&trigger_word=googlebot' http://localhost/app_dev.php/v1/message/post