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

Commit

Permalink
Merge dev for release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DZunke committed Nov 4, 2015
2 parents 88207a6 + 0219c2c commit aa56320
Show file tree
Hide file tree
Showing 24 changed files with 419 additions and 17 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
SlackBundle v1.3.0
==================
- Feature: File upload service now accepts an array of channels, string usage is deprecated
- Feature: Implement action to invite users to a channel
- Feature: Implement action and service to get details about users on the team
- Feature: Implement console command to read userdata from api
- Patch: File upload no longer need to lookup channel id due to api changes
- Patch: Set aliases for command names - old names with dzunke: prefix will be removed in the future!

SlackBundle v1.2.2
==================
- Patch: MessageAttachment support complete attachment-api (by @shimmi)
Expand Down
1 change: 1 addition & 0 deletions Command/BotMessagingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected function configure()
{
$this
->setName('dzunke:slack:run-bot')
->setAliases(['slack:run-bot'])
->setDescription('Running the Bot-User to a Channel')
->addArgument(
'channel',
Expand Down
1 change: 1 addition & 0 deletions Command/ChangeChannelsTopicCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function configure()
{
$this
->setName('dzunke:slack:channels:topic')
->setAliases(['slack:channels:topic'])
->setDescription('Changing the Topic of a Channel')
->addOption('discover', 'd', InputOption::VALUE_NONE, 'channel name is given, so discover the id')
->addArgument('channel', InputArgument::REQUIRED, 'an existing channel in your team to change the topic')
Expand Down
1 change: 1 addition & 0 deletions Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected function configure()
{
$this
->setName('dzunke:slack:debug')
->setAliases(['slack:debug'])
->setDescription('Gives some Debug Informations about the SlackBundle');
}

Expand Down
1 change: 1 addition & 0 deletions Command/MessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected function configure()
{
$this
->setName('dzunke:slack:message')
->setAliases(['slack:message'])
->setDescription('Sending a Message to a Channel or User')
->addArgument('channel', InputArgument::REQUIRED, 'an existing channel in your team to send to')
->addArgument('username', InputArgument::REQUIRED, 'an username from configured identities to send with')
Expand Down
75 changes: 75 additions & 0 deletions Command/UsersCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace DZunke\SlackBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UsersCommand extends ContainerAwareCommand
{

protected function configure()
{
$this
->setName('dzunke:slack:users')
->setAliases(['slack:users'])
->setDescription('work with the users of your team')
->addOption('only-active', 'a', InputOption::VALUE_NONE, 'lists only active users')
->addOption('only-deleted', 'd', InputOption::VALUE_NONE, 'lists only deleted users')
->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'get a single user');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$formatter = $this->getHelper('formatter');

try {
$api = $this->getContainer()->get('dz.slack.users');

if ($input->getOption('only-active')) {
$response = $api->getActiveUsers();
} elseif ($input->getOption('only-deleted')) {
$response = $api->getDeletedUsers();
} elseif ($input->getOption('user')) {
$response = $api->getUser($input->getOption('user'));

if (is_array($response)) {
$response = [$response['name'] => $response];
}
} else {
$response = $api->getUsers();
}

if (empty($response)) {
$output->writeln($formatter->formatBlock('✘ no data found', 'error'));
return;
}

array_walk(
$response,
function (&$row) {
foreach ($row as &$col) {
if (is_bool($col)) {
$col = $col ? 'true' : 'false';
}
}
}
);

$table = $this->getHelper('table');
$table->setHeaders(array_keys(reset($response)))->setRows($response);
$table->render($output);


} catch (\Exception $e) {
$output->writeln(
$formatter->formatBlock(
sprintf('✘ there was an error with your request: "%s"', $e->getMessage()),
'error'
)
);
}
}
}
4 changes: 4 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ services:
dz.slack.channels:
class: DZunke\SlackBundle\Slack\Channels
arguments: [@dz.slack.client]

dz.slack.users:
class: DZunke\SlackBundle\Slack\Users
arguments: [@dz.slack.client]
29 changes: 29 additions & 0 deletions Resources/doc/actions-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ protected $parameter = [
];
```

## channels.invite

[Slack Documentation](https://api.slack.com/methods/channels.invite)

Constant: \DZunke\SlackBundle\Slack\Client::ACTION_CHANNELS_INVITE

Available Parameters:

Both Parameters have to be the if of the entity and not the raw name

``` php
protected $parameter = [
'channel' => null,
'user' => null,
];
```

## channels.list

[Slack Documentation](https://api.slack.com/methods/channels.list)
Expand Down Expand Up @@ -105,3 +122,15 @@ protected $parameter = [
'channels' => null # If no Channel is given the File will be private to the API-User
];
```

## users.list

[Slack Documentation](https://api.slack.com/methods/users.list)

Constant: \DZunke\SlackBundle\Slack\Client::ACTION_USERS_LIST

``` php
protected $parameter = [
'presence' => 1
];
```
22 changes: 17 additions & 5 deletions Resources/doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@
Output of Debug Informations like Connection, Identities, Channels etc.

``` bash
php app/console dzunke:slack:debug
php app/console slack:debug
```

## Messaging

Sending a Message directly from Console

``` bash
php app/console dzunke:slack:message @fooUser BazUser "Lorem ipsum dolor sit amet .."
php app/console dzunke:slack:message "#FooChannel" BazUser "Lorem ipsum dolor sit amet .."
php app/console slack:message @fooUser BazUser "Lorem ipsum dolor sit amet .."
php app/console slack:message "#FooChannel" BazUser "Lorem ipsum dolor sit amet .."
```

## Switch Topic of a Channel

You can switch the Topic of a Channel

``` bash
php app/console dzunke:slack:channels:topic "C02GABTDT" "Lorem ipsum dolor sit amet .."
php app/console slack:channels:topic "C02GABTDT" "Lorem ipsum dolor sit amet .."

# If you don't have the ChannelId it must be discovered while processing
php app/console dzunke:slack:channels:topic "#foo-channel" "Lorem ipsum dolor sit amet .." -d
php app/console slack:channels:topic "#foo-channel" "Lorem ipsum dolor sit amet .." -d
```

## Read userdata from api

you will get a table of userdata.

``` bash
# Read all users from your team
php app/console slack:users

# Read a single user
php app/console slack:users --user=nameOfTheUser
```
22 changes: 22 additions & 0 deletions Resources/doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,25 @@ $service->info($channelId);
$service->setTopic($channelId, $newTopic);
```

## Users

To get more information about the users in your team there is a service to read user specific things. In lack of an
api method to load single users every method of the service will load the complete list of users in your team. Beware
of using this service without caching informations you often need.

``` php
$service = $container->get('dz.slack.users');

# get the list of all users in your team
$service->getUsers();

# get all users that are not deleted
$service->getActiveUsers();

# get all deleted users
$service->getDeletedUsers();

# get the id of a single user - needed for some actions
$service->getId($username);

```
2 changes: 1 addition & 1 deletion Slack/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(Connection $connection)
* @param array $parameter
* @return Response|bool
*/
public function send($action, array $parameter)
public function send($action, array $parameter = [])
{
if (!$this->connection->isValid()) {
return false;
Expand Down
6 changes: 5 additions & 1 deletion Slack/Client/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class Actions
const ACTION_AUTH_TEST = 'auth.test';
const ACTION_CHANNELS_SET_TOPIC = 'channels.setTopic';
const ACTION_CHANNELS_INFO = 'channels.info';
const ACTION_CHANNELS_INVITE = 'channels.invite';
const ACTION_CHANNELS_HISTORY = 'channels.history';
const ACTION_FILES_UPLOAD = 'files.upload';
const ACTION_USERS_LIST = 'users.list';

/**
* @var array
Expand All @@ -25,8 +27,10 @@ class Actions
self::ACTION_AUTH_TEST => 'AuthTest',
self::ACTION_CHANNELS_SET_TOPIC => 'ChannelsSetTopic',
self::ACTION_CHANNELS_INFO => 'ChannelsInfo',
self::ACTION_CHANNELS_INVITE => 'ChannelsInvite',
self::ACTION_CHANNELS_HISTORY => 'ChannelsHistory',
self::ACTION_FILES_UPLOAD => 'FilesUpload'
self::ACTION_FILES_UPLOAD => 'FilesUpload',
self::ACTION_USERS_LIST => 'UsersList'
];

/**
Expand Down
3 changes: 3 additions & 0 deletions Slack/Client/Actions/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/api.test
*/
class ApiTest implements ActionsInterface
{

Expand Down
3 changes: 3 additions & 0 deletions Slack/Client/Actions/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/auth.test
*/
class AuthTest implements ActionsInterface
{

Expand Down
3 changes: 3 additions & 0 deletions Slack/Client/Actions/ChannelsHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/channels.history
*/
class ChannelsHistory implements ActionsInterface
{

Expand Down
3 changes: 3 additions & 0 deletions Slack/Client/Actions/ChannelsInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/channels.info
*/
class ChannelsInfo implements ActionsInterface
{

Expand Down
65 changes: 65 additions & 0 deletions Slack/Client/Actions/ChannelsInvite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace DZunke\SlackBundle\Slack\Client\Actions;

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/channels.invite
*/
class ChannelsInvite implements ActionsInterface
{

/**
* @var array
*/
protected $parameter = [
'channel' => null,
'user' => null
];

/**
* @return array
* @throws \Exception
*/
public function getRenderedRequestParams()
{
if (is_null($this->parameter['channel']) || is_null($this->parameter['user'])) {
throw new \Exception('both parameters channel and user must be given');
}

return $this->parameter;
}

/**
* @param array $parameter
* @return $this
*/
public function setParameter(array $parameter)
{
foreach ($parameter as $key => $value) {
if (array_key_exists($key, $this->parameter)) {
$this->parameter[$key] = $value;
}
}

return $this;
}

/**
* @return string
*/
public function getAction()
{
return Actions::ACTION_CHANNELS_INVITE;
}

/**
* @param array $response
* @return array
*/
public function parseResponse(array $response)
{
return [];
}
}
3 changes: 3 additions & 0 deletions Slack/Client/Actions/ChannelsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/channels.list
*/
class ChannelsList implements ActionsInterface
{

Expand Down
3 changes: 3 additions & 0 deletions Slack/Client/Actions/ChannelsSetTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DZunke\SlackBundle\Slack\Client\Actions;

/**
* @see https://api.slack.com/methods/channels.setTopic
*/
class ChannelsSetTopic implements ActionsInterface
{

Expand Down
Loading

0 comments on commit aa56320

Please sign in to comment.