Skip to content

Commit

Permalink
Merge pull request #13 from Meneth/icon
Browse files Browse the repository at this point in the history
Config to set Slack avatar for bot
  • Loading branch information
kulttuuri authored Sep 14, 2016
2 parents e0da4ad + 9304bf1 commit 6505f6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions SlackNotifications/SlackNotificationsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static function slack_user_blocked(Block $block, $user)
*/
static function push_slack_notify($message, $bgColor, $user)
{
global $wgSlackIncomingWebhookUrl, $wgSlackFromName, $wgSlackRoomName, $wgSlackSendMethod, $wgExcludedPermission, $wgSitename;
global $wgSlackIncomingWebhookUrl, $wgSlackFromName, $wgSlackRoomName, $wgSlackSendMethod, $wgExcludedPermission, $wgSitename, $wgSlackEmoji;

if ( $wgExcludedPermission != "" ) {
if ( $user->isAllowed( $wgExcludedPermission ) )
Expand All @@ -292,10 +292,15 @@ static function push_slack_notify($message, $bgColor, $user)
$slackFromName = $wgSitename;
}

$post = sprintf('payload={"text": "%s", "username": "%s",'.$optionalChannel.' "attachments": [ { "color": "%s" } ]}',
$post = sprintf('payload={"text": "%s", "username": "%s",'.$optionalChannel.' "attachments": [ { "color": "%s" } ]',
urlencode($message),
urlencode($slackFromName),
urlencode($slackColor));
if ( $wgSlackEmoji != "" )
{
$post .= sprintf( ', "icon_emoji": "%s"', $wgSlackEmoji );
}
$post .= '}';

// Use file_get_contents to send the data. Note that you will need to have allow_url_fopen enabled in php.ini for this to work.
if ($wgSlackSendMethod == "file_get_contents") {
Expand Down
2 changes: 2 additions & 0 deletions SlackNotifications/SlackNotificationsDefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
$wgSlackIgnoreMinorEdits = false;
// If this is set, actions by users with this permission won't cause alerts
$wgExcludedPermission = "";
// If this is set, the given emoji-string will be used as the avatar of the Slack-bot for the message. Example: ":ghost:"
$wgSlackEmoji = "";

##################
# MEDIAWIKI URLS #
Expand Down
1 change: 1 addition & 0 deletions SlackNotifications/extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"SlackFromName": "",
"SlackRoomName": "",
"SlackSendMethod": "curl",
"SlackEmoji": "",
"SlackIncludePageUrls": true,
"SlackIncludeUserUrls": true,
"SlackIgnoreMinorEdits": false,
Expand Down

0 comments on commit 6505f6d

Please sign in to comment.