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\GroupsInvitePayload; |
15
|
|
|
use CL\Slack\Payload\GroupsInvitePayloadResponse; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Cas Leentfaar <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class GroupsInviteCommand extends AbstractApiCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
*/ |
27
|
|
|
protected function configure() |
28
|
|
|
{ |
29
|
|
|
parent::configure(); |
30
|
|
|
|
31
|
|
|
$this->setName('groups:invite'); |
32
|
|
|
$this->setDescription('Invites a user to a group. The token\'s user must be a member of the group'); |
33
|
|
|
$this->addArgument('group-id', InputArgument::REQUIRED, 'The ID of the group to invite the user into'); |
34
|
|
|
$this->addArgument('user-id', InputArgument::REQUIRED, 'The ID of the user to invite'); |
35
|
|
|
$this->setHelp(<<<EOT |
36
|
|
|
The <info>groups:invite</info> command is used to invite a user to a private group. |
37
|
|
|
The calling user must be a member of the group. |
38
|
|
|
|
39
|
|
|
To invite a new member to a group without giving them access to the archives of the group |
40
|
|
|
run the <info>groups.createChild</info> command before inviting. |
41
|
|
|
|
42
|
|
|
For more information about the related API method, check out the official documentation: |
43
|
|
|
<comment>https://api.slack.com/methods/groups.invite</comment> |
44
|
|
|
EOT |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return GroupsInvitePayload |
50
|
|
|
*/ |
51
|
|
|
protected function createPayload() |
52
|
|
|
{ |
53
|
|
|
$payload = new GroupsInvitePayload(); |
54
|
|
|
$payload->setGroupId($this->input->getArgument('group-id')); |
55
|
|
|
$payload->setUserId($this->input->getArgument('user-id')); |
56
|
|
|
|
57
|
|
|
return $payload; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
* |
63
|
|
|
* @param GroupsInvitePayloadResponse $payloadResponse |
64
|
|
|
*/ |
65
|
|
|
protected function handleResponse($payloadResponse) |
66
|
|
|
{ |
67
|
|
|
if ($payloadResponse->isOk()) { |
68
|
|
|
if ($payloadResponse->getAlreadyInGroup()) { |
69
|
|
|
$this->output->writeln('<comment>The given user is already in this group</comment>'); |
70
|
|
|
} else { |
71
|
|
|
$this->writeOk('Successfully invited user to the group!'); |
72
|
|
|
if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { |
73
|
|
|
$this->output->writeln('Group used:'); |
74
|
|
|
$data = $this->serializeObjectToArray($payloadResponse->getGroup()); |
75
|
|
|
$this->renderKeyValueTable($data); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} else { |
79
|
|
|
$this->writeError(sprintf('Failed to invite user: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|