Class: WitBot::Bot::Conversation::Base
- Inherits:
-
Object
- Object
- WitBot::Bot::Conversation::Base
- Includes:
- Observable
- Defined in:
- lib/wit_bot/bot/conversation/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #from_hash(json) ⇒ Object
- #input(input, meta = nil) ⇒ Object
- #listen_with(listener_class) ⇒ Object
- #messages(user: true, bot: true) ⇒ Object
- #metadata ⇒ Object
- #output(text, meta = nil) ⇒ Object
- #send_message(text, sender = nil, meta = nil) ⇒ Object
- #thread ⇒ Object
- #to_hash ⇒ Object
Class Method Details
.from_hash(json) ⇒ Object
55 56 57 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 55 def self.from_hash(json) self.new.from_hash json.with_indifferent_access end |
Instance Method Details
#from_hash(json) ⇒ Object
50 51 52 53 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 50 def from_hash(json) @thread = WitBot::MessageThread.from_hash json[:thread] self end |
#input(input, meta = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 23 def input(input, =nil) = thread. input . = .send 1, false changed notify_observers :input, end |
#listen_with(listener_class) ⇒ Object
32 33 34 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 32 def listen_with(listener_class) listener_class.new self end |
#messages(user: true, bot: true) ⇒ Object
15 16 17 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 15 def (user: true, bot: true) thread. user, bot end |
#metadata ⇒ Object
7 8 9 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 7 def thread. end |
#output(text, meta = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 36 def output(text, =nil) = thread. text . = changed notify_observers :output, end |
#send_message(text, sender = nil, meta = nil) ⇒ Object
19 20 21 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 19 def (text, sender=nil, =nil) sender && sender.bot? ? output(text, ) : input(text, ) end |
#thread ⇒ Object
11 12 13 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 11 def thread @thread ||= MessageThread.new("#{self.class.name}-#{SecureRandom.uuid}") end |
#to_hash ⇒ Object
44 45 46 47 48 |
# File 'lib/wit_bot/bot/conversation/base.rb', line 44 def to_hash { thread: @thread } end |