Class: Fluent::SlackClient::WebApi
- Defined in:
- lib/fluent/plugin/slack_client.rb
Overview
Slack client for Web API
Constant Summary collapse
- DEFAULT_ENDPOINT =
"https://slack.com/api/".freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#channels_create(params = {}, opts = {}) ⇒ Object
Creates a channel.
- #channels_create_endpoint ⇒ Object
-
#post_message(params = {}, opts = {}) ⇒ Object
Sends a message to a channel.
- #post_message_endpoint ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Fluent::SlackClient::Base
Instance Method Details
#channels_create(params = {}, opts = {}) ⇒ Object
Creates a channel.
NOTE: Bot user can not create a channel. Token must be issued by Normal User Account
115 116 117 118 |
# File 'lib/fluent/plugin/slack_client.rb', line 115 def channels_create(params = {}, opts = {}) log.info { "out_slack: channels_create #{params.dup.tap {|p| p[:token] = '[FILTERED]' if p[:token] }}" } post(channels_create_endpoint, params) end |
#channels_create_endpoint ⇒ Object
82 83 84 |
# File 'lib/fluent/plugin/slack_client.rb', line 82 def channels_create_endpoint @channels_create_endpoint ||= URI.join(DEFAULT_ENDPOINT, "channels.create") end |
#post_message(params = {}, opts = {}) ⇒ Object
Sends a message to a channel.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fluent/plugin/slack_client.rb', line 91 def (params = {}, opts = {}) retries = 1 begin log.info { "out_slack: post_message #{params.dup.tap {|p| p[:token] = '[FILTERED]' if p[:token] }}" } post(, params) rescue ChannelNotFoundError => e if opts[:auto_channels_create] log.warn "out_slack: channel \"#{params[:channel]}\" is not found. try to create the channel, and then retry to post the message." channels_create({name: params[:channel], token: params[:token]}) retry if (retries -= 1) >= 0 # one time retry else raise e end end end |
#post_message_endpoint ⇒ Object
78 79 80 |
# File 'lib/fluent/plugin/slack_client.rb', line 78 def ||= URI.join(DEFAULT_ENDPOINT, "chat.postMessage") end |