1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slack-cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Cas Leentfaar <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CL\SlackCli\Command; |
13
|
|
|
|
14
|
|
|
use CL\Slack\Payload\ChannelsSetTopicPayload; |
15
|
|
|
use CL\Slack\Payload\ChannelsSetTopicPayloadResponse; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ChannelsSetTopicCommand extends AbstractApiCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
1 |
|
protected function configure() |
27
|
|
|
{ |
28
|
1 |
|
parent::configure(); |
29
|
|
|
|
30
|
1 |
|
$this->setName('channels:set-topic'); |
31
|
1 |
|
$this->setDescription('Change the topic of a channel. The calling user must be a member of the channel.'); |
32
|
1 |
|
$this->addArgument('channel-id', InputArgument::REQUIRED, 'The ID of the channel to change the topic of'); |
33
|
1 |
|
$this->addArgument('topic', InputArgument::REQUIRED, 'The new topic'); |
34
|
1 |
|
$this->setHelp(<<<EOT |
35
|
|
|
The <info>channels.setTopic</info> command changes the topic of a channel. |
36
|
|
|
The calling user must be a member of the channel. |
37
|
|
|
|
38
|
|
|
For more information about the related API method, check out the official documentation: |
39
|
|
|
<comment>https://api.slack.com/methods/channels.setTopic</comment> |
40
|
|
|
EOT |
41
|
1 |
|
); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return ChannelsSetTopicPayload |
46
|
|
|
*/ |
47
|
1 |
|
protected function createPayload() |
48
|
|
|
{ |
49
|
1 |
|
$payload = new ChannelsSetTopicPayload(); |
50
|
1 |
|
$payload->setChannelId($this->input->getArgument('channel-id')); |
51
|
1 |
|
$payload->setTopic($this->input->getArgument('topic')); |
52
|
|
|
|
53
|
1 |
|
return $payload; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
* |
59
|
|
|
* @param ChannelsSetTopicPayloadResponse $payloadResponse |
60
|
|
|
*/ |
61
|
1 |
|
protected function handleResponse($payloadResponse) |
62
|
|
|
{ |
63
|
1 |
|
if ($payloadResponse->isOk()) { |
64
|
1 |
|
$this->writeOk(sprintf('Successfully changed topic of channel to: "%s"', $payloadResponse->getTopic())); |
65
|
1 |
|
} else { |
66
|
1 |
|
$this->writeError(sprintf('Failed to change topic of channel: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
67
|
|
|
} |
68
|
1 |
|
} |
69
|
|
|
} |
70
|
|
|
|