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