ruboty-slack_rtm 2.7.2 → 2.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9d460a6a2f0c7a73b56abe1111e76ed33ddbe450
4
- data.tar.gz: 0ee042b91b916d03bc3ef87edcc55234294338b7
2
+ SHA256:
3
+ metadata.gz: 9dc29f6cef0ea1e5e3886e70d33f4d9e5731e086f70d39088a995a9367dc27cb
4
+ data.tar.gz: 128bbc4de539fa9abe0b227fbdc0f152fc66b815cd1c73164215bc11381e350f
5
5
  SHA512:
6
- metadata.gz: 41a30fff610dd812f016081d4a77f0baaba4f0e82e0c5f83e9e09c7d4db4bef0768f930cd1ad1a0f47094010f9d13153bf103cee9f6c672d97bbdd6e35cb5c17
7
- data.tar.gz: d76ad144279c88facfa5ef7d5c51a33e0753390f998e5442aab9ad1448061780fa1b484db076cda5a4ecce12bdb909011a17a76d05682e0e94708eb55d25035a
6
+ metadata.gz: deb25f3219be6672b16552d48aeb855dcffb24a0df7b4ecc97bf489b73f0e3963ae559f26e40fc1b72c8214033922c9498554d5d416eb1507dc05cb76e865c4d
7
+ data.tar.gz: 7df223ed0d7cfbc57e932a4534a3ff37796db4d67f6d5490d59ddb109ba040279f3d01502013fca31909dc31ef971ad7c5393af94eaad5ab5fbd3ff94acd57c9
data/README.md CHANGED
@@ -16,6 +16,7 @@ gem 'ruboty-slack_rtm'
16
16
  - `SLACK_EXPOSE_CHANNEL_NAME`: if this set to 1, `message.to` will be channel name instead of id (optional)
17
17
  - `SLACK_IGNORE_GENERAL`: if this set to 1, bot ignores all messages on #general channel (optional)
18
18
  - `SLACK_GENERAL_NAME`: Set general channel name if your Slack changes general name (optional)
19
+ - `SLACK_AUTO_RECONNECT`: Enable auto reconnect if rtm disconnected by Slack (optional)
19
20
 
20
21
  This adapter doesn't require a real user account. Using with bot integration's API token is recommended.
21
22
  See: https://api.slack.com/bot-users
@@ -12,12 +12,12 @@ module Ruboty
12
12
  env :SLACK_IGNORE_BOT_MESSAGE, "If this set to 1, bot ignores bot_messages", optional: true
13
13
  env :SLACK_IGNORE_GENERAL, "if this set to 1, bot ignores all messages on #general channel", optional: true
14
14
  env :SLACK_GENERAL_NAME, "Set general channel name if your Slack changes general name", optional: true
15
+ env :SLACK_AUTO_RECONNECT, "Enable auto reconnect", optional: true
15
16
 
16
17
  def run
17
18
  init
18
19
  bind
19
20
  connect
20
- # TODO: reconnect
21
21
  end
22
22
 
23
23
  def say(message)
@@ -47,6 +47,10 @@ module Ruboty
47
47
  end
48
48
  end
49
49
 
50
+ def add_reaction(reaction, channel_id, timestamp)
51
+ client.reactions_add(name: reaction, channel: channel_id, timestamp: timestamp)
52
+ end
53
+
50
54
  private
51
55
 
52
56
  def init
@@ -77,12 +81,17 @@ module Ruboty
77
81
  end
78
82
  end
79
83
 
80
- realtime.main_loop
84
+ loop do
85
+ realtime.main_loop rescue nil
86
+ break unless ENV['SLACK_AUTO_RECONNECT']
87
+ @url = null
88
+ @realtime = null
89
+ end
81
90
  end
82
91
 
83
92
  def url
84
93
  @url ||= begin
85
- response = Net::HTTP.post_form(URI.parse('https://slack.com/api/rtm.start'), token: ENV['SLACK_TOKEN'])
94
+ response = Net::HTTP.post_form(URI.parse('https://slack.com/api/rtm.connect'), token: ENV['SLACK_TOKEN'])
86
95
  body = JSON.parse(response.body)
87
96
 
88
97
  URI.parse(body['url'])
@@ -0,0 +1,9 @@
1
+ module Ruboty
2
+ class Message
3
+ def add_reaction(reaction)
4
+ channel_id = @original[:channel]["id"]
5
+ timestamp = @original[:time].to_f
6
+ robot.add_reaction(reaction, channel_id, timestamp)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Ruboty
2
+ class Robot
3
+ delegate :add_reaction, to: :adapter
4
+
5
+ def add_reaction(reaction, channel_id, timestamp)
6
+ adapter.add_reaction(reaction, channel_id, timestamp)
7
+ true
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
1
  require 'ruboty/slack_rtm/version'
2
2
  require 'ruboty/slack_rtm/client'
3
3
  require 'ruboty/adapters/slack_rtm'
4
+ require_relative 'robot'
5
+ require_relative 'message'
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module SlackRTM
3
- VERSION = '2.7.2'
3
+ VERSION = '2.9.0'
4
4
  end
5
5
  end
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rubocop', '>= 0.28.0'
24
24
 
25
25
  spec.add_dependency 'ruboty', '>= 1.1.4'
26
- spec.add_dependency 'slack-api', '~> 1.2'
26
+ spec.add_dependency 'slack-api', '~> 1.6'
27
27
  spec.add_dependency 'websocket-client-simple', '~> 0.3.0'
28
28
  end
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: 2.7.2
4
+ version: 2.9.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: 2017-02-14 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.2'
75
+ version: '1.6'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.2'
82
+ version: '1.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: websocket-client-simple
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,8 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - lib/ruboty/adapters/slack_rtm.rb
111
+ - lib/ruboty/message.rb
112
+ - lib/ruboty/robot.rb
111
113
  - lib/ruboty/slack_rtm.rb
112
114
  - lib/ruboty/slack_rtm/client.rb
113
115
  - lib/ruboty/slack_rtm/version.rb
@@ -132,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  version: '0'
133
135
  requirements: []
134
136
  rubyforge_project:
135
- rubygems_version: 2.5.1
137
+ rubygems_version: 2.7.6
136
138
  signing_key:
137
139
  specification_version: 4
138
140
  summary: Slack real time messaging adapter for Ruboty