Class: SlackInteractiveClient::BaseInteraction

Inherits:
Object
  • Object
show all
Includes:
SlackInteractionParams, SlackPatternInteraction
Defined in:
lib/slack_interactive_client/base_interaction.rb

Direct Known Subclasses

UnknownCommandInteraction

Constant Summary

Constants included from SlackInteractionParams

SlackInteractionParams::DIRECT_MESSAGE_CHANNEL

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SlackPatternInteraction

#method_missing, #respond_to_missing?

Methods included from SlackInteractionParams

#slack_channel_id, #slack_channel_name, #slack_command, #slack_message_text, #slack_response_url, #slack_team_domain, #slack_team_id, #slack_token, #slack_user_id, #slack_user_name

Constructor Details

#initialize(webhook_params = {}) ⇒ BaseInteraction

Returns a new instance of BaseInteraction.



50
51
52
53
54
55
# File 'lib/slack_interactive_client/base_interaction.rb', line 50

def initialize(webhook_params = {})
  @interaction_params = webhook_params
  @pattern = self.class.pattern_string
  @extracted_values = {}
  extract_values(slack_message_text)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SlackPatternInteraction

Class Attribute Details

.interaction_channelsObject (readonly)

Returns the value of attribute interaction_channels.



14
15
16
# File 'lib/slack_interactive_client/base_interaction.rb', line 14

def interaction_channels
  @interaction_channels
end

.interaction_configObject (readonly)

Returns the value of attribute interaction_config.



14
15
16
# File 'lib/slack_interactive_client/base_interaction.rb', line 14

def interaction_config
  @interaction_config
end

.pattern_stringObject (readonly)

Returns the value of attribute pattern_string.



14
15
16
# File 'lib/slack_interactive_client/base_interaction.rb', line 14

def pattern_string
  @pattern_string
end

Instance Attribute Details

#interaction_paramsObject (readonly)

Returns the value of attribute interaction_params.



49
50
51
# File 'lib/slack_interactive_client/base_interaction.rb', line 49

def interaction_params
  @interaction_params
end

Class Method Details

.interaction_options(options = {}) ⇒ Object

EXAMPLE

interaction_options can_interact: { only: [‘micah.bowie’] }, channels: []



19
20
21
22
# File 'lib/slack_interactive_client/base_interaction.rb', line 19

def interaction_options(options = {})
  set_interaction_config(options[:can_interact])
  @interaction_channels = options[:channels].empty? ? :all : options[:channels]
end

.interaction_pattern(pattern_string = '') ⇒ Object



24
25
26
# File 'lib/slack_interactive_client/base_interaction.rb', line 24

def interaction_pattern(pattern_string = '')
  @pattern_string = pattern_string.strip.squeeze
end

Instance Method Details

#callObject



57
58
59
60
61
62
63
# File 'lib/slack_interactive_client/base_interaction.rb', line 57

def call
  unless can_interact?
    send_message('You are not authorized to interact with this command or interaction is in an invalid channel.')
    return
  end
  execute
end

#executeObject



65
66
67
# File 'lib/slack_interactive_client/base_interaction.rb', line 65

def execute
  puts "Method not reimplemented by child"
end