grape-slack-bot 1.8.1 → 2.0.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 +47 -22
- data/README.md +147 -118
- data/grape-slack-bot.gemspec +15 -10
- data/lib/slack_bot/api_client.rb +145 -10
- data/lib/slack_bot/args.rb +2 -0
- data/lib/slack_bot/callback.rb +29 -4
- data/lib/slack_bot/callback_storage.rb +3 -3
- data/lib/slack_bot/config.rb +4 -0
- data/lib/slack_bot/errors.rb +20 -0
- data/lib/slack_bot/grape_extension.rb +76 -21
- data/lib/slack_bot/interaction.rb +5 -1
- data/lib/slack_bot/logger.rb +15 -0
- data/lib/slack_bot/menu_options.rb +4 -0
- data/lib/slack_bot/view.rb +6 -2
- data/lib/slack_bot.rb +4 -1
- data/sig/slack_bot.rbs +379 -0
- metadata +114 -34
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a6e6b020caecc8ee5a8520f7f6f76107d006ca88070189e0cf23428bc10d2e7
|
|
4
|
+
data.tar.gz: 02aa101bb61f5ad8fc96c9d295e75fe032e1d088d90d3d49b008e09551f53b8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3217a763efe6f6b101067c422029450e59efee9ea47d611bef1bd06a166a99404c1243955a3e42a5e9f31a78e9c3cbdd051d324fcd3b0b2414812da3d84f7336
|
|
7
|
+
data.tar.gz: 3faca964608cb59b26ab6712c4eec82356f0ce761adfb4811d282e7d0051f9cdc58ac6958634feef2e24563b800a38259756a5847e0c6b0d8a3b2b6c62cb74b5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,92 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 2.0.0 (2025-11-06)
|
|
4
|
+
|
|
5
|
+
- Fix status code handling for empty/false responses - ensure 200 OK instead of 204 No Content
|
|
6
|
+
- Fix closure variable scoping issues in helper methods using `define_method` for proper variable capture
|
|
7
|
+
- Fix missing `interaction_klass` method handling in `handle_block_actions_view` using `respond_to?` check
|
|
8
|
+
- Fix `resolve_user_session` method availability in test contexts
|
|
9
|
+
- Improve error handling for handler classes without `interaction_klass` method
|
|
10
|
+
- Add timestamp validation to signature verification to prevent replay attacks (security improvement)
|
|
11
|
+
- Add comprehensive error handling for JSON parsing failures
|
|
12
|
+
- Add network error handling for all Slack API client methods (Faraday exceptions)
|
|
13
|
+
- Add custom error classes: `CallbackUserMismatchError`, `InvalidPayloadError`, `SlackApiError`, `UnknownActionTypeError`
|
|
14
|
+
- Replace all generic `raise` statements with custom error classes
|
|
15
|
+
- Add error handling for unknown event types in events endpoint
|
|
16
|
+
- Simplify `verify_current_user!` method for better readability
|
|
17
|
+
- Improve error messages and error handling throughout the codebase
|
|
18
|
+
- Add RBS type signatures for better type checking and IDE support
|
|
19
|
+
- Add StandardRB configuration for consistent code style
|
|
20
|
+
- Update gemspec to include RBS signature files
|
|
21
|
+
|
|
22
|
+
## 1.8.2 (2024-12-17)
|
|
23
|
+
|
|
24
|
+
- Update Slack API client to have more chat methods
|
|
25
|
+
|
|
26
|
+
## 1.8.1 (2024-12-08)
|
|
2
27
|
|
|
3
28
|
- Clean up dependencies
|
|
4
29
|
|
|
5
|
-
|
|
30
|
+
## 1.8.0 (2024-05-24)
|
|
6
31
|
|
|
7
32
|
- Rewind incoming request body when reading it
|
|
8
33
|
|
|
9
|
-
|
|
34
|
+
## 1.7.2 (2024-05-16)
|
|
10
35
|
|
|
11
36
|
- Fix request secret headers parsing
|
|
12
37
|
|
|
13
|
-
|
|
38
|
+
## 1.7.0 (2024-05-16)
|
|
14
39
|
|
|
15
40
|
- Add `usersList` and `chat.postEphemeral` methods
|
|
16
41
|
- Core upgrades and clean up
|
|
17
42
|
|
|
18
|
-
|
|
43
|
+
## 1.6.3 (2023-08-30)
|
|
19
44
|
|
|
20
45
|
- Implement callback for modals
|
|
21
46
|
|
|
22
|
-
|
|
47
|
+
## 1.6.2 (2023-08-30)
|
|
23
48
|
|
|
24
49
|
- Allow custom handler names for associating with interactions
|
|
25
50
|
|
|
26
|
-
|
|
51
|
+
## 1.6.1 (2023-08-30)
|
|
27
52
|
|
|
28
53
|
- Unify command, event and interaction rendering methods
|
|
29
54
|
|
|
30
|
-
|
|
55
|
+
## 1.6.0 (2023-08-30)
|
|
31
56
|
|
|
32
57
|
- Better visibility for missing handlers
|
|
33
58
|
|
|
34
|
-
|
|
59
|
+
## 1.5.8 (2023-08-30)
|
|
35
60
|
|
|
36
61
|
- Fix event registration
|
|
37
62
|
- Update event interaction example
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
## 1.5.7 (2023-08-30)
|
|
40
65
|
|
|
41
66
|
- Raise error if handler class not resolved
|
|
42
67
|
- App home interaction example added
|
|
43
68
|
- Callback logic and usage fixed
|
|
44
69
|
- Views improvements
|
|
45
70
|
|
|
46
|
-
|
|
71
|
+
## 1.5.0 (2023-08-30)
|
|
47
72
|
|
|
48
73
|
- Complete upgrade of callback storage logic
|
|
49
74
|
|
|
50
|
-
|
|
75
|
+
## 1.4.0 (2023-08-30)
|
|
51
76
|
|
|
52
77
|
- Allow setting callback expiration time on save and update
|
|
53
78
|
|
|
54
|
-
|
|
79
|
+
## 1.3.0 (2023-08-30)
|
|
55
80
|
|
|
56
81
|
- Clean up callback arguments, remove unused `method_name`
|
|
57
82
|
|
|
58
|
-
|
|
83
|
+
## 1.2.3 (2023-08-30)
|
|
59
84
|
|
|
60
85
|
- Minor fix for Events API
|
|
61
86
|
|
|
62
|
-
|
|
87
|
+
## 1.2.2 (2023-08-30)
|
|
63
88
|
|
|
64
89
|
- `SlackBot::Callback.find` method will raise `SlackBot::Errors::CallbackNotFound` if callback is not resolved or has wrong data
|
|
65
90
|
|
|
66
|
-
|
|
91
|
+
## 1.2.1 (2023-08-30)
|
|
67
92
|
|
|
68
93
|
- Extract `SlackBot::Logger` to separate file
|
|
69
94
|
|
|
70
|
-
|
|
95
|
+
## 1.2.0 (2023-08-30)
|
|
71
96
|
|
|
72
97
|
- Remove `Rails.logger` dependency, make logger configurable
|
|
73
98
|
|
|
74
|
-
|
|
99
|
+
## 1.1.0 (2023-08-30)
|
|
75
100
|
|
|
76
101
|
- Set minimum ruby version requirement to 2.5.0
|
|
77
102
|
|
|
78
|
-
|
|
103
|
+
## 1.0.5 (2023-08-29)
|
|
79
104
|
|
|
80
105
|
- Add superclass `SlackBot::Error` for all errors
|
|
81
106
|
|
|
82
|
-
|
|
107
|
+
## 1.0.2 (2023-08-29)
|
|
83
108
|
|
|
84
109
|
- Soften dependencies version requirements
|
|
85
110
|
|
|
86
|
-
|
|
111
|
+
## 1.0.1 (2023-08-29)
|
|
87
112
|
|
|
88
113
|
- Bump Faraday version to 2.7.10
|
|
89
114
|
|
|
90
|
-
|
|
115
|
+
## 1.0.0 (2023-08-29)
|
|
91
116
|
|
|
92
117
|
- Initial version
|
data/README.md
CHANGED
|
@@ -2,31 +2,105 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/grape-slack-bot) [](https://github.com/amkisko/grape-slack-bot.rb/actions/workflows/test.yml) [](https://codecov.io/gh/amkisko/grape-slack-bot.rb)
|
|
4
4
|
|
|
5
|
-
Extensible Slack bot implementation gem for [ruby-grape](https://github.com/ruby-grape/grape)
|
|
5
|
+
Extensible Slack bot implementation gem for [ruby-grape](https://github.com/ruby-grape/grape) with support for slash commands, interactive components, events, and views.
|
|
6
6
|
|
|
7
7
|
Sponsored by [Kisko Labs](https://www.kiskolabs.com).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<a href="https://www.kiskolabs.com">
|
|
10
|
+
<img src="kisko.svg" width="200" alt="Sponsored by Kisko Labs" />
|
|
11
|
+
</a>
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add to your Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem "grape-slack-bot"
|
|
14
19
|
```
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
Run `bundle install` or `gem install grape-slack-bot`.
|
|
22
|
+
|
|
23
|
+
## Integration with Other Gems
|
|
24
|
+
|
|
25
|
+
This gem works seamlessly with other gems in the ecosystem:
|
|
26
|
+
|
|
27
|
+
- **[grape-rails-logger](https://github.com/amkisko/grape-rails-logger.rb)**: Automatically logs all Slack bot requests with structured logging, including request metadata, performance metrics, and parameter filtering. Works automatically when included in your Grape API.
|
|
28
|
+
|
|
29
|
+
- **[activesupport-json_logging](https://github.com/amkisko/activesupport-json_logging.rb)**: Provides structured JSON logging for Rails applications. When used together, all Slack bot interactions are logged in JSON format, making it easy to parse and analyze logs.
|
|
30
|
+
|
|
31
|
+
Example setup with both gems:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
# config/initializers/json_logging.rb
|
|
35
|
+
Rails.application.configure do
|
|
36
|
+
base_logger = ActiveSupport::Logger.new($stdout)
|
|
37
|
+
json_logger = JsonLogging.new(base_logger)
|
|
38
|
+
config.logger = json_logger
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# app/api/slack_bot_api.rb
|
|
42
|
+
class SlackBotApi < Grape::API
|
|
43
|
+
include SlackBot::GrapeExtension
|
|
44
|
+
# grape-rails-logger automatically instruments requests
|
|
45
|
+
end
|
|
19
46
|
```
|
|
20
47
|
|
|
21
|
-
##
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
Create `app/api/slack_bot_api.rb`, it will contain bot configuration and endpoints setup:
|
|
22
51
|
|
|
23
52
|
```ruby
|
|
24
|
-
|
|
53
|
+
SlackBot::DevConsole.logger = Rails.logger
|
|
54
|
+
SlackBot::DevConsole.enabled = Rails.env.development?
|
|
55
|
+
SlackBot::Config.configure do
|
|
56
|
+
callback_storage Rails.cache
|
|
57
|
+
callback_user_finder ->(id) { User.active.find_by(id: id) }
|
|
58
|
+
|
|
59
|
+
# Register event handlers
|
|
60
|
+
event :app_home_opened, MySlackBot::AppHomeOpenedEvent
|
|
61
|
+
interaction MySlackBot::AppHomeInteraction
|
|
62
|
+
|
|
63
|
+
# Register slash command handlers
|
|
64
|
+
slash_command_endpoint :game, MySlackBot::Game::MenuCommand do
|
|
65
|
+
command :start, MySlackBot::Game::StartCommand
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class SlackBotApi < Grape::API
|
|
70
|
+
include SlackBot::GrapeExtension
|
|
71
|
+
|
|
72
|
+
helpers do
|
|
73
|
+
def config
|
|
74
|
+
SlackBot::Config.current_instance
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def resolve_user_session(team_id, user_id)
|
|
78
|
+
uid = OmniAuth::Strategies::SlackOpenid.generate_uid(team_id, user_id)
|
|
79
|
+
UserSession.find_by(uid: uid, provider: UserSession.slack_openid_provider)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def current_user_session
|
|
83
|
+
# NOTE: fetch_team_id and fetch_user_id are provided by SlackBot::GrapeHelpers
|
|
84
|
+
@current_user_session ||=
|
|
85
|
+
resolve_user_session(fetch_team_id, fetch_user_id)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def current_user_ip
|
|
89
|
+
request.env["action_dispatch.remote_ip"].to_s
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def current_user
|
|
93
|
+
@current_user ||= current_user_session&.user
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
25
97
|
```
|
|
26
98
|
|
|
27
|
-
|
|
99
|
+
In routes file `config/routes.rb` mount the API:
|
|
28
100
|
|
|
29
|
-
|
|
101
|
+
```ruby
|
|
102
|
+
mount SlackBotApi => "/api/slack"
|
|
103
|
+
```
|
|
30
104
|
|
|
31
105
|
## Concepts
|
|
32
106
|
|
|
@@ -44,7 +118,6 @@ Characteristics:
|
|
|
44
118
|
- Can trigger event in background
|
|
45
119
|
|
|
46
120
|
References:
|
|
47
|
-
- [slash_command.rb](lib/slack_bot/slash_command.rb)
|
|
48
121
|
- [Slash command documentation](https://api.slack.com/interactivity/slash-commands)
|
|
49
122
|
|
|
50
123
|
### Interactive component
|
|
@@ -56,7 +129,6 @@ Characteristics:
|
|
|
56
129
|
- Can be associated with event
|
|
57
130
|
|
|
58
131
|
References:
|
|
59
|
-
- [interaction.rb](lib/slack_bot/interaction.rb)
|
|
60
132
|
- [Interactive components documentation](https://api.slack.com/interactivity/handling)
|
|
61
133
|
|
|
62
134
|
### Event
|
|
@@ -64,7 +136,6 @@ References:
|
|
|
64
136
|
Event is a notification that is sent to bot app when something happens in Slack.
|
|
65
137
|
|
|
66
138
|
References:
|
|
67
|
-
- [event.rb](lib/slack_bot/event.rb)
|
|
68
139
|
- [Event documentation](https://api.slack.com/events-api)
|
|
69
140
|
|
|
70
141
|
### View
|
|
@@ -75,7 +146,6 @@ Characteristics:
|
|
|
75
146
|
- Can be associated with slash command, interactive component or event for using ready-made methods like `open_modal`, `update_modal` or `publish_view`
|
|
76
147
|
|
|
77
148
|
References:
|
|
78
|
-
- [view.rb](lib/slack_bot/view.rb)
|
|
79
149
|
- [App home documentation](https://api.slack.com/surfaces/app-home)
|
|
80
150
|
- [Messages documentation](https://api.slack.com/messaging)
|
|
81
151
|
- [Modals documentation](https://api.slack.com/surfaces/modals)
|
|
@@ -93,98 +163,30 @@ Callback is a class for managing interactive component state and handling intera
|
|
|
93
163
|
|
|
94
164
|
Example uses `Rails.cache` for storing interactive component state, use `CallbackStorage` for building custom storage class as a base.
|
|
95
165
|
|
|
96
|
-
References:
|
|
97
|
-
- [callback.rb](lib/slack_bot/callback.rb)
|
|
98
|
-
- [callback_storage.rb](lib/slack_bot/callback_storage.rb)
|
|
99
|
-
|
|
100
166
|
### Arguments
|
|
101
167
|
|
|
102
168
|
Class for handling slash command and interactive element values as queries.
|
|
103
169
|
|
|
104
170
|
Gem implementation uses `Rack::Utils` for parsing and building query strings.
|
|
105
171
|
|
|
106
|
-
References:
|
|
107
|
-
- [args.rb](lib/slack_bot/args.rb)
|
|
108
|
-
|
|
109
172
|
### Pager
|
|
110
173
|
|
|
111
174
|
Own implementation of pagination that is relying on [Arguments](#arguments) and [ActiveRecord](https://guides.rubyonrails.org/active_record_querying.html).
|
|
112
175
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
- [x] Extend API endpoint with custom hooks and helpers within [grape specification](https://github.com/ruby-grape/grape)
|
|
128
|
-
- [x] Supports Slack signature verification
|
|
129
|
-
- [ ] Supports Slack socket mode (?)
|
|
130
|
-
- [ ] Supports Slack token rotation
|
|
131
|
-
|
|
132
|
-
## Usage with grape
|
|
133
|
-
|
|
134
|
-
Create `app/api/slack_bot_api.rb`, it will contain bot configuration and endpoints setup:
|
|
135
|
-
|
|
136
|
-
```ruby
|
|
137
|
-
SlackBot::DevConsole.logger = Rails.logger
|
|
138
|
-
SlackBot::DevConsole.enabled = Rails.env.development?
|
|
139
|
-
SlackBot::Config.configure do
|
|
140
|
-
callback_storage Rails.cache
|
|
141
|
-
callback_user_finder ->(id) { User.active.find_by(id: id) }
|
|
142
|
-
|
|
143
|
-
# TODO: Register event handlers
|
|
144
|
-
event :app_home_opened, MySlackBot::AppHomeOpenedEvent
|
|
145
|
-
interaction MySlackBot::AppHomeInteraction
|
|
146
|
-
|
|
147
|
-
# TODO: Register slash command handlers
|
|
148
|
-
slash_command_endpoint :game, MySlackBot::Game::MenuCommand do
|
|
149
|
-
command :start, MySlackBot::Game::StartCommand
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
class SlackBotApi < Grape::API
|
|
154
|
-
include SlackBot::GrapeExtension
|
|
155
|
-
|
|
156
|
-
helpers do
|
|
157
|
-
def config
|
|
158
|
-
SlackBot::Config.current_instance
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def resolve_user_session(team_id, user_id)
|
|
162
|
-
uid = OmniAuth::Strategies::SlackOpenid.generate_uid(team_id, user_id)
|
|
163
|
-
UserSession.find_by(uid: uid, provider: UserSession.slack_openid_provider)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def current_user_session
|
|
167
|
-
# NOTE: fetch_team_id and fetch_user_id are provided by SlackBot::Grape::ApiExtension
|
|
168
|
-
@current_user_session ||=
|
|
169
|
-
resolve_user_session(fetch_team_id, fetch_user_id)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def current_user_ip
|
|
173
|
-
request.env["action_dispatch.remote_ip"].to_s
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def current_user
|
|
177
|
-
@current_user ||= current_user_session&.user
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
In routes file `config/routes.rb` mount the API:
|
|
184
|
-
|
|
185
|
-
```ruby
|
|
186
|
-
mount SlackBotApi => "/api/slack"
|
|
187
|
-
```
|
|
176
|
+
## Features
|
|
177
|
+
|
|
178
|
+
- Create any amount of endpoints that will handle Slack calls
|
|
179
|
+
- Create multiple instances of bots and configure them separately or use the same configuration for all bots
|
|
180
|
+
- Define and reuse slash command handlers for Slack slash commands
|
|
181
|
+
- Define interactive component handlers for Slack interactive components
|
|
182
|
+
- Define and reuse views for slash commands, interactive components and events
|
|
183
|
+
- Define event handlers for Slack events
|
|
184
|
+
- Define menu options handlers for Slack menu options
|
|
185
|
+
- Store interactive component state in cache for usage in other handlers
|
|
186
|
+
- Access current user session and user from any handler
|
|
187
|
+
- Extend API endpoint with custom hooks and helpers within [grape specification](https://github.com/ruby-grape/grape)
|
|
188
|
+
- Supports Slack signature verification with timestamp validation (replay attack protection)
|
|
189
|
+
- Automatic error handling for network failures and malformed payloads
|
|
188
190
|
|
|
189
191
|
## Slack bot manifest
|
|
190
192
|
|
|
@@ -244,7 +246,9 @@ settings:
|
|
|
244
246
|
token_rotation_enabled: false
|
|
245
247
|
```
|
|
246
248
|
|
|
247
|
-
##
|
|
249
|
+
## Examples
|
|
250
|
+
|
|
251
|
+
### Command example
|
|
248
252
|
|
|
249
253
|
```ruby
|
|
250
254
|
module MySlackBot::Game
|
|
@@ -263,10 +267,9 @@ module MySlackBot::Game
|
|
|
263
267
|
end
|
|
264
268
|
end
|
|
265
269
|
end
|
|
266
|
-
|
|
267
270
|
```
|
|
268
271
|
|
|
269
|
-
|
|
272
|
+
### Interaction example
|
|
270
273
|
|
|
271
274
|
```ruby
|
|
272
275
|
module MySlackBot::Game
|
|
@@ -294,7 +297,7 @@ module MySlackBot::Game
|
|
|
294
297
|
end
|
|
295
298
|
```
|
|
296
299
|
|
|
297
|
-
App home interaction example
|
|
300
|
+
### App home interaction example
|
|
298
301
|
|
|
299
302
|
```ruby
|
|
300
303
|
module MySlackBot
|
|
@@ -318,7 +321,7 @@ module MySlackBot
|
|
|
318
321
|
end
|
|
319
322
|
```
|
|
320
323
|
|
|
321
|
-
|
|
324
|
+
### View example
|
|
322
325
|
|
|
323
326
|
Modal view example:
|
|
324
327
|
|
|
@@ -432,12 +435,11 @@ module MySlackBot
|
|
|
432
435
|
def index_view
|
|
433
436
|
blocks = []
|
|
434
437
|
if current_user.present?
|
|
435
|
-
blocks
|
|
438
|
+
blocks << {
|
|
436
439
|
type: "section",
|
|
437
440
|
text: {
|
|
438
441
|
type: "mrkdwn",
|
|
439
|
-
text:
|
|
440
|
-
"*Hello, #{current_user.name}!*"
|
|
442
|
+
text: "*Hello, #{current_user.name}!*"
|
|
441
443
|
}
|
|
442
444
|
}
|
|
443
445
|
else
|
|
@@ -445,8 +447,7 @@ module MySlackBot
|
|
|
445
447
|
type: "section",
|
|
446
448
|
text: {
|
|
447
449
|
type: "mrkdwn",
|
|
448
|
-
text:
|
|
449
|
-
"*Please login at https://example.com using Slack*"
|
|
450
|
+
text: "*Please login at https://example.com using Slack*"
|
|
450
451
|
}
|
|
451
452
|
}
|
|
452
453
|
end
|
|
@@ -471,7 +472,7 @@ module MySlackBot
|
|
|
471
472
|
end
|
|
472
473
|
```
|
|
473
474
|
|
|
474
|
-
|
|
475
|
+
### Event example
|
|
475
476
|
|
|
476
477
|
```ruby
|
|
477
478
|
module MySlackBot
|
|
@@ -491,11 +492,29 @@ module MySlackBot
|
|
|
491
492
|
end
|
|
492
493
|
```
|
|
493
494
|
|
|
494
|
-
##
|
|
495
|
+
## Security
|
|
496
|
+
|
|
497
|
+
The gem implements Slack's signature verification with the following security features:
|
|
498
|
+
|
|
499
|
+
- **Signature verification**: Validates requests using HMAC-SHA256 signature
|
|
500
|
+
- **Timestamp validation**: Rejects requests older than 5 minutes to prevent replay attacks
|
|
501
|
+
- **Secure comparison**: Uses `ActiveSupport::SecurityUtils.secure_compare` to prevent timing attacks
|
|
495
502
|
|
|
496
|
-
|
|
503
|
+
## Compatibility
|
|
497
504
|
|
|
498
|
-
|
|
505
|
+
- Grape >= 1.6, < 3.0
|
|
506
|
+
- Rails >= 5.0 (for ActionDispatch::RemoteIp)
|
|
507
|
+
- Ruby >= 3.0
|
|
508
|
+
- ActiveSupport >= 5.0
|
|
509
|
+
|
|
510
|
+
## Development
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
bundle install
|
|
514
|
+
bundle exec rspec
|
|
515
|
+
bundle exec rbs validate
|
|
516
|
+
bundle exec standardrb --fix
|
|
517
|
+
```
|
|
499
518
|
|
|
500
519
|
For development and testing purposes you can use [Cloudflare Argo Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps) to expose your local development environment to the internet.
|
|
501
520
|
|
|
@@ -507,28 +526,38 @@ sudo cloudflared tunnel run --token <LONG_TOKEN_FROM_TUNNEL_PAGE>
|
|
|
507
526
|
|
|
508
527
|
For easiness of getting information, most of endpoints have `SlackBot::DevConsole.log` calls that will print out information to the console.
|
|
509
528
|
|
|
529
|
+
### Code Quality
|
|
530
|
+
|
|
531
|
+
The gem uses [StandardRB](https://github.com/standardrb/standard) for consistent code style. Run `bundle exec standardrb --fix` to automatically fix style issues.
|
|
532
|
+
|
|
533
|
+
The gem includes [RBS](https://github.com/ruby/rbs) type signatures in the `sig/` directory for better type checking and IDE support. Type signatures are included in the gem package.
|
|
534
|
+
|
|
510
535
|
## Contributing
|
|
511
536
|
|
|
512
537
|
Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/grape-slack-bot.rb
|
|
513
538
|
|
|
514
539
|
Contribution policy:
|
|
515
|
-
- New features are not
|
|
540
|
+
- New features are not necessarily added to the gem
|
|
516
541
|
- Pull request should have test coverage for affected parts
|
|
517
542
|
- Pull request should have changelog entry
|
|
543
|
+
|
|
544
|
+
Review policy:
|
|
518
545
|
- It might take up to 2 calendar weeks to review and merge critical fixes
|
|
519
546
|
- It might take up to 6 calendar months to review and merge pull request
|
|
520
547
|
- It might take up to 1 calendar year to review an issue
|
|
521
548
|
|
|
522
549
|
## Publishing
|
|
523
550
|
|
|
524
|
-
Prefer using script `usr/bin/release.sh`, it will ensure that repository is synced and after publishing gem will create a tag.
|
|
525
|
-
|
|
526
551
|
```sh
|
|
527
|
-
GEM_VERSION=$(grep -Eo "VERSION\s*=\s*\".+\"" lib/slack_bot.rb | grep -Eo "[0-9.]{5,}")
|
|
528
552
|
rm grape-slack-bot-*.gem
|
|
529
553
|
gem build grape-slack-bot.gemspec
|
|
530
|
-
gem push grape-slack-bot
|
|
531
|
-
|
|
554
|
+
gem push grape-slack-bot-*.gem
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
Or use the release script:
|
|
558
|
+
|
|
559
|
+
```sh
|
|
560
|
+
usr/bin/release.sh
|
|
532
561
|
```
|
|
533
562
|
|
|
534
563
|
## License
|
data/grape-slack-bot.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
|
11
11
|
gem.platform = Gem::Platform::RUBY
|
|
12
12
|
|
|
13
13
|
gem.authors = ["Andrei Makarov"]
|
|
14
|
-
gem.email = ["
|
|
14
|
+
gem.email = ["contact@kiskolabs.com"]
|
|
15
15
|
gem.homepage = repository_url
|
|
16
16
|
gem.summary = "Slack bot implementation for ruby-grape"
|
|
17
17
|
gem.description = gem.summary
|
|
@@ -24,20 +24,25 @@ Gem::Specification.new do |gem|
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
gem.executables = Dir.glob("bin/*").map { |f| File.basename(f) }
|
|
27
|
-
gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + root_files
|
|
27
|
+
gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + Dir.glob("sig/**/*.rbs") + root_files
|
|
28
28
|
|
|
29
29
|
gem.required_ruby_version = ">= 3"
|
|
30
30
|
gem.require_paths = ["lib"]
|
|
31
31
|
|
|
32
|
-
gem.add_runtime_dependency "rack", "
|
|
33
|
-
gem.add_runtime_dependency "grape", "
|
|
34
|
-
gem.add_runtime_dependency "faraday", "
|
|
35
|
-
gem.add_runtime_dependency "activesupport", "
|
|
32
|
+
gem.add_runtime_dependency "rack", "~> 3.0"
|
|
33
|
+
gem.add_runtime_dependency "grape", ">= 1.6", "< 3.0"
|
|
34
|
+
gem.add_runtime_dependency "faraday", "~> 2.0"
|
|
35
|
+
gem.add_runtime_dependency "activesupport", ">= 6.1", "< 9.0"
|
|
36
36
|
|
|
37
|
-
gem.add_development_dependency "
|
|
38
|
-
gem.add_development_dependency "rspec", "~> 3"
|
|
39
|
-
gem.add_development_dependency "rspec_junit_formatter", "~> 0.6"
|
|
37
|
+
gem.add_development_dependency "rspec", "~> 3.12"
|
|
40
38
|
gem.add_development_dependency "webmock", "~> 3"
|
|
39
|
+
gem.add_development_dependency "rake", "~> 13.0"
|
|
41
40
|
gem.add_development_dependency "simplecov", "~> 0.21"
|
|
42
|
-
gem.add_development_dependency "
|
|
41
|
+
gem.add_development_dependency "rspec_junit_formatter", "~> 0.6"
|
|
42
|
+
gem.add_development_dependency "simplecov-cobertura", "~> 3"
|
|
43
|
+
gem.add_development_dependency "standard", "~> 1.0"
|
|
44
|
+
gem.add_development_dependency "appraisal", "~> 2.4"
|
|
45
|
+
gem.add_development_dependency "memory_profiler", "~> 1.0"
|
|
46
|
+
gem.add_development_dependency "rbs", "~> 3.0"
|
|
47
|
+
gem.add_development_dependency "rack-test", "~> 2.0"
|
|
43
48
|
end
|