Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #15 from mvdstam/patch-2
Browse files Browse the repository at this point in the history
Refactored the slack.php recipe and also added support for the "icon_url" configuration.
  • Loading branch information
Hubert Viktor committed Jun 18, 2015
2 parents dff3dbf + c366580 commit 5c50b9f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions recipes/slack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5c50b9f

Please sign in to comment.