Class: WitBot::MessageThread
- Inherits:
-
Object
- Object
- WitBot::MessageThread
- Defined in:
- lib/wit_bot/models/message_thread.rb
Instance Attribute Summary collapse
-
#bot_messages ⇒ Object
readonly
Returns the value of attribute bot_messages.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #context ⇒ Object
- #create_bot_message(text, id = SecureRandom.uuid) ⇒ Object
- #create_message(text, id = SecureRandom.uuid) ⇒ Object
- #equals_without_messages(other) ⇒ Object
- #from_hash(json) ⇒ Object
-
#initialize(id = SecureRandom.uuid) ⇒ MessageThread
constructor
A new instance of MessageThread.
- #message(id) ⇒ Object
- #messages_list(user: true, bot: false) ⇒ Object
- #reset_context ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(id = SecureRandom.uuid) ⇒ MessageThread
Returns a new instance of MessageThread.
7 8 9 10 11 12 |
# File 'lib/wit_bot/models/message_thread.rb', line 7 def initialize(id=SecureRandom.uuid) @id = id @messages = ActiveSupport::OrderedHash.new @bot_messages = ActiveSupport::OrderedHash.new @metadata = nil end |
Instance Attribute Details
#bot_messages ⇒ Object (readonly)
Returns the value of attribute bot_messages.
5 6 7 |
# File 'lib/wit_bot/models/message_thread.rb', line 5 def @bot_messages end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/wit_bot/models/message_thread.rb', line 5 def id @id end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'lib/wit_bot/models/message_thread.rb', line 5 def @messages end |
#metadata ⇒ Object
Returns the value of attribute metadata.
3 4 5 |
# File 'lib/wit_bot/models/message_thread.rb', line 3 def @metadata end |
Class Method Details
.from_hash(json) ⇒ Object
62 63 64 65 |
# File 'lib/wit_bot/models/message_thread.rb', line 62 def self.from_hash(json) json = json.with_indifferent_access self.new(json[:id]).from_hash json end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/wit_bot/models/message_thread.rb', line 67 def ==(other) self.id == other.id && self.context == other.context && self. == other. && self. == other. && self. == other. end |
#context ⇒ Object
32 33 34 |
# File 'lib/wit_bot/models/message_thread.rb', line 32 def context @context ||= Context.new end |
#create_bot_message(text, id = SecureRandom.uuid) ⇒ Object
28 29 30 |
# File 'lib/wit_bot/models/message_thread.rb', line 28 def (text, id=SecureRandom.uuid) @bot_messages[id] = WitBot::Bot::Message.new self, text, id: id end |
#create_message(text, id = SecureRandom.uuid) ⇒ Object
24 25 26 |
# File 'lib/wit_bot/models/message_thread.rb', line 24 def (text, id=SecureRandom.uuid) @messages[id] = WitBot::Message.new self, text, id: id end |
#equals_without_messages(other) ⇒ Object
75 76 77 78 79 |
# File 'lib/wit_bot/models/message_thread.rb', line 75 def (other) self.id == other.id && self.context == other.context && self. == other. end |
#from_hash(json) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/wit_bot/models/message_thread.rb', line 52 def from_hash(json) m = json[:messages] @messages = WitBot::Message.many_from_hash(self, m[:user]) @bot_messages = WitBot::Message.many_from_hash(self, m[:bot]) @context = Context.from_hash json[:context] if json[:context] @metadata = json[:metadata] self end |
#message(id) ⇒ Object
14 15 16 |
# File 'lib/wit_bot/models/message_thread.rb', line 14 def (id) [id] end |
#messages_list(user: true, bot: false) ⇒ Object
18 19 20 21 22 |
# File 'lib/wit_bot/models/message_thread.rb', line 18 def (user: true, bot: false) = bot ? @bot_messages.values : [] = user ? @messages.values : [] + end |
#reset_context ⇒ Object
36 37 38 |
# File 'lib/wit_bot/models/message_thread.rb', line 36 def reset_context @context = Context.new end |
#to_hash ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wit_bot/models/message_thread.rb', line 40 def to_hash { id: @id, context: @context, messages: { bot: @bot_messages, user: @messages }, metadata: @metadata } end |