Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Slack fix #178

Merged
merged 3 commits into from

2 participants

@danshultz

Slack handler was not properly notifying a channel as this seemed to be using an older version of the slack api maybe? I have created an update to use the slack channel as per the documentation and also have updated it to ensure names are linked.

I have added 2 additional features to the slack notifer as well which allow you to specify the name that appears when notifying the channel (this overrides the default name configured in slack for the token) and added the ability to specify an emoji icon for the notification (which also overrides the default in slack).

These two additions are helpful and make it easier to use a single token across multiple use cases for integrations.

danshultz added some commits
@danshultz danshultz fix slack handler
* Channel should be passed as a body argument
* Include link names to ensure channel properly notified
762a415
@danshultz danshultz include ability to set bot username 584549d
@danshultz danshultz slack notifier supports emoji fc13337
@eric
Collaborator

Looks good.

@eric eric merged commit d78b312 into mojombo:master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 2, 2014
  1. @danshultz

    fix slack handler

    danshultz authored
    * Channel should be passed as a body argument
    * Include link names to ensure channel properly notified
  2. @danshultz
  3. @danshultz
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 5 deletions.
  1. +11 −4 lib/god/contacts/slack.rb
  2. +1 −1  test/test_slack.rb
View
15 lib/god/contacts/slack.rb
@@ -19,7 +19,7 @@ module Contacts
class Slack < Contact
class << self
- attr_accessor :account, :token, :channel, :notify_channel, :format
+ attr_accessor :account, :token, :channel, :notify_channel, :format, :username, :emoji
end
self.channel = "#general"
@@ -33,7 +33,7 @@ def valid?
valid
end
- attr_accessor :account, :token, :channel, :notify_channel, :format
+ attr_accessor :account, :token, :channel, :notify_channel, :format, :username, :emoji
def text(data)
text = ""
@@ -63,7 +63,7 @@ def notify(message, time, priority, category, host)
end
def api_url
- URI.parse("https://#{arg(:account)}.slack.com/services/hooks/incoming-webhook?token=#{arg(:token)}&channel=#{arg(:channel)}")
+ URI.parse("https://#{arg(:account)}.slack.com/services/hooks/incoming-webhook?token=#{arg(:token)}")
end
def request(text)
@@ -71,7 +71,14 @@ def request(text)
http.use_ssl = true
req = Net::HTTP::Post.new(api_url.request_uri)
- req.body = { :text => text }.to_json
+ req.body = {
+ :link_names => 1,
+ :text => text,
+ :channel => arg(:channel)
+ }.tap { |payload|
+ payload[:username] = arg(:username) if arg(:username)
+ payload[:icon_emoji] = arg(:emoji) if arg(:emoji)
+ }.to_json
res = http.request(req)
View
2  test/test_slack.rb
@@ -16,7 +16,7 @@ def setup
end
def test_api_url
- assert_equal "https://foo.slack.com/services/hooks/incoming-webhook?token=foo&channel=#general", @slack.api_url.to_s
+ assert_equal "https://foo.slack.com/services/hooks/incoming-webhook?token=foo", @slack.api_url.to_s
end
def test_notify
Something went wrong with that request. Please try again.