Class: ChatNotifier::Chatter::Slack
Direct Known Subclasses
Debug
Constant Summary
collapse
- API_URL =
"https://slack.com/api/chat.postMessage"
- REPLIES_URL =
"https://slack.com/api/conversations.replies"
- UPDATE_URL =
"https://slack.com/api/chat.update"
- DEFAULT_THREAD_GROUP_SIZE =
10
- STATUS_EVENT_TYPE =
"chat_notifier_status"
OPEN_TIMEOUT, READ_TIMEOUT
Instance Attribute Summary collapse
#environment, #repository, #settings, #thread_store
Class Method Summary
collapse
Instance Method Summary
collapse
#body, handlers, handling, #http_client, #http_post, #initialize, register, #verbose?
Instance Attribute Details
#sleeper ⇒ Object
45
46
47
|
# File 'lib/chat_notifier/chatter/slack.rb', line 45
def sleeper
@sleeper ||= Kernel.method(:sleep)
end
|
Class Method Details
.handles?(settings) ⇒ Boolean
17
18
19
20
21
|
# File 'lib/chat_notifier/chatter/slack.rb', line 17
def handles?(settings)
%w[NOTIFY_SLACK_WEBHOOK_URL NOTIFY_SLACK_BOT_TOKEN].any? do |key|
settings.fetch(key, nil)
end
end
|
Instance Method Details
#api_form_post(url, params, process: method(:http_post)) ⇒ Object
Slack read APIs (conversations.history, conversations.replies) take
form-encoded params rather than JSON bodies.
70
71
72
73
|
# File 'lib/chat_notifier/chatter/slack.rb', line 70
def api_form_post(url, params, process: method(:http_post))
response = process.call(URI(url), URI.encode_www_form(params), )
parsed_response(response)
end
|
#bot_token ⇒ Object
28
29
30
|
# File 'lib/chat_notifier/chatter/slack.rb', line 28
def bot_token
settings.fetch("NOTIFY_SLACK_BOT_TOKEN", nil)
end
|
#channel ⇒ Object
32
33
34
|
# File 'lib/chat_notifier/chatter/slack.rb', line 32
def channel
settings.fetch("NOTIFY_SLACK_NOTIFY_CHANNEL", nil)
end
|
#conditional_post(messenger, process: method(:http_post)) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/chat_notifier/chatter/slack.rb', line 57
def conditional_post(messenger, process: method(:http_post))
return super unless bot_token
return post(messenger, process:) if messenger.failure? || verbose?
resolve_episode(messenger, process:)
end
|
#default_thread_store ⇒ Object
With a bot token the channel itself can store thread metadata.
76
77
78
79
80
|
# File 'lib/chat_notifier/chatter/slack.rb', line 76
def default_thread_store
return super unless bot_token
ThreadStore::SlackMetadata.new(chatter: self)
end
|
#payload(data) ⇒ Object
64
65
66
|
# File 'lib/chat_notifier/chatter/slack.rb', line 64
def payload(data)
super(Configuration.for(data, self).to_h)
end
|
#post(messenger, process: method(:http_post)) ⇒ Object
When a bot token is configured we use the Slack Web API, which can
thread failures. The token path is preferred over an incoming webhook.
51
52
53
54
55
|
# File 'lib/chat_notifier/chatter/slack.rb', line 51
def post(messenger, process: method(:http_post))
return super unless bot_token
post_via_api(messenger, process:)
end
|
#thread_group_size ⇒ Object
#webhook_url ⇒ Object
24
25
26
|
# File 'lib/chat_notifier/chatter/slack.rb', line 24
def webhook_url
settings.fetch("NOTIFY_SLACK_WEBHOOK_URL", nil)
end
|