lita-slack 1.4.0 → 1.5.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 +2 -1
- data/lib/lita/adapters/slack/api.rb +4 -1
- data/lib/lita/adapters/slack/message_handler.rb +65 -0
- data/lib/lita/adapters/slack/room_creator.rb +19 -0
- data/lib/lita/adapters/slack/rtm_connection.rb +2 -0
- data/lib/lita/adapters/slack/slack_channel.rb +37 -0
- data/lib/lita/adapters/slack/team_data.rb +1 -1
- data/lita-slack.gemspec +2 -2
- data/spec/lita/adapters/slack/api_spec.rb +3 -1
- data/spec/lita/adapters/slack/message_handler_spec.rb +333 -0
- data/spec/lita/adapters/slack/room_creator_spec.rb +31 -0
- data/spec/lita/adapters/slack/rtm_connection_spec.rb +11 -1
- data/spec/lita/adapters/slack/slack_channel_spec.rb +40 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3600cd068e9891e914063b341e384e1e66c117
|
4
|
+
data.tar.gz: 0dcbfb0f922578b75ec22a835d7d77e7072c22fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b285b424783c62984f4f31b1dec16937c6ea8807f74b428fd769b83d60dc5ca2793c695ed4ae79efb52c0079c9ddfb813782379aa72c1ebf325a73f3eb17a9b
|
7
|
+
data.tar.gz: 67da2107713a27eab01d59b19c9256593778341b437c7aeb6f6f832f05eafb359038aa36466fbccd0b5841481712048a4b7590aabd26824b1fc954bb8390e512
|
data/README.md
CHANGED
@@ -47,7 +47,8 @@ Lita will join your default channel after initial setup. To have it join additio
|
|
47
47
|
|
48
48
|
* `:connected` - When the robot has connected to Slack. No payload.
|
49
49
|
* `:disconnected` - When the robot has disconnected from Slack. No payload.
|
50
|
-
* `:slack_user_created` - When the robot creates/updates a user's info - name, mention name, etc
|
50
|
+
* `:slack_user_created` - When the robot creates/updates a user's info - name, mention name, etc., as directed by Slack. The payload has a single object, a `Lita::Slack::Adapters::SlackUser` object, under the `:slack_user` key.
|
51
|
+
* `:slack_channel_created` - When the robot creates/updates a channel's or group's info, as directed by Slack. The payload has a single object, a `Lita::Slack::Adapters::SlackChannel` object, under the `:slack_channel` key.
|
51
52
|
|
52
53
|
## License
|
53
54
|
|
@@ -3,6 +3,7 @@ require 'faraday'
|
|
3
3
|
require 'lita/adapters/slack/team_data'
|
4
4
|
require 'lita/adapters/slack/slack_im'
|
5
5
|
require 'lita/adapters/slack/slack_user'
|
6
|
+
require 'lita/adapters/slack/slack_channel'
|
6
7
|
|
7
8
|
module Lita
|
8
9
|
module Adapters
|
@@ -30,7 +31,9 @@ module Lita
|
|
30
31
|
SlackIM.from_data_array(response_data["ims"]),
|
31
32
|
SlackUser.from_data(response_data["self"]),
|
32
33
|
SlackUser.from_data_array(response_data["users"]),
|
33
|
-
response_data["
|
34
|
+
SlackChannel.from_data_array(response_data["channels"]) +
|
35
|
+
SlackChannel.from_data_array(response_data["groups"]),
|
36
|
+
response_data["url"],
|
34
37
|
)
|
35
38
|
end
|
36
39
|
|
@@ -19,6 +19,8 @@ module Lita
|
|
19
19
|
handle_user_change
|
20
20
|
when "bot_added", "bot_changed"
|
21
21
|
handle_bot_change
|
22
|
+
when "channel_created", "channel_rename", "group_rename"
|
23
|
+
handle_channel_change
|
22
24
|
when "error"
|
23
25
|
handle_error
|
24
26
|
else
|
@@ -38,6 +40,8 @@ module Lita
|
|
38
40
|
data["text"].sub(/^\s*<@#{robot_id}>/, "@#{robot.mention_name}")
|
39
41
|
end
|
40
42
|
|
43
|
+
normalized_message = remove_formatting(normalized_message) unless normalized_message.nil?
|
44
|
+
|
41
45
|
attachment_text = Array(data["attachments"]).map do |attachment|
|
42
46
|
attachment["text"]
|
43
47
|
end
|
@@ -45,6 +49,62 @@ module Lita
|
|
45
49
|
([normalized_message] + attachment_text).compact.join("\n")
|
46
50
|
end
|
47
51
|
|
52
|
+
def remove_formatting(message)
|
53
|
+
# https://api.slack.com/docs/formatting
|
54
|
+
message = message.gsub(/
|
55
|
+
< # opening angle bracket
|
56
|
+
(?<type>[@#!])? # link type
|
57
|
+
(?<link>[^>|]+) # link
|
58
|
+
(?:\| # start of |label (optional)
|
59
|
+
(?<label>[^>]+) # label
|
60
|
+
)? # end of label
|
61
|
+
> # closing angle bracket
|
62
|
+
/ix) do
|
63
|
+
link = Regexp.last_match[:link]
|
64
|
+
label = Regexp.last_match[:label]
|
65
|
+
|
66
|
+
case Regexp.last_match[:type]
|
67
|
+
when '@'
|
68
|
+
if label
|
69
|
+
label
|
70
|
+
else
|
71
|
+
user = User.find_by_id(link)
|
72
|
+
if user
|
73
|
+
"@#{user.name}"
|
74
|
+
else
|
75
|
+
"@#{link}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
when '#'
|
80
|
+
if label
|
81
|
+
label
|
82
|
+
else
|
83
|
+
channel = Lita::Room.find_by_id(link)
|
84
|
+
if channel
|
85
|
+
"\##{channel.name}"
|
86
|
+
else
|
87
|
+
"\##{link}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
when '!'
|
92
|
+
"@#{link}" if ['channel', 'group', 'everyone'].include? link
|
93
|
+
else
|
94
|
+
link = link.gsub /^mailto:/, ''
|
95
|
+
if label && !(link.include? label)
|
96
|
+
"#{label} (#{link})"
|
97
|
+
else
|
98
|
+
label == nil ? link : label
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
message.gsub('<', '<')
|
103
|
+
.gsub('>', '>')
|
104
|
+
.gsub('&', '&')
|
105
|
+
|
106
|
+
end
|
107
|
+
|
48
108
|
def channel
|
49
109
|
data["channel"]
|
50
110
|
end
|
@@ -71,6 +131,11 @@ module Lita
|
|
71
131
|
UserCreator.create_user(SlackUser.from_data(data["bot"]), robot, robot_id)
|
72
132
|
end
|
73
133
|
|
134
|
+
def handle_channel_change
|
135
|
+
log.debug("Updating channel data.")
|
136
|
+
RoomCreator.create_room(SlackChannel.from_data(data["channel"]), robot)
|
137
|
+
end
|
138
|
+
|
74
139
|
def handle_error
|
75
140
|
error = data["error"]
|
76
141
|
code = error["code"]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Lita
|
2
|
+
module Adapters
|
3
|
+
class Slack < Adapter
|
4
|
+
class RoomCreator
|
5
|
+
class << self
|
6
|
+
def create_room(channel, robot)
|
7
|
+
Lita::Room.create_or_update(channel.id, name: channel.name)
|
8
|
+
|
9
|
+
robot.trigger(:slack_channel_created, slack_channel: channel)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_rooms(channels, robot)
|
13
|
+
channels.each { |channel| create_room(channel, robot) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -5,6 +5,7 @@ require 'lita/adapters/slack/api'
|
|
5
5
|
require 'lita/adapters/slack/event_loop'
|
6
6
|
require 'lita/adapters/slack/im_mapping'
|
7
7
|
require 'lita/adapters/slack/message_handler'
|
8
|
+
require 'lita/adapters/slack/room_creator'
|
8
9
|
require 'lita/adapters/slack/user_creator'
|
9
10
|
|
10
11
|
module Lita
|
@@ -27,6 +28,7 @@ module Lita
|
|
27
28
|
@robot_id = team_data.self.id
|
28
29
|
|
29
30
|
UserCreator.create_users(team_data.users, robot, robot_id)
|
31
|
+
RoomCreator.create_rooms(team_data.channels, robot)
|
30
32
|
end
|
31
33
|
|
32
34
|
def im_for(user_id)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Lita
|
2
|
+
module Adapters
|
3
|
+
class Slack < Adapter
|
4
|
+
class SlackChannel
|
5
|
+
class << self
|
6
|
+
def from_data(channel_data)
|
7
|
+
new(
|
8
|
+
channel_data['id'],
|
9
|
+
channel_data['name'],
|
10
|
+
channel_data['created'],
|
11
|
+
channel_data['creator'],
|
12
|
+
channel_data
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def from_data_array(channels_data)
|
17
|
+
channels_data.map { |channel_data| from_data(channel_data) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :id
|
22
|
+
attr_reader :name
|
23
|
+
attr_reader :created
|
24
|
+
attr_reader :creator
|
25
|
+
attr_reader :raw_data
|
26
|
+
|
27
|
+
def initialize(id, name, created, creator, raw_data)
|
28
|
+
@id = id
|
29
|
+
@name = name
|
30
|
+
@created = created
|
31
|
+
@creator = creator
|
32
|
+
@raw_data = raw_data
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lita-slack.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-slack"
|
3
|
-
spec.version = "1.
|
3
|
+
spec.version = "1.5.0"
|
4
4
|
spec.authors = ["Ken J.", "Jimmy Cuadra"]
|
5
5
|
spec.email = ["kenjij@gmail.com", "jimmy@jimmycuadra.com"]
|
6
6
|
spec.description = %q{Lita adapter for Slack.}
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.add_runtime_dependency "eventmachine"
|
18
18
|
spec.add_runtime_dependency "faraday"
|
19
19
|
spec.add_runtime_dependency "faye-websocket", ">= 0.8.0"
|
20
|
-
spec.add_runtime_dependency "lita", ">= 4.
|
20
|
+
spec.add_runtime_dependency "lita", ">= 4.4.2"
|
21
21
|
spec.add_runtime_dependency "multi_json"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -141,7 +141,9 @@ describe Lita::Adapters::Slack::API do
|
|
141
141
|
url: 'wss://example.com/',
|
142
142
|
users: [{ id: 'U023BECGF' }],
|
143
143
|
ims: [{ id: 'D024BFF1M' }],
|
144
|
-
self: { id: 'U12345678' }
|
144
|
+
self: { id: 'U12345678' },
|
145
|
+
channels: [{ id: 'C1234567890' }],
|
146
|
+
groups: [{ id: 'G0987654321' }],
|
145
147
|
})
|
146
148
|
end
|
147
149
|
|
@@ -3,8 +3,15 @@ require "spec_helper"
|
|
3
3
|
describe Lita::Adapters::Slack::MessageHandler, lita: true do
|
4
4
|
subject { described_class.new(robot, robot_id, data) }
|
5
5
|
|
6
|
+
before do
|
7
|
+
allow(robot).to receive(:trigger)
|
8
|
+
Lita::Adapters::Slack::RoomCreator.create_room(channel, robot)
|
9
|
+
end
|
10
|
+
|
6
11
|
let(:robot) { instance_double('Lita::Robot', name: 'Lita', mention_name: 'lita') }
|
7
12
|
let(:robot_id) { 'U12345678' }
|
13
|
+
let(:channel) { Lita::Adapters::Slack::SlackChannel.new('C2147483705', 'general', 1360782804, 'U023BECGF', raw_data) }
|
14
|
+
let(:raw_data) { Hash.new }
|
8
15
|
|
9
16
|
describe "#handle" do
|
10
17
|
context "with a hello message" do
|
@@ -140,6 +147,310 @@ describe Lita::Adapters::Slack::MessageHandler, lita: true do
|
|
140
147
|
subject.handle
|
141
148
|
end
|
142
149
|
end
|
150
|
+
|
151
|
+
describe "Removing message formatting" do
|
152
|
+
|
153
|
+
let(:user) { instance_double('Lita::User', id: 'U123',name: 'name', mention_name: 'label') }
|
154
|
+
|
155
|
+
context "does nothing if there are no user links" do
|
156
|
+
let(:data) do
|
157
|
+
{
|
158
|
+
"type" => "message",
|
159
|
+
"channel" => "C2147483705",
|
160
|
+
"text" => "foo",
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
it "removes formatting" do
|
165
|
+
expect(Lita::Message).to receive(:new).with(
|
166
|
+
robot,
|
167
|
+
"foo",
|
168
|
+
source
|
169
|
+
).and_return(message)
|
170
|
+
|
171
|
+
subject.handle
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
context "decodes entities" do
|
176
|
+
let(:data) do
|
177
|
+
{
|
178
|
+
"type" => "message",
|
179
|
+
"channel" => "C2147483705",
|
180
|
+
"text" => "foo > & < >&<",
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
it "removes formatting" do
|
185
|
+
expect(Lita::Message).to receive(:new).with(
|
186
|
+
robot,
|
187
|
+
"foo > & < >&<",
|
188
|
+
source
|
189
|
+
).and_return(message)
|
190
|
+
|
191
|
+
subject.handle
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
context "changes <@123> links to @name" do
|
197
|
+
let(:data) do
|
198
|
+
{
|
199
|
+
"type" => "message",
|
200
|
+
"channel" => "C2147483705",
|
201
|
+
"text" => "foo <@123> bar",
|
202
|
+
}
|
203
|
+
end
|
204
|
+
it "removes formatting" do
|
205
|
+
expect(Lita::Message).to receive(:new).with(
|
206
|
+
robot,
|
207
|
+
"foo @name bar",
|
208
|
+
source
|
209
|
+
).and_return(message)
|
210
|
+
|
211
|
+
subject.handle
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "changes <@U123|label> links to label" do
|
216
|
+
let(:data) do
|
217
|
+
{
|
218
|
+
"type" => "message",
|
219
|
+
"channel" => "C2147483705",
|
220
|
+
"text" => "foo <@123|label> bar",
|
221
|
+
}
|
222
|
+
end
|
223
|
+
it "removes formatting" do
|
224
|
+
expect(Lita::Message).to receive(:new).with(
|
225
|
+
robot,
|
226
|
+
"foo label bar",
|
227
|
+
source
|
228
|
+
).and_return(message)
|
229
|
+
|
230
|
+
subject.handle
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "changes <#C2147483705> links to #general" do
|
235
|
+
let(:data) do
|
236
|
+
{
|
237
|
+
"type" => "message",
|
238
|
+
"channel" => "C2147483705",
|
239
|
+
"text" => "foo <#C2147483705> bar",
|
240
|
+
}
|
241
|
+
end
|
242
|
+
it "removes formatting" do
|
243
|
+
expect(Lita::Message).to receive(:new).with(
|
244
|
+
robot,
|
245
|
+
"foo #general bar",
|
246
|
+
source
|
247
|
+
).and_return(message)
|
248
|
+
|
249
|
+
subject.handle
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context "changes <#C2147483705|genral> links to #general" do
|
254
|
+
let(:data) do
|
255
|
+
{
|
256
|
+
"type" => "message",
|
257
|
+
"channel" => "C2147483705",
|
258
|
+
"text" => "foo <#C2147483705|general> bar",
|
259
|
+
}
|
260
|
+
end
|
261
|
+
it "removes formatting" do
|
262
|
+
expect(Lita::Message).to receive(:new).with(
|
263
|
+
robot,
|
264
|
+
"foo general bar",
|
265
|
+
source
|
266
|
+
).and_return(message)
|
267
|
+
|
268
|
+
subject.handle
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context "changes <!everyone> links to @everyone" do
|
273
|
+
let(:data) do
|
274
|
+
{
|
275
|
+
"type" => "message",
|
276
|
+
"channel" => "C2147483705",
|
277
|
+
"text" => "foo <!everyone> bar",
|
278
|
+
}
|
279
|
+
end
|
280
|
+
it "removes formatting" do
|
281
|
+
expect(Lita::Message).to receive(:new).with(
|
282
|
+
robot,
|
283
|
+
"foo @everyone bar",
|
284
|
+
source
|
285
|
+
).and_return(message)
|
286
|
+
subject.handle
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context "changes <!channel> links to @channel" do
|
291
|
+
let(:data) do
|
292
|
+
{
|
293
|
+
"type" => "message",
|
294
|
+
"channel" => "C2147483705",
|
295
|
+
"text" => "foo <!channel> bar",
|
296
|
+
}
|
297
|
+
end
|
298
|
+
it "removes formatting" do
|
299
|
+
expect(Lita::Message).to receive(:new).with(
|
300
|
+
robot,
|
301
|
+
"foo @channel bar",
|
302
|
+
source
|
303
|
+
).and_return(message)
|
304
|
+
subject.handle
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context "changes <!group> links to @group" do
|
309
|
+
let(:data) do
|
310
|
+
{
|
311
|
+
"type" => "message",
|
312
|
+
"channel" => "C2147483705",
|
313
|
+
"text" => "foo <!group> bar",
|
314
|
+
}
|
315
|
+
end
|
316
|
+
it "removes formatting" do
|
317
|
+
expect(Lita::Message).to receive(:new).with(
|
318
|
+
robot,
|
319
|
+
"foo @group bar",
|
320
|
+
source
|
321
|
+
).and_return(message)
|
322
|
+
subject.handle
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context "removes remove formatting around <http> links" do
|
327
|
+
let(:data) do
|
328
|
+
{
|
329
|
+
"type" => "message",
|
330
|
+
"channel" => "C2147483705",
|
331
|
+
"text" => "foo <http://www.example.com> bar",
|
332
|
+
}
|
333
|
+
end
|
334
|
+
it "removes formatting" do
|
335
|
+
expect(Lita::Message).to receive(:new).with(
|
336
|
+
robot,
|
337
|
+
"foo http://www.example.com bar",
|
338
|
+
source
|
339
|
+
).and_return(message)
|
340
|
+
subject.handle
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context "removes remove formatting around <http> links with a substring label" do
|
345
|
+
let(:data) do
|
346
|
+
{
|
347
|
+
"type" => "message",
|
348
|
+
"channel" => "C2147483705",
|
349
|
+
"text" => "foo <http://www.example.com|www.example.com> bar",
|
350
|
+
}
|
351
|
+
end
|
352
|
+
it "removes formatting" do
|
353
|
+
expect(Lita::Message).to receive(:new).with(
|
354
|
+
robot,
|
355
|
+
"foo www.example.com bar",
|
356
|
+
source
|
357
|
+
).and_return(message)
|
358
|
+
subject.handle
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context "remove formatting around <skype> links" do
|
363
|
+
let(:data) do
|
364
|
+
{
|
365
|
+
"type" => "message",
|
366
|
+
"channel" => "C2147483705",
|
367
|
+
"text" => "foo <skype:echo123?call> bar",
|
368
|
+
}
|
369
|
+
end
|
370
|
+
it "removes formatting" do
|
371
|
+
expect(Lita::Message).to receive(:new).with(
|
372
|
+
robot,
|
373
|
+
"foo skype:echo123?call bar",
|
374
|
+
source
|
375
|
+
).and_return(message)
|
376
|
+
subject.handle
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
context "remove formatting around <http> links with a label containing entities" do
|
381
|
+
let(:data) do
|
382
|
+
{
|
383
|
+
"type" => "message",
|
384
|
+
"channel" => "C2147483705",
|
385
|
+
"text" => "foo <http://www.example.com|label > & <> bar",
|
386
|
+
}
|
387
|
+
end
|
388
|
+
it "removes formatting" do
|
389
|
+
expect(Lita::Message).to receive(:new).with(
|
390
|
+
robot,
|
391
|
+
"foo label > & < (http://www.example.com) bar",
|
392
|
+
source
|
393
|
+
).and_return(message)
|
394
|
+
subject.handle
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context "remove formatting around around <mailto> links" do
|
399
|
+
let(:data) do
|
400
|
+
{
|
401
|
+
"type" => "message",
|
402
|
+
"channel" => "C2147483705",
|
403
|
+
"text" => "foo <mailto:name@example.com> bar",
|
404
|
+
}
|
405
|
+
end
|
406
|
+
it "removes formatting" do
|
407
|
+
expect(Lita::Message).to receive(:new).with(
|
408
|
+
robot,
|
409
|
+
"foo name@example.com bar",
|
410
|
+
source
|
411
|
+
).and_return(message)
|
412
|
+
subject.handle
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
context "remove formatting around <mailto> links with an email label" do
|
417
|
+
let(:data) do
|
418
|
+
{
|
419
|
+
"type" => "message",
|
420
|
+
"channel" => "C2147483705",
|
421
|
+
"text" => "foo <mailto:name@example.com|name@example.com> bar",
|
422
|
+
}
|
423
|
+
end
|
424
|
+
it "removes formatting" do
|
425
|
+
expect(Lita::Message).to receive(:new).with(
|
426
|
+
robot,
|
427
|
+
"foo name@example.com bar",
|
428
|
+
source
|
429
|
+
).and_return(message)
|
430
|
+
subject.handle
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
context "change multiple links at once" do
|
435
|
+
let(:data) do
|
436
|
+
{
|
437
|
+
"type" => "message",
|
438
|
+
"channel" => "C2147483705",
|
439
|
+
"text" => "foo <@U123|label> bar <#C2147483705> <!channel> <http://www.example.com|label>",
|
440
|
+
}
|
441
|
+
end
|
442
|
+
it "removes formatting" do
|
443
|
+
expect(Lita::Message).to receive(:new).with(
|
444
|
+
robot,
|
445
|
+
"foo label bar #general @channel label (http://www.example.com)",
|
446
|
+
source
|
447
|
+
).and_return(message)
|
448
|
+
subject.handle
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
|
453
|
+
end
|
143
454
|
end
|
144
455
|
|
145
456
|
context "with a message with an unsupported subtype" do
|
@@ -225,6 +536,28 @@ describe Lita::Adapters::Slack::MessageHandler, lita: true do
|
|
225
536
|
end
|
226
537
|
end
|
227
538
|
|
539
|
+
%w(channel_created channel_rename group_rename).each do |type|
|
540
|
+
context "with a #{type} message" do
|
541
|
+
before { allow(robot).to receive(:trigger) }
|
542
|
+
|
543
|
+
let(:data) do
|
544
|
+
{
|
545
|
+
"type" => type,
|
546
|
+
"channel" => {
|
547
|
+
"id" => "C01234567890",
|
548
|
+
"name" => "mychannel",
|
549
|
+
}
|
550
|
+
}
|
551
|
+
end
|
552
|
+
|
553
|
+
it "creates a new room for the channel" do
|
554
|
+
subject.handle
|
555
|
+
|
556
|
+
expect(Lita::Room.find_by_name("mychannel").id).to eq('C01234567890')
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
228
561
|
context "with an error message" do
|
229
562
|
let(:data) do
|
230
563
|
{
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Adapters::Slack::RoomCreator, lita: true do
|
4
|
+
describe ".create_rooms" do
|
5
|
+
before { allow(robot).to receive(:trigger) }
|
6
|
+
|
7
|
+
let(:robot) { instance_double('Lita::Robot') }
|
8
|
+
|
9
|
+
let(:group) do
|
10
|
+
Lita::Adapters::Slack::SlackChannel.from_data('id' => 'G1234567890', 'name' => 'mygroup')
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:room) do
|
14
|
+
Lita::Adapters::Slack::SlackChannel.from_data('id' => 'C1234567890', 'name' => 'mychannel')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a Room for each Slack channel" do
|
18
|
+
described_class.create_rooms([room] + [group], robot)
|
19
|
+
|
20
|
+
expect(Lita::Room.find_by_name("mychannel").id).to eq("C1234567890")
|
21
|
+
expect(Lita::Room.find_by_name("mygroup").id).to eq("G1234567890")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "triggers the slack_channel_created event" do
|
25
|
+
expect(robot).to receive(:trigger).with(:slack_channel_created, slack_channel: room)
|
26
|
+
expect(robot).to receive(:trigger).with(:slack_channel_created, slack_channel: group)
|
27
|
+
|
28
|
+
described_class.create_rooms([room] + [group], robot)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -15,11 +15,15 @@ describe Lita::Adapters::Slack::RTMConnection, lita: true do
|
|
15
15
|
let(:registry) { Lita::Registry.new }
|
16
16
|
let(:robot) { Lita::Robot.new(registry) }
|
17
17
|
let(:raw_user_data) { Hash.new }
|
18
|
+
let(:channel) { Lita::Adapters::Slack::SlackChannel.new('C2147483705', 'general', 1360782804, 'U023BECGF', raw_data) }
|
19
|
+
let(:raw_data) { Hash.new }
|
20
|
+
|
18
21
|
let(:rtm_start_response) do
|
19
22
|
Lita::Adapters::Slack::TeamData.new(
|
20
23
|
[],
|
21
24
|
Lita::Adapters::Slack::SlackUser.new('U12345678', 'carl', nil, raw_user_data),
|
22
25
|
[Lita::Adapters::Slack::SlackUser.new('U12345678', 'carl', '', raw_user_data)],
|
26
|
+
[channel],
|
23
27
|
"wss://example.com/"
|
24
28
|
)
|
25
29
|
end
|
@@ -47,6 +51,12 @@ describe Lita::Adapters::Slack::RTMConnection, lita: true do
|
|
47
51
|
|
48
52
|
described_class.build(robot, config)
|
49
53
|
end
|
54
|
+
|
55
|
+
it "creates rooms with the results of rtm.start data" do
|
56
|
+
expect(Lita::Adapters::Slack::RoomCreator).to receive(:create_rooms)
|
57
|
+
|
58
|
+
described_class.build(robot, config)
|
59
|
+
end
|
50
60
|
end
|
51
61
|
|
52
62
|
describe "#im_for" do
|
@@ -94,7 +104,7 @@ describe Lita::Adapters::Slack::RTMConnection, lita: true do
|
|
94
104
|
allow(Lita::Adapters::Slack::MessageHandler).to receive(:new).with(
|
95
105
|
robot,
|
96
106
|
'U12345678',
|
97
|
-
{}
|
107
|
+
{},
|
98
108
|
).and_return(message_handler)
|
99
109
|
|
100
110
|
expect(message_handler).to receive(:handle)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Adapters::Slack::SlackChannel do
|
4
|
+
let(:channel_data_1) do
|
5
|
+
{
|
6
|
+
"id" => "C2147483705",
|
7
|
+
"name" => "Room 1",
|
8
|
+
"created" => 1360782804,
|
9
|
+
"creator" => 'U023BECGF'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:channel_data_2) do
|
13
|
+
{
|
14
|
+
"id" => "C2147483706",
|
15
|
+
"name" => "Room 2",
|
16
|
+
"created" => 1360782805,
|
17
|
+
"creator" => 'U023BECGF'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
let(:channels_data) { [channel_data_1, channel_data_2] }
|
21
|
+
|
22
|
+
describe ".from_data_array" do
|
23
|
+
subject { described_class.from_data_array(channels_data) }
|
24
|
+
|
25
|
+
it "returns an object for each hash of Channel data" do
|
26
|
+
expect(subject.size).to eq(2)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates SlackIM objects" do
|
30
|
+
expect(subject[0].id).to eq('C2147483705')
|
31
|
+
expect(subject[0].name).to eq('Room 1')
|
32
|
+
expect(subject[0].creator).to eq('U023BECGF')
|
33
|
+
expect(subject[0].created).to eq(1360782804)
|
34
|
+
expect(subject[1].id).to eq('C2147483706')
|
35
|
+
expect(subject[1].name).to eq('Room 2')
|
36
|
+
expect(subject[1].creator).to eq('U023BECGF')
|
37
|
+
expect(subject[1].created).to eq(1360782805)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken J.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 4.
|
62
|
+
version: 4.4.2
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 4.
|
69
|
+
version: 4.4.2
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: multi_json
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,7 +185,9 @@ files:
|
|
185
185
|
- lib/lita/adapters/slack/event_loop.rb
|
186
186
|
- lib/lita/adapters/slack/im_mapping.rb
|
187
187
|
- lib/lita/adapters/slack/message_handler.rb
|
188
|
+
- lib/lita/adapters/slack/room_creator.rb
|
188
189
|
- lib/lita/adapters/slack/rtm_connection.rb
|
190
|
+
- lib/lita/adapters/slack/slack_channel.rb
|
189
191
|
- lib/lita/adapters/slack/slack_im.rb
|
190
192
|
- lib/lita/adapters/slack/slack_user.rb
|
191
193
|
- lib/lita/adapters/slack/team_data.rb
|
@@ -196,7 +198,9 @@ files:
|
|
196
198
|
- spec/lita/adapters/slack/event_loop_spec.rb
|
197
199
|
- spec/lita/adapters/slack/im_mapping_spec.rb
|
198
200
|
- spec/lita/adapters/slack/message_handler_spec.rb
|
201
|
+
- spec/lita/adapters/slack/room_creator_spec.rb
|
199
202
|
- spec/lita/adapters/slack/rtm_connection_spec.rb
|
203
|
+
- spec/lita/adapters/slack/slack_channel_spec.rb
|
200
204
|
- spec/lita/adapters/slack/slack_im_spec.rb
|
201
205
|
- spec/lita/adapters/slack/slack_user_spec.rb
|
202
206
|
- spec/lita/adapters/slack/user_creator_spec.rb
|
@@ -232,9 +236,12 @@ test_files:
|
|
232
236
|
- spec/lita/adapters/slack/event_loop_spec.rb
|
233
237
|
- spec/lita/adapters/slack/im_mapping_spec.rb
|
234
238
|
- spec/lita/adapters/slack/message_handler_spec.rb
|
239
|
+
- spec/lita/adapters/slack/room_creator_spec.rb
|
235
240
|
- spec/lita/adapters/slack/rtm_connection_spec.rb
|
241
|
+
- spec/lita/adapters/slack/slack_channel_spec.rb
|
236
242
|
- spec/lita/adapters/slack/slack_im_spec.rb
|
237
243
|
- spec/lita/adapters/slack/slack_user_spec.rb
|
238
244
|
- spec/lita/adapters/slack/user_creator_spec.rb
|
239
245
|
- spec/lita/adapters/slack_spec.rb
|
240
246
|
- spec/spec_helper.rb
|
247
|
+
has_rdoc:
|