diff --git a/recipes/slack.php b/recipes/slack.php index e310cb8..98ec3eb 100644 --- a/recipes/slack.php +++ b/recipes/slack.php @@ -36,12 +36,21 @@ throw new \RuntimeException("Please configure new slack: set('slack', array('token' => 'xoxp...', 'team' => 'team', 'channel' => '#channel', 'messsage' => 'message to send'));"); } - $url = 'https://slack.com/api/chat.postMessage?token=' . $config['token'] . - '&channel=' . urlencode($config['channel']) . - '&text=' . urlencode($config['message']) . - '&username=' . urlencode($config['username']) . - '&icon_emoji=' . urlencode($config['icon']) . - '&pretty=1'; + $urlParams = [ + 'channel' => $config['channel'], + 'token' => $config['token'], + 'text' => $config['message'], + 'username' => $config['username'], + 'icon_emoji' => $config['icon'], + 'pretty' => true + ]; + + if (isset($config['icon_url'])) { + unset($urlParams['icon_emoji']); + $urlParams['icon_url'] = $config['icon_url']; + } + + $url = 'https://slack.com/api/chat.postMessage?' . http_build_query($urlParams); $result = @file_get_contents($url);