ruboty-slack_rtm 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -6
- data/lib/ruboty/adapters/slack_rtm.rb +20 -8
- data/lib/ruboty/slack_rtm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e73d77b1b4391c773714eb6f44b0221ad8dabf
|
4
|
+
data.tar.gz: b97942197c1b6ac18f0b29a7bbf11bcb1fbdb97a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 196669e7298354cc24f308c5b95634c169b4cbb655163fd13f99aff566f06e4fe0f8157fe07cb81b72efb8ade73bcf6d5875e5e88c98634c96718fd2823cf3cc
|
7
|
+
data.tar.gz: f30da17bd38608e2d2b0914cc85d1f8519607a046f77d474eceab2cdc6d72211b33fc784464e46deb10db75ee31b360a2281bac74e70438f76e5cc639f88d3c7
|
data/README.md
CHANGED
@@ -12,13 +12,11 @@ gem 'ruboty-slack_rtm'
|
|
12
12
|
|
13
13
|
## ENV
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
```
|
18
|
-
|
19
|
-
Do not requires real user account. using with bot is recommended.
|
15
|
+
- `SLACK_TOKEN`: Account's token. get one on https://api.slack.com/web#basics
|
16
|
+
- `SLACK_EXPOSE_CHANNEL_NAME_AS_FROM`: if this set to 1, `message.from` will be channel name instead of id (optional)
|
20
17
|
|
21
|
-
|
18
|
+
This adapter doesn't require a real user account. Using with bot integration's API token is recommended.
|
19
|
+
See: https://api.slack.com/bot-users
|
22
20
|
|
23
21
|
## Contributing
|
24
22
|
|
@@ -7,6 +7,7 @@ module Ruboty
|
|
7
7
|
module Adapters
|
8
8
|
class SlackRTM < Base
|
9
9
|
env :SLACK_TOKEN, "Account's token. get one on https://api.slack.com/web#basics"
|
10
|
+
env :SLACK_EXPOSE_CHANNEL_NAME_AS_FROM, "if this set to 1, message.from will be channel name instead of id", optional: true
|
10
11
|
|
11
12
|
def run
|
12
13
|
init
|
@@ -35,7 +36,7 @@ module Ruboty
|
|
35
36
|
def init
|
36
37
|
response = client.auth_test
|
37
38
|
@user_info_caches = {}
|
38
|
-
@
|
39
|
+
@channel_info_caches = {}
|
39
40
|
|
40
41
|
ENV['RUBOTY_NAME'] ||= response['user']
|
41
42
|
|
@@ -73,6 +74,14 @@ module Ruboty
|
|
73
74
|
@realtime ||= ::SlackRTM::Client.new(websocket_url: url)
|
74
75
|
end
|
75
76
|
|
77
|
+
def expose_channel_name_as_from?
|
78
|
+
if @expose_channel_name_as_from.nil?
|
79
|
+
@expose_channel_name_as_from = ENV['SLACK_EXPOSE_CHANNEL_NAME_AS_FROM'] == '1'
|
80
|
+
else
|
81
|
+
@expose_channel_name_as_from
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
76
85
|
def set_active
|
77
86
|
client.users_setActive
|
78
87
|
end
|
@@ -83,12 +92,15 @@ module Ruboty
|
|
83
92
|
data = resolve_mention!(data)
|
84
93
|
user = user_info(data['user']) || {}
|
85
94
|
|
95
|
+
channel = channel_info(data['channel'])
|
96
|
+
channel_from = expose_channel_name_as_from? ? "##{channel['name']}" : channel['id']
|
97
|
+
|
86
98
|
robot.receive(
|
87
99
|
body: data['text'],
|
88
|
-
from:
|
100
|
+
from: channel_from,
|
89
101
|
from_name: user['name'],
|
90
102
|
to: data['channel'],
|
91
|
-
channel:
|
103
|
+
channel: channel,
|
92
104
|
user: user,
|
93
105
|
mention_to: data['mention_to'],
|
94
106
|
time: Time.at(data['ts'].to_f)
|
@@ -154,13 +166,13 @@ module Ruboty
|
|
154
166
|
|
155
167
|
def resolve_send_mention(text)
|
156
168
|
text = text.to_s
|
157
|
-
text.gsub!(/@(?<mention>[0-9a-
|
169
|
+
text.gsub!(/@(?<mention>[0-9a-z._-]+)/) do |_|
|
158
170
|
mention = Regexp.last_match[:mention]
|
159
171
|
msg = "@#{mention}"
|
160
172
|
|
161
173
|
@user_info_caches.each_pair do |id, user|
|
162
174
|
if user['name'].downcase == mention.downcase
|
163
|
-
msg = "<@#{id}
|
175
|
+
msg = "<@#{id}>"
|
164
176
|
end
|
165
177
|
end
|
166
178
|
|
@@ -175,7 +187,7 @@ module Ruboty
|
|
175
187
|
room_id = Regexp.last_match[:room_id]
|
176
188
|
msg = "##{room_id}"
|
177
189
|
|
178
|
-
@
|
190
|
+
@channel_info_caches.each_pair do |id, channel|
|
179
191
|
if channel && channel['name'] == room_id
|
180
192
|
msg = "<##{id}|#{room_id}>"
|
181
193
|
end
|
@@ -200,7 +212,7 @@ module Ruboty
|
|
200
212
|
resp = client.channels_list
|
201
213
|
if resp['ok']
|
202
214
|
resp['channels'].each do |channel|
|
203
|
-
@
|
215
|
+
@channel_info_caches[channel['id']] = channel
|
204
216
|
end
|
205
217
|
end
|
206
218
|
end
|
@@ -216,7 +228,7 @@ module Ruboty
|
|
216
228
|
end
|
217
229
|
|
218
230
|
def channel_info(channel_id)
|
219
|
-
@
|
231
|
+
@channel_info_caches[channel_id] ||= begin
|
220
232
|
resp = case channel_id
|
221
233
|
when /^C/
|
222
234
|
client.channels_info(channel: channel_id)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-slack_rtm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Kusano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|