Class: WitBot::MessageThread

Inherits:
Object
  • Object
show all
Defined in:
lib/wit_bot/models/message_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = SecureRandom.uuid) ⇒ MessageThread

Returns a new instance of MessageThread.



7
8
9
10
11
# 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
end

Instance Attribute Details

#bot_messagesObject (readonly)

Returns the value of attribute bot_messages.



5
6
7
# File 'lib/wit_bot/models/message_thread.rb', line 5

def bot_messages
  @bot_messages
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/wit_bot/models/message_thread.rb', line 5

def id
  @id
end

#messagesObject (readonly)

Returns the value of attribute messages.



5
6
7
# File 'lib/wit_bot/models/message_thread.rb', line 5

def messages
  @messages
end

#metadataObject

Returns the value of attribute metadata.



3
4
5
# File 'lib/wit_bot/models/message_thread.rb', line 3

def 
  
end

Instance Method Details

#contextObject



31
32
33
# File 'lib/wit_bot/models/message_thread.rb', line 31

def context
  @context ||= Context.new
end

#create_bot_message(text, id = SecureRandom.uuid) ⇒ Object



27
28
29
# File 'lib/wit_bot/models/message_thread.rb', line 27

def create_bot_message(text, id=SecureRandom.uuid)
  @bot_messages[id] = WitBot::Bot::Message.new self, text, id: id
end

#create_message(text, id = SecureRandom.uuid) ⇒ Object



23
24
25
# File 'lib/wit_bot/models/message_thread.rb', line 23

def create_message(text, id=SecureRandom.uuid)
  @messages[id] = WitBot::Message.new self, text, id: id
end

#message(id) ⇒ Object



13
14
15
# File 'lib/wit_bot/models/message_thread.rb', line 13

def message(id)
  messages[id]
end

#messages_list(user: true, bot: false) ⇒ Object



17
18
19
20
21
# File 'lib/wit_bot/models/message_thread.rb', line 17

def messages_list(user: true, bot: false)
  bot_messages = bot ? @bot_messages.values : []
  user_messages = user ? @messages.values : []
  bot_messages + user_messages
end

#reset_contextObject



35
36
37
# File 'lib/wit_bot/models/message_thread.rb', line 35

def reset_context
  @context = Context.new
end