Class: WitBot::Bot::Base

Inherits:
Conversation::Participant show all
Defined in:
lib/wit_bot/bot/base.rb

Instance Attribute Summary

Attributes inherited from Conversation::Participant

#conversation

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Conversation::Participant

#bot?, #send_message, #update

Constructor Details

#initialize(conversation) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/wit_bot/bot/base.rb', line 4

def initialize(conversation)
  super conversation
end

Class Method Details

.intents(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wit_bot/bot/base.rb', line 9

def intents(*args)
  @intents ||= []
  if args.empty?
    @intents.map! do |intent|
      if intent.is_a? WitBot::WitModel::Intent
        intent
      else
        WitBot::WitModel::Intent.find intent
      end
    end
  else
    @intents.concat args
  end
end

Instance Method Details

#intent_namesObject



29
30
31
# File 'lib/wit_bot/bot/base.rb', line 29

def intent_names
  intents.map { |intent| intent.name }
end

#intentsObject



25
26
27
# File 'lib/wit_bot/bot/base.rb', line 25

def intents
  self.class.intents
end

#on_input(message) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/wit_bot/bot/base.rb', line 33

def on_input(message)
  outcome = message.outcome
  intent = outcome.intent
  intent_name = intent.name.to_sym

  if intent_names.include? intent_name
    method_name = "on_#{intent_name}".to_sym
    self.send method_name, message if self.respond_to? method_name, true
  end
end