Class: SmartTodo::Dispatchers::Slack
- Defined in:
- lib/smart_todo/dispatchers/slack.rb
Overview
Dispatcher that sends TODO reminders on Slack. Assignees can be either individual (using the associated slack email address) or a channel.
Class Method Summary collapse
Instance Method Summary collapse
-
#dispatch ⇒ Array
Make a Slack API call to dispatch the message to each assignee.
-
#dispatch_one(assignee) ⇒ Hash
Make a Slack API call to dispatch the message to the user or channel.
Methods inherited from Base
Constructor Details
This class inherits a constructor from SmartTodo::Dispatchers::Base
Class Method Details
.validate_options!(options) ⇒ Object
9 10 11 12 13 |
# File 'lib/smart_todo/dispatchers/slack.rb', line 9 def () [:slack_token] ||= ENV.fetch("SMART_TODO_SLACK_TOKEN") { raise(ArgumentError, "Missing :slack_token") } .fetch(:fallback_channel) { raise(ArgumentError, "Missing :fallback_channel") } end |
Instance Method Details
#dispatch ⇒ Array
Make a Slack API call to dispatch the message to each assignee
22 23 24 25 26 |
# File 'lib/smart_todo/dispatchers/slack.rb', line 22 def dispatch @assignees.each do |assignee| dispatch_one(assignee) end end |
#dispatch_one(assignee) ⇒ Hash
Make a Slack API call to dispatch the message to the user or channel
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/smart_todo/dispatchers/slack.rb', line 35 def dispatch_one(assignee) user = slack_user_or_channel(assignee) client.(user.dig("user", "id"), (user, assignee)) rescue SlackClient::Error => error if ["users_not_found", "channel_not_found", "is_archived"].include?(error.error_code) user = { "user" => { "id" => @options[:fallback_channel] }, "fallback" => true } else raise(error) end client.(user.dig("user", "id"), (user, assignee)) end |