|
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\ChatUpdatePayload; |
|
15
|
|
|
use CL\Slack\Payload\ChatUpdatePayloadResponse; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ChatUpdateCommand extends AbstractApiCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
1 |
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
1 |
|
parent::configure(); |
|
29
|
|
|
|
|
30
|
1 |
|
$this->setName('chat:update'); |
|
31
|
1 |
|
$this->setDescription('Updates a message from a given channel'); |
|
32
|
1 |
|
$this->addArgument('channel-id', InputArgument::REQUIRED, 'The ID of the channel containing the message to be updated'); |
|
33
|
1 |
|
$this->addArgument('timestamp', InputArgument::REQUIRED, 'Timestamp of the message to be updated'); |
|
34
|
1 |
|
$this->addArgument('text', InputArgument::REQUIRED, 'New text for the message, using the default formatting rules'); |
|
35
|
1 |
|
$this->setHelp(<<<EOT |
|
36
|
|
|
The <info>chat:update</info> command updates a message from a given channel. |
|
37
|
|
|
|
|
38
|
|
|
The new message uses the default formatting rules, which can be found here: <comment>https://api.slack.com/docs/formatting</comment> |
|
39
|
|
|
|
|
40
|
|
|
For more information about the related API method, check out the official documentation: |
|
41
|
|
|
<comment>https://api.slack.com/methods/chat.update</comment> |
|
42
|
|
|
EOT |
|
43
|
1 |
|
); |
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return ChatUpdatePayload |
|
48
|
|
|
*/ |
|
49
|
1 |
|
protected function createPayload() |
|
50
|
|
|
{ |
|
51
|
1 |
|
$payload = new ChatUpdatePayload(); |
|
52
|
1 |
|
$payload->setChannelId($this->input->getArgument('channel-id')); |
|
53
|
1 |
|
$payload->setSlackTimestamp($this->input->getArgument('timestamp')); |
|
54
|
1 |
|
$payload->setText($this->input->getArgument('text')); |
|
55
|
|
|
|
|
56
|
1 |
|
return $payload; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
* |
|
62
|
|
|
* @param ChatUpdatePayloadResponse $payloadResponse |
|
63
|
|
|
*/ |
|
64
|
1 |
|
protected function handleResponse($payloadResponse) |
|
65
|
|
|
{ |
|
66
|
1 |
|
if ($payloadResponse->isOk()) { |
|
67
|
1 |
|
$this->writeOk('Successfully updated message!'); |
|
68
|
1 |
|
} else { |
|
69
|
1 |
|
$this->writeError(sprintf('Failed to update message: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
|
70
|
|
|
} |
|
71
|
1 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|