lib/fluent/plugin/out_slack.rb in fluent-plugin-slack-0.6.3 vs lib/fluent/plugin/out_slack.rb in fluent-plugin-slack-0.6.4
- old
+ new
@@ -47,10 +47,17 @@
config_param :color, :string, default: nil
desc <<-DESC
Emoji to use as the icon.
Either of `icon_emoji` or `icon_url` can be specified.
DESC
+ config_param :as_user, :bool, default: nil
+ desc <<-DESC
+Post message as the authenticated user.
+NOTE: This parameter is only enabled if you use the Web API with your bot token.
+You cannot use both of `username` and `icon_emoji`(`icon_url`) when
+you set this parameter to `true`.
+DESC
config_param :icon_emoji, :string, default: nil
desc <<-DESC
Url to an image to use as the icon.
Either of `icon_emoji` or `icon_url` can be specified.
DESC
@@ -131,18 +138,24 @@
if @webhook_url
if @webhook_url.empty?
raise Fluent::ConfigError.new("`webhook_url` is an empty string")
end
+ unless @as_user.nil?
+ log.warn "out_slack: `as_user` parameter are not available for Incoming Webhook"
+ end
@slack = Fluent::SlackClient::IncomingWebhook.new(@webhook_url)
elsif @slackbot_url
if @slackbot_url.empty?
raise Fluent::ConfigError.new("`slackbot_url` is an empty string")
end
if @username or @color or @icon_emoji or @icon_url
log.warn "out_slack: `username`, `color`, `icon_emoji`, `icon_url` parameters are not available for Slackbot Remote Control"
end
+ unless @as_user.nil?
+ log.warn "out_slack: `as_user` parameter are not available for Slackbot Remote Control"
+ end
@slack = Fluent::SlackClient::Slackbot.new(@slackbot_url)
elsif @token
if @token.empty?
raise Fluent::ConfigError.new("`token` is an empty string")
end
@@ -181,10 +194,14 @@
if @icon_emoji and @icon_url
raise Fluent::ConfigError, "either of `icon_emoji` or `icon_url` can be specified"
end
+ if @as_user and (@icon_emoji or @icon_url or @username)
+ raise Fluent::ConfigError, "`username`, `icon_emoji` and `icon_url` cannot be specified when `as_user` is set to true"
+ end
+
if @mrkdwn
# Enable markdown for attachments. See https://api.slack.com/docs/formatting
@mrkdwn_in = %w[text fields]
end
@@ -230,9 +247,10 @@
end
def common_payload
return @common_payload if @common_payload
@common_payload = {}
+ @common_payload[:as_user] = @as_user unless @as_user.nil?
@common_payload[:username] = @username if @username
@common_payload[:icon_emoji] = @icon_emoji if @icon_emoji
@common_payload[:icon_url] = @icon_url if @icon_url
@common_payload[:mrkdwn] = @mrkdwn if @mrkdwn
@common_payload[:link_names] = @link_names if @link_names