grape-slack-bot 1.8.2 → 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 +42 -23
- data/README.md +147 -120
- data/grape-slack-bot.gemspec +15 -10
- data/lib/slack_bot/api_client.rb +127 -33
- 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,98 +1,117 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
##
|
|
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)
|
|
4
23
|
|
|
5
24
|
- Update Slack API client to have more chat methods
|
|
6
25
|
|
|
7
|
-
## 1.8.1
|
|
26
|
+
## 1.8.1 (2024-12-08)
|
|
8
27
|
|
|
9
28
|
- Clean up dependencies
|
|
10
29
|
|
|
11
|
-
## 1.8.0
|
|
30
|
+
## 1.8.0 (2024-05-24)
|
|
12
31
|
|
|
13
32
|
- Rewind incoming request body when reading it
|
|
14
33
|
|
|
15
|
-
## 1.7.2
|
|
34
|
+
## 1.7.2 (2024-05-16)
|
|
16
35
|
|
|
17
36
|
- Fix request secret headers parsing
|
|
18
37
|
|
|
19
|
-
## 1.7.0
|
|
38
|
+
## 1.7.0 (2024-05-16)
|
|
20
39
|
|
|
21
40
|
- Add `usersList` and `chat.postEphemeral` methods
|
|
22
41
|
- Core upgrades and clean up
|
|
23
42
|
|
|
24
|
-
## 1.6.3
|
|
43
|
+
## 1.6.3 (2023-08-30)
|
|
25
44
|
|
|
26
45
|
- Implement callback for modals
|
|
27
46
|
|
|
28
|
-
## 1.6.2
|
|
47
|
+
## 1.6.2 (2023-08-30)
|
|
29
48
|
|
|
30
49
|
- Allow custom handler names for associating with interactions
|
|
31
50
|
|
|
32
|
-
## 1.6.1
|
|
51
|
+
## 1.6.1 (2023-08-30)
|
|
33
52
|
|
|
34
53
|
- Unify command, event and interaction rendering methods
|
|
35
54
|
|
|
36
|
-
## 1.6.0
|
|
55
|
+
## 1.6.0 (2023-08-30)
|
|
37
56
|
|
|
38
57
|
- Better visibility for missing handlers
|
|
39
58
|
|
|
40
|
-
## 1.5.8
|
|
59
|
+
## 1.5.8 (2023-08-30)
|
|
41
60
|
|
|
42
61
|
- Fix event registration
|
|
43
62
|
- Update event interaction example
|
|
44
63
|
|
|
45
|
-
## 1.5.7
|
|
64
|
+
## 1.5.7 (2023-08-30)
|
|
46
65
|
|
|
47
66
|
- Raise error if handler class not resolved
|
|
48
67
|
- App home interaction example added
|
|
49
68
|
- Callback logic and usage fixed
|
|
50
69
|
- Views improvements
|
|
51
70
|
|
|
52
|
-
## 1.5.0
|
|
71
|
+
## 1.5.0 (2023-08-30)
|
|
53
72
|
|
|
54
73
|
- Complete upgrade of callback storage logic
|
|
55
74
|
|
|
56
|
-
## 1.4.0
|
|
75
|
+
## 1.4.0 (2023-08-30)
|
|
57
76
|
|
|
58
77
|
- Allow setting callback expiration time on save and update
|
|
59
78
|
|
|
60
|
-
## 1.3.0
|
|
79
|
+
## 1.3.0 (2023-08-30)
|
|
61
80
|
|
|
62
81
|
- Clean up callback arguments, remove unused `method_name`
|
|
63
82
|
|
|
64
|
-
## 1.2.3
|
|
83
|
+
## 1.2.3 (2023-08-30)
|
|
65
84
|
|
|
66
85
|
- Minor fix for Events API
|
|
67
86
|
|
|
68
|
-
## 1.2.2
|
|
87
|
+
## 1.2.2 (2023-08-30)
|
|
69
88
|
|
|
70
89
|
- `SlackBot::Callback.find` method will raise `SlackBot::Errors::CallbackNotFound` if callback is not resolved or has wrong data
|
|
71
90
|
|
|
72
|
-
## 1.2.1
|
|
91
|
+
## 1.2.1 (2023-08-30)
|
|
73
92
|
|
|
74
93
|
- Extract `SlackBot::Logger` to separate file
|
|
75
94
|
|
|
76
|
-
## 1.2.0
|
|
95
|
+
## 1.2.0 (2023-08-30)
|
|
77
96
|
|
|
78
97
|
- Remove `Rails.logger` dependency, make logger configurable
|
|
79
98
|
|
|
80
|
-
## 1.1.0
|
|
99
|
+
## 1.1.0 (2023-08-30)
|
|
81
100
|
|
|
82
101
|
- Set minimum ruby version requirement to 2.5.0
|
|
83
102
|
|
|
84
|
-
## 1.0.5
|
|
103
|
+
## 1.0.5 (2023-08-29)
|
|
85
104
|
|
|
86
105
|
- Add superclass `SlackBot::Error` for all errors
|
|
87
106
|
|
|
88
|
-
## 1.0.2
|
|
107
|
+
## 1.0.2 (2023-08-29)
|
|
89
108
|
|
|
90
109
|
- Soften dependencies version requirements
|
|
91
110
|
|
|
92
|
-
## 1.0.1
|
|
111
|
+
## 1.0.1 (2023-08-29)
|
|
93
112
|
|
|
94
113
|
- Bump Faraday version to 2.7.10
|
|
95
114
|
|
|
96
|
-
## 1.0.0
|
|
115
|
+
## 1.0.0 (2023-08-29)
|
|
97
116
|
|
|
98
117
|
- Initial version
|
data/README.md
CHANGED
|
@@ -2,33 +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
|
-
##
|
|
13
|
+
## Installation
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
Add to your Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem "grape-slack-bot"
|
|
16
19
|
```
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
21
46
|
```
|
|
22
47
|
|
|
23
|
-
##
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
Create `app/api/slack_bot_api.rb`, it will contain bot configuration and endpoints setup:
|
|
24
51
|
|
|
25
52
|
```ruby
|
|
26
|
-
|
|
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
|
|
27
97
|
```
|
|
28
98
|
|
|
29
|
-
|
|
99
|
+
In routes file `config/routes.rb` mount the API:
|
|
30
100
|
|
|
31
|
-
|
|
101
|
+
```ruby
|
|
102
|
+
mount SlackBotApi => "/api/slack"
|
|
103
|
+
```
|
|
32
104
|
|
|
33
105
|
## Concepts
|
|
34
106
|
|
|
@@ -46,7 +118,6 @@ Characteristics:
|
|
|
46
118
|
- Can trigger event in background
|
|
47
119
|
|
|
48
120
|
References:
|
|
49
|
-
- [slash_command.rb](lib/slack_bot/slash_command.rb)
|
|
50
121
|
- [Slash command documentation](https://api.slack.com/interactivity/slash-commands)
|
|
51
122
|
|
|
52
123
|
### Interactive component
|
|
@@ -58,7 +129,6 @@ Characteristics:
|
|
|
58
129
|
- Can be associated with event
|
|
59
130
|
|
|
60
131
|
References:
|
|
61
|
-
- [interaction.rb](lib/slack_bot/interaction.rb)
|
|
62
132
|
- [Interactive components documentation](https://api.slack.com/interactivity/handling)
|
|
63
133
|
|
|
64
134
|
### Event
|
|
@@ -66,7 +136,6 @@ References:
|
|
|
66
136
|
Event is a notification that is sent to bot app when something happens in Slack.
|
|
67
137
|
|
|
68
138
|
References:
|
|
69
|
-
- [event.rb](lib/slack_bot/event.rb)
|
|
70
139
|
- [Event documentation](https://api.slack.com/events-api)
|
|
71
140
|
|
|
72
141
|
### View
|
|
@@ -77,7 +146,6 @@ Characteristics:
|
|
|
77
146
|
- Can be associated with slash command, interactive component or event for using ready-made methods like `open_modal`, `update_modal` or `publish_view`
|
|
78
147
|
|
|
79
148
|
References:
|
|
80
|
-
- [view.rb](lib/slack_bot/view.rb)
|
|
81
149
|
- [App home documentation](https://api.slack.com/surfaces/app-home)
|
|
82
150
|
- [Messages documentation](https://api.slack.com/messaging)
|
|
83
151
|
- [Modals documentation](https://api.slack.com/surfaces/modals)
|
|
@@ -95,98 +163,30 @@ Callback is a class for managing interactive component state and handling intera
|
|
|
95
163
|
|
|
96
164
|
Example uses `Rails.cache` for storing interactive component state, use `CallbackStorage` for building custom storage class as a base.
|
|
97
165
|
|
|
98
|
-
References:
|
|
99
|
-
- [callback.rb](lib/slack_bot/callback.rb)
|
|
100
|
-
- [callback_storage.rb](lib/slack_bot/callback_storage.rb)
|
|
101
|
-
|
|
102
166
|
### Arguments
|
|
103
167
|
|
|
104
168
|
Class for handling slash command and interactive element values as queries.
|
|
105
169
|
|
|
106
170
|
Gem implementation uses `Rack::Utils` for parsing and building query strings.
|
|
107
171
|
|
|
108
|
-
References:
|
|
109
|
-
- [args.rb](lib/slack_bot/args.rb)
|
|
110
|
-
|
|
111
172
|
### Pager
|
|
112
173
|
|
|
113
174
|
Own implementation of pagination that is relying on [Arguments](#arguments) and [ActiveRecord](https://guides.rubyonrails.org/active_record_querying.html).
|
|
114
175
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
- [x] Extend API endpoint with custom hooks and helpers within [grape specification](https://github.com/ruby-grape/grape)
|
|
130
|
-
- [x] Supports Slack signature verification
|
|
131
|
-
- [ ] Supports Slack socket mode (?)
|
|
132
|
-
- [ ] Supports Slack token rotation
|
|
133
|
-
|
|
134
|
-
## Usage with grape
|
|
135
|
-
|
|
136
|
-
Create `app/api/slack_bot_api.rb`, it will contain bot configuration and endpoints setup:
|
|
137
|
-
|
|
138
|
-
```ruby
|
|
139
|
-
SlackBot::DevConsole.logger = Rails.logger
|
|
140
|
-
SlackBot::DevConsole.enabled = Rails.env.development?
|
|
141
|
-
SlackBot::Config.configure do
|
|
142
|
-
callback_storage Rails.cache
|
|
143
|
-
callback_user_finder ->(id) { User.active.find_by(id: id) }
|
|
144
|
-
|
|
145
|
-
# TODO: Register event handlers
|
|
146
|
-
event :app_home_opened, MySlackBot::AppHomeOpenedEvent
|
|
147
|
-
interaction MySlackBot::AppHomeInteraction
|
|
148
|
-
|
|
149
|
-
# TODO: Register slash command handlers
|
|
150
|
-
slash_command_endpoint :game, MySlackBot::Game::MenuCommand do
|
|
151
|
-
command :start, MySlackBot::Game::StartCommand
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
class SlackBotApi < Grape::API
|
|
156
|
-
include SlackBot::GrapeExtension
|
|
157
|
-
|
|
158
|
-
helpers do
|
|
159
|
-
def config
|
|
160
|
-
SlackBot::Config.current_instance
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def resolve_user_session(team_id, user_id)
|
|
164
|
-
uid = OmniAuth::Strategies::SlackOpenid.generate_uid(team_id, user_id)
|
|
165
|
-
UserSession.find_by(uid: uid, provider: UserSession.slack_openid_provider)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def current_user_session
|
|
169
|
-
# NOTE: fetch_team_id and fetch_user_id are provided by SlackBot::Grape::ApiExtension
|
|
170
|
-
@current_user_session ||=
|
|
171
|
-
resolve_user_session(fetch_team_id, fetch_user_id)
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def current_user_ip
|
|
175
|
-
request.env["action_dispatch.remote_ip"].to_s
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def current_user
|
|
179
|
-
@current_user ||= current_user_session&.user
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
In routes file `config/routes.rb` mount the API:
|
|
186
|
-
|
|
187
|
-
```ruby
|
|
188
|
-
mount SlackBotApi => "/api/slack"
|
|
189
|
-
```
|
|
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
|
|
190
190
|
|
|
191
191
|
## Slack bot manifest
|
|
192
192
|
|
|
@@ -246,7 +246,9 @@ settings:
|
|
|
246
246
|
token_rotation_enabled: false
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
-
##
|
|
249
|
+
## Examples
|
|
250
|
+
|
|
251
|
+
### Command example
|
|
250
252
|
|
|
251
253
|
```ruby
|
|
252
254
|
module MySlackBot::Game
|
|
@@ -265,10 +267,9 @@ module MySlackBot::Game
|
|
|
265
267
|
end
|
|
266
268
|
end
|
|
267
269
|
end
|
|
268
|
-
|
|
269
270
|
```
|
|
270
271
|
|
|
271
|
-
|
|
272
|
+
### Interaction example
|
|
272
273
|
|
|
273
274
|
```ruby
|
|
274
275
|
module MySlackBot::Game
|
|
@@ -296,7 +297,7 @@ module MySlackBot::Game
|
|
|
296
297
|
end
|
|
297
298
|
```
|
|
298
299
|
|
|
299
|
-
App home interaction example
|
|
300
|
+
### App home interaction example
|
|
300
301
|
|
|
301
302
|
```ruby
|
|
302
303
|
module MySlackBot
|
|
@@ -320,7 +321,7 @@ module MySlackBot
|
|
|
320
321
|
end
|
|
321
322
|
```
|
|
322
323
|
|
|
323
|
-
|
|
324
|
+
### View example
|
|
324
325
|
|
|
325
326
|
Modal view example:
|
|
326
327
|
|
|
@@ -434,12 +435,11 @@ module MySlackBot
|
|
|
434
435
|
def index_view
|
|
435
436
|
blocks = []
|
|
436
437
|
if current_user.present?
|
|
437
|
-
blocks
|
|
438
|
+
blocks << {
|
|
438
439
|
type: "section",
|
|
439
440
|
text: {
|
|
440
441
|
type: "mrkdwn",
|
|
441
|
-
text:
|
|
442
|
-
"*Hello, #{current_user.name}!*"
|
|
442
|
+
text: "*Hello, #{current_user.name}!*"
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
else
|
|
@@ -447,8 +447,7 @@ module MySlackBot
|
|
|
447
447
|
type: "section",
|
|
448
448
|
text: {
|
|
449
449
|
type: "mrkdwn",
|
|
450
|
-
text:
|
|
451
|
-
"*Please login at https://example.com using Slack*"
|
|
450
|
+
text: "*Please login at https://example.com using Slack*"
|
|
452
451
|
}
|
|
453
452
|
}
|
|
454
453
|
end
|
|
@@ -473,7 +472,7 @@ module MySlackBot
|
|
|
473
472
|
end
|
|
474
473
|
```
|
|
475
474
|
|
|
476
|
-
|
|
475
|
+
### Event example
|
|
477
476
|
|
|
478
477
|
```ruby
|
|
479
478
|
module MySlackBot
|
|
@@ -493,11 +492,29 @@ module MySlackBot
|
|
|
493
492
|
end
|
|
494
493
|
```
|
|
495
494
|
|
|
496
|
-
##
|
|
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
|
|
497
502
|
|
|
498
|
-
|
|
503
|
+
## Compatibility
|
|
499
504
|
|
|
500
|
-
|
|
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
|
+
```
|
|
501
518
|
|
|
502
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.
|
|
503
520
|
|
|
@@ -509,28 +526,38 @@ sudo cloudflared tunnel run --token <LONG_TOKEN_FROM_TUNNEL_PAGE>
|
|
|
509
526
|
|
|
510
527
|
For easiness of getting information, most of endpoints have `SlackBot::DevConsole.log` calls that will print out information to the console.
|
|
511
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
|
+
|
|
512
535
|
## Contributing
|
|
513
536
|
|
|
514
537
|
Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/grape-slack-bot.rb
|
|
515
538
|
|
|
516
539
|
Contribution policy:
|
|
517
|
-
- New features are not
|
|
540
|
+
- New features are not necessarily added to the gem
|
|
518
541
|
- Pull request should have test coverage for affected parts
|
|
519
542
|
- Pull request should have changelog entry
|
|
543
|
+
|
|
544
|
+
Review policy:
|
|
520
545
|
- It might take up to 2 calendar weeks to review and merge critical fixes
|
|
521
546
|
- It might take up to 6 calendar months to review and merge pull request
|
|
522
547
|
- It might take up to 1 calendar year to review an issue
|
|
523
548
|
|
|
524
549
|
## Publishing
|
|
525
550
|
|
|
526
|
-
Prefer using script `usr/bin/release.sh`, it will ensure that repository is synced and after publishing gem will create a tag.
|
|
527
|
-
|
|
528
551
|
```sh
|
|
529
|
-
GEM_VERSION=$(grep -Eo "VERSION\s*=\s*\".+\"" lib/slack_bot.rb | grep -Eo "[0-9.]{5,}")
|
|
530
552
|
rm grape-slack-bot-*.gem
|
|
531
553
|
gem build grape-slack-bot.gemspec
|
|
532
|
-
gem push grape-slack-bot
|
|
533
|
-
|
|
554
|
+
gem push grape-slack-bot-*.gem
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
Or use the release script:
|
|
558
|
+
|
|
559
|
+
```sh
|
|
560
|
+
usr/bin/release.sh
|
|
534
561
|
```
|
|
535
562
|
|
|
536
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
|