1 | <?php |
||
8 | class Sender extends AbstractSender |
||
9 | { |
||
10 | private $slackbot; |
||
11 | |||
12 | /** |
||
13 | * Sender constructor. |
||
14 | * |
||
15 | * @param AbstractBot $slackbot |
||
16 | */ |
||
17 | 13 | public function __construct(AbstractBot $slackbot) |
|
21 | |||
22 | /** |
||
23 | * @return Slackbot |
||
24 | */ |
||
25 | 9 | public function getSlackbot() |
|
29 | |||
30 | /** |
||
31 | * @param AbstractBot $slackbot |
||
32 | */ |
||
33 | 13 | public function setSlackbot(AbstractBot $slackbot) |
|
37 | |||
38 | /** |
||
39 | * Final endpoint for the response. |
||
40 | * |
||
41 | * @param $channel |
||
42 | * @param $text |
||
43 | * @param $attachments |
||
44 | * |
||
45 | * @throws \Exception |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | 9 | public function send($text, $channel = null, $attachments = null) |
|
83 | |||
84 | /** |
||
85 | * @param $response |
||
86 | */ |
||
87 | 1 | private function respondToSlashCommand($response) |
|
88 | { |
||
89 | /** @noinspection PhpUndefinedClassInspection */ |
||
90 | 1 | $request = new Request( |
|
91 | 1 | 'POST', |
|
92 | 1 | $this->getSlackbot()->getRequest('response_url'), |
|
93 | 1 | ['Content-Type' => 'application/json'], |
|
94 | 1 | json_encode([ |
|
95 | 1 | 'text' => $response, |
|
96 | 1 | 'response_type' => 'in_channel', |
|
97 | ]) |
||
98 | ); |
||
99 | |||
100 | /* @noinspection PhpUndefinedClassInspection */ |
||
101 | 1 | $this->getClient()->send($request); |
|
102 | 1 | } |
|
103 | |||
104 | /** |
||
105 | * @param $data |
||
106 | */ |
||
107 | 1 | private function respondToSlack($data) |
|
111 | |||
112 | /** |
||
113 | * @param $data |
||
114 | */ |
||
115 | 7 | private function respondAsJSON($data) |
|
124 | |||
125 | /** |
||
126 | * Specify the response type |
||
127 | * If response in config is set to empty, it will be considered based on listener. |
||
128 | * |
||
129 | * @return mixed|string |
||
130 | */ |
||
131 | 9 | private function getResponseType() |
|
141 | |||
142 | /** |
||
143 | * @return string|null |
||
144 | */ |
||
145 | 2 | private function getResponseByListenerType() |
|
157 | |||
158 | /** |
||
159 | * Send confirmation. |
||
160 | */ |
||
161 | 1 | public function sendConfirmation() |
|
180 | } |
||
181 |