slack-bot-server 0.4.1 → 0.4.2
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 +6 -0
- data/README.md +12 -3
- data/lib/slack_bot_server/bot.rb +9 -11
- data/lib/slack_bot_server/server.rb +2 -2
- data/lib/slack_bot_server/version.rb +1 -1
- data/slack_bot_server.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc965f9cb1a969b0ea3f1b58f467084aa308552
|
4
|
+
data.tar.gz: b409898adb366f5420d6403f83015b0c05a366d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0488b12f7bb24e7310e974e07f24d0775bc4d977783066c94bd0460c27e36d56540807cbd498362d6b163cff19aff16266388dacd8f43123b056031288cba89
|
7
|
+
data.tar.gz: c6a89f534877ea4ca3433ad8ee2e732f2fc4c848750f90a6e7a129a98d4d0e724e2d0af7b027ba5b8b44f452d0f1514246d68e58bb3463acf7ab875a0bb3b55f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ This server is designed to hopefully make it easier to manage running bots for m
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem '
|
14
|
+
gem 'slack-bot-server'
|
15
15
|
```
|
16
16
|
|
17
17
|
And then execute:
|
@@ -20,7 +20,7 @@ And then execute:
|
|
20
20
|
|
21
21
|
Or install it yourself as:
|
22
22
|
|
23
|
-
$ gem install
|
23
|
+
$ gem install slack-bot-server
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
@@ -53,7 +53,16 @@ end
|
|
53
53
|
server.start
|
54
54
|
```
|
55
55
|
|
56
|
-
|
56
|
+
If you're using Rails, I'd suggest you create your script as `bin/slack_server` (i.e. a file called `slack_server` in the `bin` directory you already have)
|
57
|
+
|
58
|
+
Running this script will start a server and keep it running; you may wish to use a tool like [Foreman](http://ddollar.github.io/foreman/) to actually start it and manage it in production. Here's a sample `Procfile`:
|
59
|
+
|
60
|
+
```
|
61
|
+
web: bundle exec rails server
|
62
|
+
slack_server: bundle exec rails runner bin/slack_server
|
63
|
+
```
|
64
|
+
|
65
|
+
By running the `bin/slack_server` script using `rails runner`, your bots get access to all the Rails models and libraries even when they are running outside of the main Rails web processes.
|
57
66
|
|
58
67
|
### Advanced server example
|
59
68
|
|
data/lib/slack_bot_server/bot.rb
CHANGED
@@ -37,8 +37,8 @@ class SlackBotServer::Bot
|
|
37
37
|
|
38
38
|
attr_reader :key, :token, :client
|
39
39
|
|
40
|
-
# Raised if
|
41
|
-
class
|
40
|
+
# Raised if there was an error while trying to connect to Slack
|
41
|
+
class ConnectionError < Slack::Web::Api::Error; end
|
42
42
|
|
43
43
|
# Create a new bot.
|
44
44
|
# This is normally called from within the block passed to
|
@@ -51,13 +51,10 @@ class SlackBotServer::Bot
|
|
51
51
|
def initialize(token:, key: nil)
|
52
52
|
@token = token
|
53
53
|
@key = key || @token
|
54
|
-
@client = ::Slack::RealTime::Client.new(token: @token)
|
55
54
|
@im_channels = []
|
56
55
|
@channels = []
|
57
56
|
@connected = false
|
58
57
|
@running = false
|
59
|
-
|
60
|
-
raise InvalidToken unless @client.web_client.auth_test['ok']
|
61
58
|
end
|
62
59
|
|
63
60
|
# Returns the username (for @ replying) of the bot user we are connected as,
|
@@ -151,6 +148,7 @@ class SlackBotServer::Bot
|
|
151
148
|
# when it is ready for the bot to connect
|
152
149
|
# @see Server#start
|
153
150
|
def start
|
151
|
+
@client = ::Slack::RealTime::Client.new(token: @token)
|
154
152
|
@running = true
|
155
153
|
|
156
154
|
@client.on :open do |event|
|
@@ -192,6 +190,8 @@ class SlackBotServer::Bot
|
|
192
190
|
end
|
193
191
|
|
194
192
|
@client.start_async
|
193
|
+
rescue Slack::Web::Api::Error => e
|
194
|
+
raise ConnectionError.new(e.message, e.response)
|
195
195
|
end
|
196
196
|
|
197
197
|
# Stops the bot from running. You should not call this method; instead
|
@@ -353,9 +353,7 @@ class SlackBotServer::Bot
|
|
353
353
|
end
|
354
354
|
|
355
355
|
on :finish do
|
356
|
-
if @running
|
357
|
-
start
|
358
|
-
end
|
356
|
+
start if @running
|
359
357
|
end
|
360
358
|
|
361
359
|
# Returns a String representation of this {Bot}
|
@@ -396,11 +394,11 @@ class SlackBotServer::Bot
|
|
396
394
|
end
|
397
395
|
|
398
396
|
def load_channels
|
399
|
-
|
397
|
+
debug "Loading channels"
|
400
398
|
@im_channels = @client.ims
|
401
|
-
|
399
|
+
debug im_channels: @im_channels
|
402
400
|
@channels = @client.channels.select { |d| d['is_member'] == true }
|
403
|
-
|
401
|
+
debug channels: @channels
|
404
402
|
end
|
405
403
|
|
406
404
|
def channel(id)
|
@@ -99,7 +99,7 @@ class SlackBotServer::Server
|
|
99
99
|
# @see #on_add
|
100
100
|
def add_bot(*args)
|
101
101
|
bot = @add_proc.call(*args)
|
102
|
-
if bot.respond_to?(:start)
|
102
|
+
if bot.respond_to?(:start) && !bot(bot.key)
|
103
103
|
log "adding bot #{bot}"
|
104
104
|
@bots[bot.key.to_sym] = bot
|
105
105
|
bot.start if @running
|
@@ -136,7 +136,7 @@ class SlackBotServer::Server
|
|
136
136
|
def process_instruction(instruction)
|
137
137
|
type, *args = instruction
|
138
138
|
bot_key = args.shift
|
139
|
-
if type == :add_bot
|
139
|
+
if type.to_sym == :add_bot
|
140
140
|
log "adding bot: #{bot_key} #{args.inspect}"
|
141
141
|
add_bot(bot_key, *args)
|
142
142
|
else
|
data/slack_bot_server.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "slack-ruby-client", "~> 0.5"
|
22
|
+
spec.add_dependency "slack-ruby-client", "~> 0.5.3"
|
23
23
|
spec.add_dependency "faye-websocket", "~> 0.10"
|
24
24
|
spec.add_dependency "multi_json"
|
25
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-bot-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Adam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.5.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.5.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faye-websocket
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|