Class: SlackBot::Interaction
- Inherits:
-
Object
- Object
- SlackBot::Interaction
- Includes:
- Concerns::ViewKlass
- Defined in:
- lib/slack_bot/interaction.rb
Defined Under Namespace
Classes: SlackViewsReply
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
- .open_modal(callback:, trigger_id:, view:) ⇒ Object
- .publish_view(user_id:, view:, callback: nil, metadata: nil) ⇒ Object
- .update_modal(callback:, view_id:, view:) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(current_user: nil, params: nil, callback: nil, config: nil) ⇒ Interaction
constructor
A new instance of Interaction.
Methods included from Concerns::ViewKlass
Constructor Details
#initialize(current_user: nil, params: nil, callback: nil, config: nil) ⇒ Interaction
Returns a new instance of Interaction.
65 66 67 68 69 70 |
# File 'lib/slack_bot/interaction.rb', line 65 def initialize(current_user: nil, params: nil, callback: nil, config: nil) @current_user = current_user @params = params @callback = callback @config = config || SlackBot::Config.current_instance end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
64 65 66 |
# File 'lib/slack_bot/interaction.rb', line 64 def callback @callback end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
64 65 66 |
# File 'lib/slack_bot/interaction.rb', line 64 def config @config end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
64 65 66 |
# File 'lib/slack_bot/interaction.rb', line 64 def current_user @current_user end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
64 65 66 |
# File 'lib/slack_bot/interaction.rb', line 64 def params @params end |
Class Method Details
.open_modal(callback:, trigger_id:, view:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/slack_bot/interaction.rb', line 12 def self.open_modal(callback:, trigger_id:, view:) view = view.merge({type: "modal", callback_id: callback&.id}) response = SlackBot::ApiClient.new.views_open(trigger_id: trigger_id, view: view) if !response.ok? raise SlackBot::Errors::OpenModalError.new(response.error, data: response.data, payload: view) end view_id = response.data.dig("view", "id") if callback.present? && view_id.present? callback.view_id = view_id callback.save end SlackViewsReply.new(callback&.id, view_id) end |
.publish_view(user_id:, view:, callback: nil, metadata: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/slack_bot/interaction.rb', line 46 def self.publish_view(user_id:, view:, callback: nil, metadata: nil) view = view.merge(callback_id: callback.id) if callback.present? view = view.merge(private_metadata: ) if .present? response = SlackBot::ApiClient.new.views_publish(user_id: user_id, view: view) if !response.ok? raise SlackBot::Errors::PublishViewError.new(response.error, data: response.data, payload: view) end view_id = response.data.dig("view", "id") if callback.present? && view_id.present? callback.view_id = view_id callback.save end SlackViewsReply.new(callback&.id, view_id) end |
.update_modal(callback:, view_id:, view:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/slack_bot/interaction.rb', line 29 def self.update_modal(callback:, view_id:, view:) view = view.merge({type: "modal", callback_id: callback&.id}) response = SlackBot::ApiClient.new.views_update(view_id: view_id, view: view) if !response.ok? raise SlackBot::Errors::UpdateModalError.new(response.error, data: response.data, payload: view) end view_id = response.data.dig("view", "id") if callback.present? && view_id.present? callback.view_id = view_id callback.save end SlackViewsReply.new(callback&.id, view_id) end |
Instance Method Details
#call ⇒ Object
72 73 74 |
# File 'lib/slack_bot/interaction.rb', line 72 def call nil end |