options = $options; } public function sendMessage(string $text, array $options) { $mergedOptions = array_merge($this->options, $options); $url = $mergedOptions['url'] ?? throw new RuntimeException("Empty hook url"); $body = $this->makeBody($text, $mergedOptions); $client = new Client(); $client->post($url, [ 'json' => $body ]); } private function makeBody(string $text, array $options) { /* { "channel": "town-square", "username": "test-automation", "icon_url": "https://mattermost.org/wp-content/uploads/2016/04/icon.png", "text": "#### Test results for July 27th, 2017\n please review failed tests.\n | Component | Tests Run | Tests Failed | |:-----------|:-----------:|:-----------------------------------------------| | Server | 948 | :white_check_mark: 0 | | Web Client | 123 | :warning: 2 [(see details)](http://linktologs) | | iOS Client | 78 | :warning: 3 [(see details)](http://linktologs) | " } */ $body = []; if (array_key_exists('channel', $options)) $body['channel'] = $options['channel']; if (array_key_exists('username', $options)) $body['username'] = $options['username']; if (array_key_exists('icon_url', $options)) $body['icon_url'] = $options['icon_url']; if (array_key_exists('info', $options)) { if (!array_key_exists('props', $body)) $body['props'] = []; $body['props']['card'] = $options['info']; } $body['text'] = $text; return $body; } }