Conditions | 2 |
Paths | 2 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public function dispatch(MessageInterface $message) |
||
10 | { |
||
11 | // Get the dispatch and message data from the message. |
||
12 | $dispatchData = $message->getDispatchData(); |
||
13 | $messageData = $message->getMessageData(); |
||
14 | |||
15 | // Build payload from the message data. |
||
16 | $messageData['text'] = $messageData['body']; |
||
17 | unset($messageData['body']); |
||
18 | |||
19 | $data = 'payload=' . json_encode($messageData); |
||
20 | |||
21 | $ch = curl_init(); |
||
22 | curl_setopt($ch, CURLOPT_URL, $dispatchData['webhook']); |
||
23 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
||
24 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||
25 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
26 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
27 | $result = curl_exec($ch); |
||
28 | |||
29 | if ($result !== 'ok') { |
||
30 | return false; |
||
31 | } |
||
32 | |||
33 | curl_close($ch); |
||
34 | |||
35 | return true; |
||
36 | } |
||
37 | } |