Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
DZunke committed Sep 16, 2014
2 parents e8a698e + 3a25122 commit dd70e9e
Show file tree
Hide file tree
Showing 27 changed files with 435 additions and 147 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SlackBundle v1.1.0
==================
- Feature: Added Provider for Silex-Integration
- Feature: Added Attachments to the Messaging-Methods
- (NOT BC) Refactor: Identities are only needed for Chat, so no general use is needed

SlackBundle v1.0.0
==================
- Initial Release
2 changes: 1 addition & 1 deletion Monolog/Handler/SlackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(Messaging $messaging, $channel, $username, $level =
$this->channel = $channel;
$this->username = $username;

if (!$this->messagingClient->getClient()->getIdentityBag()->has($username)) {
if (!$this->messagingClient->getIdentityBag()->has($username)) {
throw new \InvalidArgumentException('Invalid Username given');
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Dependency Status](https://www.versioneye.com/user/projects/53f7cb30e09da3d0bf00047b/badge.svg)](https://www.versioneye.com/user/projects/53f7cb30e09da3d0bf00047b) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/12c02e49-a1a8-42f7-a213-71d4288fc75d/mini.png)](https://insight.sensiolabs.com/projects/12c02e49-a1a8-42f7-a213-71d4288fc75d) [![Latest Unstable Version](https://poser.pugx.org/dzunke/slack-bundle/v/unstable.svg)](https://packagist.org/packages/dzunke/slack-bundle) [![Latest Stable Version](https://poser.pugx.org/dzunke/slack-bundle/v/stable.svg)](https://packagist.org/packages/dzunke/slack-bundle)

The Bundle will integrate [Slack](https://slack.com/) Team-Communication-Software into your Symfony2 Project and in the Feature deliver a set of Project-Management-Tools to use between your Symfony-Project and Slack.
The Bundle will integrate [Slack](https://slack.com/) Team-Communication-Software into your Symfony2 Project and in the future will deliver a set of Project-Management-Tools to use between your Symfony-Project and Slack.

## Documentation

Expand Down
6 changes: 2 additions & 4 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
services:

dz.slack.identity_bag:
class: DZunke\SlackBundle\Slack\Client\IdentityBag
class: DZunke\SlackBundle\Slack\Messaging\IdentityBag

dz.slack.connection:
class: DZunke\SlackBundle\Slack\Client\Connection

dz.slack.client:
class: DZunke\SlackBundle\Slack\Client
arguments: [@dz.slack.connection]
calls:
- [setIdentityBag, [@dz.slack.identity_bag]]

dz.slack.messaging:
class: DZunke\SlackBundle\Slack\Messaging
arguments: [@dz.slack.client]
arguments: [@dz.slack.client, @dz.slack.identity_bag]

dz.slack.channels:
class: DZunke\SlackBundle\Slack\Channels
Expand Down
3 changes: 3 additions & 0 deletions Resources/doc/actions-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ Available Parameters:

``` php
protected $parameter = [
'identity' => null, # Object of Class \DZunke\SlackBundle\Slack\Messaging\Identity
'channel' => null,
'text' => null,
'icon_url' => null,
'icon_emoji' => null,
'parse' => 'full',
'link_names' => 1,
'unfurl_links' => 1
Expand Down
8 changes: 2 additions & 6 deletions Resources/doc/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ $identity = new \DZunke\SlackBundle\Slack\Client\Identity();
$identity->setUsername('CoffeeBrewer');
$identity->setIconEmoji(':coffee:');

$identityBag = new \DZunke\SlackBundle\Slack\Client\IdentityBag();
$identityBag->addIdentity($identity);

$connection = new \DZunke\SlackBundle\Slack\Client\Connection();
$connection->setEndpoint('slack.com/api/');
$connection->setToken('YOUR API TOKEN');

$client = new \DZunke\SlackBundle\Slack\Client($connection);
$client->setIdentityBag($identityBag);

$response = $client->send(
\DZunke\SlackBundle\Slack\Client\Actions::ACTION_POST_MESSAGE,
[
'identity => $identity
'channel' => '#slack-testing',
'text' => 'Good Morning, please make sure u got a coffee before working!'
],
'CoffeeBrewer'
]
);
```
4 changes: 3 additions & 1 deletion Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
7. [Commands](commands.md)
8. [Monolog Integration](monolog.md)

9. [Help for Slack](slack.md)
9. [Silex Integration](silex.md)

10. [Help for Slack](slack.md)
11 changes: 7 additions & 4 deletions Resources/doc/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

To view a bit into the future there are some ideas for features and the will to implement them. The long term Target is to create a Set of Project-Management Features to make the daily work easier and use the full capacity of the gorgeous Slack-System.

* Update ChatMessage for ProgressBars etc.
* Upload File for automatic Reportings
* Reading E-Mails from an Account (maybe olny for slack-client)
* Sending E-Mails for daily reports of team members in an channel and post the awnsers
* Upload Files
* Connectors for extern Tools to fetch Data and post them (maybe with a cache to only get updated content)
* "iDoneThis" for Slack-Chat (Checking if it is possible with the API)


The following Features could not be implemented yet because of problems with the API of Slack.

* Update ChatMessage for ProgressBars etc.
16 changes: 16 additions & 0 deletions Resources/doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ $response = $container->get('dz.slack.messaging')->message(
);
```

There is also a way to use the "Attachment"-Feature of Slack. In this Case there will be a multi-column part below the Message.
For this you must create deliver an Array of Attachments to the Message-Method.

``` php
$attachment = new Attachment();
$attachment->setColor('danger');
$attachment->addField('Test1', 'Test works');

$response = $container->get('dz.slack.messaging')->message(
'#foo-channel',
'Good Morning, please make sure u got a coffee before working!',
'CoffeeBrewer',
[$attachment]
);
```

## Channels

There are some operations you can do for a Channel. It is necessary to get the ChannelId from the Slack-API before you
Expand Down
36 changes: 36 additions & 0 deletions Resources/doc/silex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Silex Integration

In the Bundle there is a SilexProvider you can use with your Silex-Application. There is no need to get an extra Package. The Provider delivers the following Extensions:

$app['dz.slack.connection'] # Slack/Client/Connection.php
$app['dz.slack.client'] # Slack/Client.php
$app['dz.slack.identity_bag'] # Slack/Messaging/IdentityBag.php
$app['dz.slack.messaging'] # Slack/Messaging.php

To configure the SlackBundle in Silex there is the need to set some Configuration-Values

``` php
$app['dz.slack.options'] = [
'token' => 'YOUR TOKEN HERE,
'identities' => [
'YOUR IDENTITIY' => []
],
'logging' => [
'enabled' => true,
'channel' => 'YOUR CHANNEL TO LOG TO',
'identity' => 'THE IDENTITY TO LOG WITH'
]
];
```

Wit these Options set you can load the Provider in your index

``` php
$app->register(new DZunke\SlackBundle\Silex\Provider\SlackServiceProvider());
```

## Monolog Integration

If you want to integrate the SlackHandler to an Instance of Monolog be sure the logging is enabled in the config. In that case the Provider will try to add the Handler to the default Logger ```$app['monolog']```. It will use the same LogLevel as the default Logger.

Be sure that the MonologProvider is handled before!
8 changes: 4 additions & 4 deletions Resources/doc/symfony-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public function messageAction()
$response = $client->send(
\DZunke\SlackBundle\Slack\Client\Actions::ACTION_POST_MESSAGE,
[
'channel' => '#slack-testing',
'text' => 'Good Morning, please make sure u got a coffee before working!'
],
'CoffeeBrewer'
'identity' => $this->get('dz.slack.identity_bag')->get('CoffeeBrewer'),
'channel' => '#slack-testing',
'text' => 'Good Morning, please make sure u got a coffee before working!'
]
);
}
```
94 changes: 94 additions & 0 deletions Silex/Provider/SlackServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace DZunke\SlackBundle\Silex\Provider;

use DZunke\SlackBundle\Monolog\Handler\SlackHandler;
use DZunke\SlackBundle\Slack\Client;
use DZunke\SlackBundle\Slack\Messaging;
use Silex\Application;
use Silex\Provider\MonologServiceProvider;
use Silex\ServiceProviderInterface;

class SlackServiceProvider implements ServiceProviderInterface
{

public function register(Application $app)
{
$default_options = [
'endpoint' => 'slack.com/api/',
'token' => null,
'limit_retries' => 5,
'identities' => [
'Silex' => []
],
'logging' => [
'enabled' => false,
'channel' => '',
'identity' => ''
]
];

if (isset($app['dz.slack.options'])) {
$app['dz.slack.options'] = array_merge($default_options, $app['dz.slack.options']);
} else {
$app['dz.slack.options'] = $default_options;
}

$app['dz.slack.identity_bag'] = $app->share(
function ($app) {
$identityBag = new Messaging\IdentityBag();
$identityBag->createIdentities($app['dz.slack.options']['identities']);

return $identityBag;
}
);

$app['dz.slack.connection'] = $app->share(
function ($app) {
$connection = new Client\Connection();
$connection->setEndpoint($app['dz.slack.options']['endpoint']);
$connection->setLimitRetries($app['dz.slack.options']['limit_retries']);
$connection->setToken($app['dz.slack.options']['token']);

return $connection;
}
);

$app['dz.slack.client'] = $app->share(
function ($app) {
return new Client($app['dz.slack.connection']);
}
);

$app['dz.slack.messaging'] = $app->share(
function ($app) {
return new Messaging($app['dz.slack.client'], $app['dz.slack.identity_bag']);
}
);

if ($app['dz.slack.options']['logging']['enabled']) {

$app['monolog.handler.slack'] = $app->share(
function ($app) {
$level = MonologServiceProvider::translateLevel($app['monolog.level']);

return new SlackHandler(
$app['dz.slack.messaging'],
$app['dz.slack.options']['logging']['channel'],
$app['dz.slack.options']['logging']['identity'],
$level
);
}
);

$app['monolog']->pushHandler($app['monolog.handler.slack']);

}
}

public function boot(Application $app)
{

}

}
6 changes: 3 additions & 3 deletions Slack/Channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getId($channelName)
}

/**
* @return Client\Response
* @return Client\Response|bool
*/
public function listAll()
{
Expand All @@ -61,7 +61,7 @@ public function listAll()

/**
* @param string $channel The Id of the Channel - NOT the Name. self::getId() if needed
* @return Client\Response
* @return Client\Response|bool
*/
public function info($channel)
{
Expand All @@ -76,7 +76,7 @@ public function info($channel)
/**
* @param string $channel The Id of the Channel - NOT the Name. self::getId() if needed
* @param string $topic
* @return $this|Client\Response
* @return $this|Client\Response|bool
*/
public function setTopic($channel, $topic)
{
Expand Down
37 changes: 4 additions & 33 deletions Slack/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DZunke\SlackBundle\Slack\Client\Actions;
use DZunke\SlackBundle\Slack\Client\Connection;
use DZunke\SlackBundle\Slack\Client\IdentityBag;
use DZunke\SlackBundle\Slack\Client\Response;
use Guzzle\Common\Event;
use Guzzle\Http\Client as GuzzleClient;
Expand All @@ -18,11 +17,6 @@ class Client
*/
protected $connection;

/**
* @var IdentityBag
*/
protected $identityBag;

/**
* @param Connection $connection
*/
Expand All @@ -31,41 +25,18 @@ public function __construct(Connection $connection)
$this->connection = $connection;
}

/**
* @param IdentityBag $identityBag
* @return $this
*/
public function setIdentityBag(IdentityBag $identityBag)
{
$this->identityBag = $identityBag;

return $this;
}

/**
* @return IdentityBag
*/
public function getIdentityBag()
{
return $this->identityBag;
}

/**
* @param string $action
* @param array $parameter
* @param null $identity
* @return Response
* @return Response|bool
*/
public function send($action, array $parameter, $identity = null)
public function send($action, array $parameter)
{
if (!is_null($identity) && is_string($identity) && $this->identityBag->has($identity)) {
$identity = $this->identityBag->get($identity);
if (!$this->connection->isValid()) {
return false;
}

$action = Actions::loadClass($action);
if (!is_null($identity)) {
$action->setIdentity($identity);
}
$action->setParameter($parameter);

$url = $this->buildRequestUrl(
Expand Down
8 changes: 0 additions & 8 deletions Slack/Client/Actions/ActionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace DZunke\SlackBundle\Slack\Client\Actions;

use DZunke\SlackBundle\Slack\Client\Identity;

interface ActionsInterface
{

Expand All @@ -18,12 +16,6 @@ public function getRenderedRequestParams();
*/
public function parseResponse(array $response);

/**
* @param Identity $config
* @return $this
*/
public function setIdentity(Identity $config);

/**
* @return string
*/
Expand Down
Loading

0 comments on commit dd70e9e

Please sign in to comment.