slackify 0.1.5 → 0.2.0

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: ef19a6dcce63500188e60c11300e64b87bc9e1f14b19b74414a9836a6c62bbe6
4
- data.tar.gz: 99b6d64edb26950cb2170726482c8dfee60a0ec6f2783ad6590590569f30c756
3
+ metadata.gz: ca58d1a63e649165df6caccc7092ee6ab04ee2fa9edaa5b3225a156cb66d4566
4
+ data.tar.gz: 3d3ae1cdd0f6f78ba32361fa61d858402968643819359fa363b15f4ee1547b49
5
5
  SHA512:
6
- metadata.gz: cb26feeb493688c5d4b8968df4f8675696cfc63be388de73c83c1ccf35bb6b856594ef1262610f09abfc214ec3f042586de2bc7228b09d87614789624ccf65f4
7
- data.tar.gz: c197031062643ab45484f851bb274378eab85b272917b8bfb829e8c1f2f3c13448af27ff70eeb80c980c69a2d8c76c5996e0436c43c6ec34883b0867df0be47f
6
+ metadata.gz: 51f0928b97da9b9839317b550ae616299ed4fb6692ed020f6ebfd6e0f14e0e222cc34aa7d225bfb0dc197441d6bb7988e3b2318369efe44814a0a60c4837770c
7
+ data.tar.gz: 3c7a7e4d3e394c0024df2523716f92a6e556f43e6cb00e620257d0148c2f889daabb4dbd67db3a977e3524e8b0fc05f5f3acaa2f4bb78e734fa062f3a73c9f8e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## V0.2.0
2
+
3
+ Update `custom_event_subtype_handlers` to `custom_message_subtype_handlers` and add support for `custom_event_type_handlers`. This is a breaking change since we rename the field that was previously used. To fix, update any calls from `custom_event_subtype_handlers` to `custom_message_subtype_handlers` and you should be good to go.
4
+
1
5
  ## V0.1.5
2
6
 
3
7
  Update how the `bot_id` is set in the handler configuration. You can disable the slack auth test (which is used to obtain the bot_id) by setting `SLACK_AUTH_SKIP=1` in your environment variables. If you are running in a Rails environment other than production, development or staging and would like to use the bot for real requests, you can trigger a manual auth test by calling `Slackify.configuration.handlers.bot_auth_test`. Gemfile.lock was removed.
data/README.md CHANGED
@@ -8,7 +8,8 @@ Slackify is a gem that allows to build slackbots on Rails using the [Event API](
8
8
  * [Plain messages](#handling-plain-messages)
9
9
  * [Interactive messages](#handling-interactive-messages)
10
10
  * [Slash Command](#handling-slash-commands)
11
- * [Custom handler for event subtypes](#custom-handler-for-event-subtypes)
11
+ * [Custom handler for message subtypes](#custom-handler-for-message-subtypes)
12
+ * [Custom handler for event types](#custom-handler-for-event-types)
12
13
  * [Custom unhandled handler](#custom-unhandled-handler)
13
14
  * [Slack client](#slack-client)
14
15
  * [Sending a simple message](#sending-a-simple-message)
@@ -85,17 +86,29 @@ class DummyHandler < Slackify::Handlers::Base
85
86
  end
86
87
  ```
87
88
 
88
- ### Custom handler for event subtypes
89
+ ### Custom handler for message subtypes
89
90
 
90
- If you wish to add more functionalities to your bot, you can specify define new behaviours for different event subtypes. You can specify a hash with the event subtype as a key and the handler class as the value. Slackify will call `.handle_event` on your class and pass the controller params as parameters.
91
+ If you wish to add more functionalities to your bot, you can specify define new behaviours for different message subtypes. You can specify a hash with the event subtype as a key and the handler class as the value. Slackify will call `.handle_event` on your class and pass the controller params as parameters.
91
92
 
92
93
  ```ruby
93
- Slackify.configuration.custom_event_subtype_handlers = {
94
+ Slackify.configuration.custom_message_subtype_handlers = {
95
+ file_share: MessageImageHandler
96
+ }
97
+ ```
98
+
99
+ In this example, all message of subtype `file_share` will be sent to the `MessageImageHandler` class.
100
+
101
+ ### Custom handler for event types
102
+
103
+ If you wish to add more functionalities to your bot, you can specify define new behaviours for different event types. You can specify a hash with the event type as a key and the handler class as the value. Slackify will call `.handle_event` on your class and pass the controller params as parameters.
104
+
105
+ ```ruby
106
+ Slackify.configuration.custom_event_type_handlers = {
94
107
  file_share: ImageHandler
95
108
  }
96
109
  ```
97
110
 
98
- In this example, all events of subtype `file_share` will be sent to the `ImageHandler` class.
111
+ In this example, all events of type `file_share` will be sent to the `ImageHandler` class.
99
112
 
100
113
  ### Custom unhandled handler
101
114
 
@@ -223,7 +236,7 @@ Slackify.load_handlers
223
236
  ```ruby
224
237
  # config/initializers/slackify.rb
225
238
  Slackify.load_handlers
226
- Slackify.configuration.custom_event_subtype_handlers = {
239
+ Slackify.configuration.custom_message_subtype_handlers = {
227
240
  file_share: ImageHandler,
228
241
  channel_join: JoinHandler,
229
242
  ...
@@ -9,6 +9,8 @@ module Slackify
9
9
  def event_callback
10
10
  if params[:type] == "url_verification"
11
11
  render plain: params["challenge"]
12
+ elsif Slackify.configuration.custom_event_type_handlers[params[:event][:type]]
13
+ handle_custom_event_type
12
14
  elsif params[:event][:type] == "message"
13
15
  handle_direct_message_event
14
16
  head :ok
@@ -51,7 +53,7 @@ module Slackify
51
53
  private
52
54
 
53
55
  def handle_direct_message_event
54
- if handler = Slackify.configuration.custom_event_subtype_handlers[params[:event][:subtype]]
56
+ if handler = Slackify.configuration.custom_message_subtype_handlers[params[:event][:subtype]]
55
57
  handler.handle_event(params[:slack])
56
58
  head :ok
57
59
  return
@@ -65,6 +67,11 @@ module Slackify
65
67
  raise e unless e.message == "Component not found for a command message"
66
68
  end
67
69
 
70
+ def handle_custom_event_type
71
+ Slackify.configuration.custom_event_type_handlers[params[:event][:type]].handle_event(params[:slack])
72
+ head :ok
73
+ end
74
+
68
75
  def handler_from_callback_id(callback_id)
69
76
  class_name, method_name = callback_id.split('#')
70
77
  class_name = class_name.camelize
@@ -4,7 +4,7 @@ require 'slack'
4
4
 
5
5
  module Slackify
6
6
  class Configuration
7
- attr_reader :custom_event_subtype_handlers, :slack_bot_token, :unhandled_handler
7
+ attr_reader :custom_message_subtype_handlers, :slack_bot_token, :unhandled_handler, :custom_event_type_handlers
8
8
  attr_accessor :handlers, :slack_secret_token, :slack_client
9
9
 
10
10
  def initialize
@@ -12,7 +12,8 @@ module Slackify
12
12
  @slack_secret_token = nil
13
13
  @handlers = nil
14
14
  @slack_client = nil
15
- @custom_event_subtype_handlers = {}
15
+ @custom_message_subtype_handlers = {}
16
+ @custom_event_type_handlers = {}
16
17
  @unhandled_handler = Handlers::UnhandledHandler
17
18
  end
18
19
 
@@ -32,8 +33,12 @@ module Slackify
32
33
  @slack_client = Slack::Web::Client.new(token: token).freeze
33
34
  end
34
35
 
35
- def custom_event_subtype_handlers=(event_subtype_hash)
36
- @custom_event_subtype_handlers = event_subtype_hash.with_indifferent_access
36
+ def custom_message_subtype_handlers=(event_subtype_hash)
37
+ @custom_message_subtype_handlers = event_subtype_hash.with_indifferent_access
38
+ end
39
+
40
+ def custom_event_type_handlers=(event_type_hash)
41
+ @custom_event_type_handlers = event_type_hash.with_indifferent_access
37
42
  end
38
43
  end
39
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Leger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-11 00:00:00.000000000 Z
12
+ date: 2019-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails