1 | <?php |
||
10 | abstract class AbstractBaseListener |
||
11 | { |
||
12 | const ORIGIN_VERIFICATION_SUCCESS_KEY = 'success'; |
||
13 | const ORIGIN_VERIFICATION_MESSAGE_KEY = 'message'; |
||
14 | |||
15 | private $config; |
||
16 | private $request; |
||
17 | private $requestUtility; |
||
18 | |||
19 | /** |
||
20 | * listen. |
||
21 | * |
||
22 | * @throws \Exception |
||
23 | * |
||
24 | * @return mixed |
||
25 | */ |
||
26 | 10 | public function listen() |
|
47 | |||
48 | /** |
||
49 | * @return mixed |
||
50 | */ |
||
51 | abstract public function extractRequest(); |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | abstract public function getChannelId(): string; |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | abstract public function getKey(): string; |
||
62 | |||
63 | /** |
||
64 | * @param null|string $key |
||
65 | * |
||
66 | * @return mixed |
||
67 | */ |
||
68 | 35 | public function getRequest(string $key = null) |
|
84 | |||
85 | /** |
||
86 | * @param array $request |
||
87 | */ |
||
88 | 45 | public function setRequest($request) |
|
92 | |||
93 | /** |
||
94 | * @return Config |
||
95 | */ |
||
96 | 8 | public function getConfig(): Config |
|
104 | |||
105 | /** |
||
106 | * @param Config $config |
||
107 | */ |
||
108 | 12 | public function setConfig(Config $config) |
|
112 | |||
113 | /** |
||
114 | * Verify the request comes from Slack |
||
115 | * Each listener must have have this and has got its own way to check the request. |
||
116 | * |
||
117 | * @throws \Exception |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | abstract public function verifyOrigin(); |
||
122 | |||
123 | /** |
||
124 | * Check if the request belongs to the bot itself. |
||
125 | * |
||
126 | * @throws \Exception |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | abstract public function isThisBot(): bool; |
||
131 | |||
132 | /** |
||
133 | * @return RequestUtility |
||
134 | */ |
||
135 | 24 | public function getRequestUtility(): RequestUtility |
|
143 | |||
144 | /** |
||
145 | * @param RequestUtility $requestUtility |
||
146 | */ |
||
147 | 25 | public function setRequestUtility(RequestUtility $requestUtility) |
|
151 | |||
152 | /** |
||
153 | * respondOK. |
||
154 | */ |
||
155 | 10 | protected function respondOK() |
|
191 | |||
192 | /** |
||
193 | * @throws \Exception |
||
194 | * |
||
195 | * @return array<string,boolean|string> |
||
196 | */ |
||
197 | 5 | public function verifyRequest(): array |
|
221 | |||
222 | /** |
||
223 | * @return string|null |
||
224 | */ |
||
225 | 8 | public function determineAction() |
|
240 | |||
241 | /** |
||
242 | * Return message based on the listener |
||
243 | * If listener is event and event text is empty, fall back to request text. |
||
244 | * |
||
245 | * @throws \Exception |
||
246 | * |
||
247 | * @return mixed|string |
||
248 | */ |
||
249 | 9 | public function getMessage() |
|
261 | } |
||
262 |