slack_message 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +22 -0
- data/lib/slack_message/configuration.rb +2 -2
- data/lib/slack_message.rb +17 -1
- data/slack_message.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e66bdedefd2ac86c6c49d974e5f5d0474cc9b3756ce3a64e52df66ccc6e39cf4
|
4
|
+
data.tar.gz: b085edf556d957516d1cbbc9b260b7aff0e5d34b4561d27ae0d5f6b2dda9c93b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea935db68ca4771e11b40828d5cbd2fef02cf10c248fab3ede05ea82aef6a3a6d7ad96953debdc9214833ee0f281222e5e09adefd923c70d21090c996dba31a0
|
7
|
+
data.tar.gz: 46d2163aa9ec0e9df582700575d0c8b47b389b808f93275129025bc277086eb02fbeb4caa0754408dbc6d6fba9f06b6d8720493280550e0d3664bc735059f7c1
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
## [Unreleased]
|
4
4
|
|
5
|
+
## [1.6.0] - 2021-10-04
|
6
|
+
- Added `:default_channel` and `post_as` to deal with repetitive channel usage.
|
7
|
+
|
5
8
|
## [1.5.0] - 2021-10-01
|
6
|
-
- Added `ol` and `ul` to sections w/ some formatting
|
9
|
+
- Added `ol` and `ul` to sections w/ some formatting.
|
7
10
|
|
8
11
|
## [1.4.0] - 2021-09-27
|
9
12
|
- Moved image to accessory_image to differentiate between the image block
|
data/README.md
CHANGED
@@ -55,6 +55,28 @@ SlackMessage.configure do |config|
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
If you frequently ping the same channel with the same bot, and don't want to
|
59
|
+
continually specify the channel name, you can specify a default channel and
|
60
|
+
post using the `post_as` method. It is otherwise identical to `post_to`, but
|
61
|
+
allows you to omit the channel argument:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
SlackMessage.configure do |config|
|
65
|
+
config.add_profile(:prod_alert_bot,
|
66
|
+
name: 'Prod Alert Bot',
|
67
|
+
url: ENV['SLACK_PROD_ALERT_WEBHOOK_URL'],
|
68
|
+
default_channel: '#red_alerts'
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
SlackMessage.post_as(:prod_alert_bot) do
|
73
|
+
text ":ambulance: weeooo weeooo something went wrong"
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
Note that `post_as` does not allow you to choose a channel (because that's just
|
78
|
+
the same as using `post_to`), so you really do have to specify `default_channel`.
|
79
|
+
|
58
80
|
#### Configuring User Search
|
59
81
|
|
60
82
|
Slack's API no longer allows you to send DMs to users by username. You need to
|
@@ -27,12 +27,12 @@ module SlackMessage::Configuration
|
|
27
27
|
|
28
28
|
###
|
29
29
|
|
30
|
-
def self.add_profile(handle = :default, name:, url:)
|
30
|
+
def self.add_profile(handle = :default, name:, url:, default_channel: nil)
|
31
31
|
if @@profiles.include?(handle)
|
32
32
|
warn "WARNING: Overriding profile '#{handle}' in SlackMessage config"
|
33
33
|
end
|
34
34
|
|
35
|
-
@@profiles[handle] = { name: name, url: url, handle: handle }
|
35
|
+
@@profiles[handle] = { name: name, url: url, handle: handle, default_channel: default_channel }
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.profile(handle, custom_name: nil)
|
data/lib/slack_message.rb
CHANGED
@@ -11,7 +11,7 @@ module SlackMessage
|
|
11
11
|
configuration.configure(&block)
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.user_id_for(email)
|
14
|
+
def self.user_id_for(email) # spooky undocumented public method 👻
|
15
15
|
Api::user_id_for(email)
|
16
16
|
end
|
17
17
|
|
@@ -26,6 +26,22 @@ module SlackMessage
|
|
26
26
|
Api.post(payload.render, target, profile)
|
27
27
|
end
|
28
28
|
|
29
|
+
def self.post_as(profile_name, &block)
|
30
|
+
payload = Dsl.new.tap do |instance|
|
31
|
+
instance.instance_eval(&block)
|
32
|
+
end
|
33
|
+
|
34
|
+
profile = Configuration.profile(profile_name, custom_name: payload.custom_bot_name)
|
35
|
+
if profile[:default_channel].nil?
|
36
|
+
raise ArgumentError, "Sorry, you need to specify a default_channel for profile #{profile_name} to use post_as"
|
37
|
+
end
|
38
|
+
|
39
|
+
target = profile[:default_channel]
|
40
|
+
target = user_id_for(target) if target =~ /^\S{1,}@\S{2,}\.\S{2,}$/
|
41
|
+
|
42
|
+
Api.post(payload.render, target, profile)
|
43
|
+
end
|
44
|
+
|
29
45
|
def self.build(&block)
|
30
46
|
Dsl.new.tap do |instance|
|
31
47
|
instance.instance_eval(&block)
|
data/slack_message.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_message
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Mastey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|