Переглянути джерело

allow custom icon for slack webhooks

stvnrlly 10 роки тому
батько
коміт
9e4b58b023
1 змінених файлів з 10 додано та 2 видалено
  1. 10 2
      app/models/agents/slack_agent.rb

+ 10 - 2
app/models/agents/slack_agent.rb

@@ -20,7 +20,10 @@ module Agents
       Once the webhook has been setup it can be used to post to other channels or ping team members.
       Once the webhook has been setup it can be used to post to other channels or ping team members.
       To send a private message to team-mate, assign his username as `@username` to the channel option.
       To send a private message to team-mate, assign his username as `@username` to the channel option.
       To communicate with a different webhook on slack, assign your custom webhook name to the webhook option.
       To communicate with a different webhook on slack, assign your custom webhook name to the webhook option.
-      Messages can also be formatted using [Liquid](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid)
+      Messages can also be formatted using [Liquid](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid).
+
+      Finally, you can set a custom icon for this webhook in `icon`, either as [emoji](http://unicodey.com/emoji-data/table.htm) or an URL to an image.
+      Leaving this field blank will use the default icon for a webhook.
     MD
     MD
 
 
     def default_options
     def default_options
@@ -29,6 +32,7 @@ module Agents
         'channel' => '#general',
         'channel' => '#general',
         'username' => DEFAULT_USERNAME,
         'username' => DEFAULT_USERNAME,
         'message' => "Hey there, It's Huginn",
         'message' => "Hey there, It's Huginn",
+        'icon' => '',
       }
       }
     end
     end
 
 
@@ -67,7 +71,11 @@ module Agents
     def receive(incoming_events)
     def receive(incoming_events)
       incoming_events.each do |event|
       incoming_events.each do |event|
         opts = interpolated(event)
         opts = interpolated(event)
-        slack_notifier.ping opts[:message], channel: opts[:channel], username: opts[:username]
+        if /^:/.match(opts[:icon])
+            slack_notifier.ping opts[:message], channel: opts[:channel], username: opts[:username], icon_emoji: opts[:icon]
+        else
+            slack_notifier.ping opts[:message], channel: opts[:channel], username: opts[:username], icon_url: opts[:icon]
+        end
       end
       end
     end
     end
   end
   end