grape-slack-bot 1.6.10 → 1.6.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 182ee366d5e5d1fb89152bcd753a75e4361b8f611fa1d9ca0a4b81dc5f6221ab
4
- data.tar.gz: 49f18848a1abef7bf401eb3af87a2037ba25850d0a9043428a4f44cba6bd2371
3
+ metadata.gz: e747b1927fe6e5c4daefb40830a338271b003a964dc857e4e85c0f06c0e72723
4
+ data.tar.gz: 1d06b0374106aa8dad4c9a9f46e5173a0c3bfe6785ba80f5d7da2429a6057f91
5
5
  SHA512:
6
- metadata.gz: 8379e1b62eb08f3dcf9507dffa299ac07d4c4753ac544e502ecef8f28107f7166df66c8f2783a338e58cd1a41f8f5702678650ac19aad100c597300097bb330e
7
- data.tar.gz: 7ee9589a200c7c105948df9751878ebf231430b3aa6313cfc86533de254e0340e01205e2d339810741fe7c2411c368083a1924511280671de63cb9be2d87f0ca
6
+ metadata.gz: 0c852fd5c5cb8bf2692b774d42c0fe2e7e074eb138df04ed9b44e34fcaf90d8db281a2cbe17e6fe80dc49c937984f70e36fad8e70b962be1c5eb6c99859e4e4c
7
+ data.tar.gz: 3fb00ab57011e5b5573970e4e36907482ca0020ec0a2186b6c9db6662097b41614e8d091b493ea843263b8af61fecd5ff6664473b2391619576b1e471bc60818
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # grape-slack-bot.rb
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/grape-slack-bot.svg)](https://badge.fury.io/rb/grape-slack-bot) [![Test Status](https://github.com/amkisko/grape-slack-bot.rb/actions/workflows/test.yml/badge.svg)](https://github.com/amkisko/grape-slack-bot.rb/actions/workflows/test.yml)
3
+ [![Gem Version](https://badge.fury.io/rb/grape-slack-bot.svg)](https://badge.fury.io/rb/grape-slack-bot) [![Test Status](https://github.com/amkisko/grape-slack-bot.rb/actions/workflows/test.yml/badge.svg)](https://github.com/amkisko/grape-slack-bot.rb/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/amkisko/grape-slack-bot.rb/graph/badge.svg?token=VIZ94XFOR3)](https://codecov.io/gh/amkisko/grape-slack-bot.rb)
4
4
 
5
5
  Extensible Slack bot implementation gem for [ruby-grape](https://github.com/ruby-grape/grape)
6
6
 
@@ -53,6 +53,7 @@ Interactive component is a component that is requested to be opened by bot app f
53
53
 
54
54
  Characteristics:
55
55
  - Can be associated with slash command
56
+ - Can be associated with event
56
57
 
57
58
  References:
58
59
  - [interaction.rb](lib/slack_bot/interaction.rb)
@@ -114,19 +115,19 @@ References:
114
115
 
115
116
  ## Specification
116
117
 
117
- [x] Create any amount of endpoints that will handle Slack calls
118
- [x] Create multiple instances of bots and configure them separately or use the same configuration for all bots
119
- [x] Define and reuse slash command handlers for Slack slash commands
120
- [x] Define interactive component handlers for Slack interactive components
121
- [x] Define and reuse views for slash commands, interactive components and events
122
- [x] Define event handlers for Slack events
123
- [x] Define menu options handlers for Slack menu options
124
- [x] Store interactive component state in cache for usage in other handlers
125
- [x] Access current user session and user from any handler
126
- [x] Extend API endpoint with custom hooks and helpers within [grape specification](https://github.com/ruby-grape/grape)
127
- [x] Supports Slack signature verification
128
- [ ] Supports Slack socket mode (?)
129
- [ ] Supports Slack token rotation
118
+ - [x] Create any amount of endpoints that will handle Slack calls
119
+ - [x] Create multiple instances of bots and configure them separately or use the same configuration for all bots
120
+ - [x] Define and reuse slash command handlers for Slack slash commands
121
+ - [x] Define interactive component handlers for Slack interactive components
122
+ - [x] Define and reuse views for slash commands, interactive components and events
123
+ - [x] Define event handlers for Slack events
124
+ - [x] Define menu options handlers for Slack menu options
125
+ - [x] Store interactive component state in cache for usage in other handlers
126
+ - [x] Access current user session and user from any handler
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
130
131
 
131
132
  ## Usage with grape
132
133
 
@@ -520,10 +521,14 @@ Contribution policy:
520
521
 
521
522
  ## Publishing
522
523
 
524
+ Prefer using script `usr/bin/release.sh`, it will ensure that repository is synced and after publishing gem will create a tag.
525
+
523
526
  ```sh
527
+ GEM_VERSION=$(grep -Eo "VERSION\s*=\s*'.+'" lib/slack_bot.rb | grep -Eo "[0-9.]{5,}")
524
528
  rm grape-slack-bot-*.gem
525
529
  gem build grape-slack-bot.gemspec
526
- gem push grape-slack-bot-*.gem
530
+ gem push grape-slack-bot-$GEM_VERSION.gem
531
+ git tag $GEM_VERSION && git push --tags
527
532
  ```
528
533
 
529
534
  ## License
@@ -1,4 +1,5 @@
1
1
  require 'rack/utils'
2
+ require 'active_support'
2
3
  require 'active_support/core_ext/hash/indifferent_access'
3
4
 
4
5
  module SlackBot
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/object'
2
3
 
3
4
  module SlackBot
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/object'
2
3
 
3
4
  module SlackBot
@@ -34,7 +35,7 @@ module SlackBot
34
35
  )
35
36
  true
36
37
  else
37
- raise SlackBot::SignatureAuthenticationError.new("Signature mismatch")
38
+ raise SlackBot::Errors::SignatureAuthenticationError.new("Signature mismatch")
38
39
  end
39
40
  end
40
41
 
@@ -43,7 +44,7 @@ module SlackBot
43
44
  if slack_team_id == fetch_team_id
44
45
  true
45
46
  else
46
- raise SlackBot::TeamAuthenticationError.new("Team is not authorized")
47
+ raise SlackBot::Errors::TeamAuthenticationError.new("Team is not authorized")
47
48
  end
48
49
  end
49
50
 
@@ -51,7 +52,7 @@ module SlackBot
51
52
  if params[:channel_name] == "directmessage"
52
53
  true
53
54
  else
54
- raise SlackBot::ChannelAuthenticationError.new(
55
+ raise SlackBot::Errors::ChannelAuthenticationError.new(
55
56
  "This command is only available in direct messages"
56
57
  )
57
58
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/object'
2
3
 
3
4
  require 'slack_bot/concerns/view_klass'
@@ -14,7 +15,7 @@ module SlackBot
14
15
  SlackBot::ApiClient.new.views_open(trigger_id: trigger_id, view: view)
15
16
 
16
17
  if !response.ok?
17
- raise SlackBot::Errors::OpenModalError.new(response.error, data: response.data, payload: payload)
18
+ raise SlackBot::Errors::OpenModalError.new(response.error, data: response.data, payload: view)
18
19
  end
19
20
 
20
21
  view_id = response.data.dig("view", "id")
@@ -31,7 +32,7 @@ module SlackBot
31
32
  SlackBot::ApiClient.new.views_update(view_id: view_id, view: view)
32
33
 
33
34
  if !response.ok?
34
- raise SlackBot::Errors::UpdateModalError.new(response.error, data: response.data, payload: payload)
35
+ raise SlackBot::Errors::UpdateModalError.new(response.error, data: response.data, payload: view)
35
36
  end
36
37
 
37
38
  view_id = response.data.dig("view", "id")
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/hash/indifferent_access'
2
3
  require 'slack_bot/concerns/pager_klass'
3
4
 
data/lib/slack_bot.rb CHANGED
@@ -22,5 +22,5 @@ require 'slack_bot/pager'
22
22
  require 'slack_bot/grape_extension'
23
23
 
24
24
  module SlackBot
25
- VERSION = '1.6.10'.freeze
25
+ VERSION = '1.6.12'.freeze
26
26
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe SlackBot::Event do
4
4
  let(:current_user) { double(:current_user) }
5
5
  let(:params) { double(:params) }
6
- let(:callback) { double(:callback) }
7
- let(:config) { double(:config) }
6
+ let(:callback) { instance_double(SlackBot::Callback) }
7
+ let(:config) { instance_double(SlackBot::Config) }
8
8
 
9
9
  subject do
10
10
  described_class.new(
@@ -1,5 +1,95 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SlackBot::Interaction do
4
+ subject { described_class.new(current_user: current_user, params: params, callback: callback, config: config) }
4
5
 
6
+ let(:current_user) { double("current_user") }
7
+ let(:params) { {} }
8
+ let(:callback) { instance_double(SlackBot::Callback, id: "test-callback-id") }
9
+ let(:config) { instance_double(SlackBot::Config) }
10
+
11
+ before do
12
+ allow(callback).to receive(:view_id=).and_return(nil)
13
+ allow(callback).to receive(:save).and_return(nil)
14
+ end
15
+
16
+ it "initializes" do
17
+ expect(subject.current_user).to eq(current_user)
18
+ expect(subject.params).to eq(params)
19
+ expect(subject.callback).to eq(callback)
20
+ expect(subject.config).to eq(config)
21
+ end
22
+
23
+ describe ".open_modal" do
24
+ subject(:open_modal) { described_class.open_modal(callback: callback, trigger_id: trigger_id, view: view) }
25
+
26
+ let(:trigger_id) { "trigger_id" }
27
+ let(:view) { {} }
28
+ let(:response) { instance_double(SlackBot::ApiResponse, ok?: true, data: { "view" => { "id" => "view_id" } }) }
29
+
30
+ before do
31
+ allow(SlackBot::ApiClient).to receive(:new).and_return(instance_double(SlackBot::ApiClient, views_open: response))
32
+ end
33
+
34
+ it "opens modal" do
35
+ expect(open_modal).to eq(SlackBot::Interaction::SlackViewsReply.new(callback&.id, "view_id"))
36
+ end
37
+
38
+ context "when response is not ok" do
39
+ let(:response) { instance_double(SlackBot::ApiResponse, ok?: false, error: "error", data: { "view" => { "id" => "view_id" } }) }
40
+
41
+ it "raises error" do
42
+ expect { open_modal }.to raise_error(SlackBot::Errors::OpenModalError)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe ".update_modal" do
48
+ subject(:update_modal) { described_class.update_modal(callback: callback, view_id: view_id, view: view) }
49
+
50
+ let(:view_id) { "view_id" }
51
+ let(:view) { {} }
52
+ let(:response) { instance_double(SlackBot::ApiResponse, ok?: true, data: { "view" => { "id" => "view_id" } }) }
53
+
54
+ before do
55
+ allow(SlackBot::ApiClient).to receive(:new).and_return(instance_double(SlackBot::ApiClient, views_update: response))
56
+ end
57
+
58
+ it "updates modal" do
59
+ expect(update_modal).to eq(SlackBot::Interaction::SlackViewsReply.new(callback&.id, "view_id"))
60
+ end
61
+
62
+ context "when response is not ok" do
63
+ let(:response) { instance_double(SlackBot::ApiResponse, ok?: false, error: "error", data: { "view" => { "id" => "view_id" } }) }
64
+
65
+ it "raises error" do
66
+ expect { update_modal }.to raise_error(SlackBot::Errors::UpdateModalError)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe ".publish_view" do
72
+ subject(:publish_view) { described_class.publish_view(callback: callback, metadata: metadata, user_id: user_id, view: view) }
73
+
74
+ let(:user_id) { "user_id" }
75
+ let(:metadata) { "metadata" }
76
+ let(:view) { {} }
77
+ let(:response) { instance_double(SlackBot::ApiResponse, ok?: true, data: { "view" => { "id" => "view_id" } }) }
78
+
79
+ before do
80
+ allow(SlackBot::ApiClient).to receive(:new).and_return(instance_double(SlackBot::ApiClient, views_publish: response))
81
+ end
82
+
83
+ it "publishes view" do
84
+ expect(publish_view).to eq(SlackBot::Interaction::SlackViewsReply.new(callback&.id, "view_id"))
85
+ end
86
+
87
+ context "when response is not ok" do
88
+ let(:response) { instance_double(SlackBot::ApiResponse, ok?: false, error: "error", data: { "view" => { "id" => "view_id" } }) }
89
+
90
+ it "raises error" do
91
+ expect { publish_view }.to raise_error(SlackBot::Errors::PublishViewError)
92
+ end
93
+ end
94
+ end
5
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-slack-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.10
4
+ version: 1.6.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-31 00:00:00.000000000 Z
11
+ date: 2023-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack