Class: WitBot::Message
- Inherits:
-
Object
- Object
- WitBot::Message
- Defined in:
- lib/wit_bot/models/message.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_outcomes ⇒ Object
readonly
Returns the value of attribute _outcomes.
-
#_text ⇒ Object
readonly
Returns the value of attribute _text.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#outcomes ⇒ Object
readonly
Returns the value of attribute outcomes.
-
#sent ⇒ Object
readonly
Returns the value of attribute sent.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #bot? ⇒ Boolean
-
#initialize(thread = WitBot.thread, text, id: SecureRandom.uuid) ⇒ Message
constructor
A new instance of Message.
- #outcome ⇒ Object
- #params(p = nil) ⇒ Object
- #send(n = 1, keep_context = true) ⇒ Object
Constructor Details
#initialize(thread = WitBot.thread, text, id: SecureRandom.uuid) ⇒ Message
Returns a new instance of Message.
5 6 7 8 9 10 11 12 |
# File 'lib/wit_bot/models/message.rb', line 5 def initialize(thread=WitBot.thread, text, id: SecureRandom.uuid) @thread = thread @text = text @_text = nil @id = id @sent = false @outcomes = @_outcomes = nil end |
Instance Attribute Details
#_outcomes ⇒ Object (readonly)
Returns the value of attribute _outcomes.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def _outcomes @_outcomes end |
#_text ⇒ Object (readonly)
Returns the value of attribute _text.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def _text @_text end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def id @id end |
#outcomes ⇒ Object (readonly)
Returns the value of attribute outcomes.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def outcomes @outcomes end |
#sent ⇒ Object (readonly)
Returns the value of attribute sent.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def sent @sent end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def text @text end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
3 4 5 |
# File 'lib/wit_bot/models/message.rb', line 3 def thread @thread end |
Instance Method Details
#bot? ⇒ Boolean
14 15 16 |
# File 'lib/wit_bot/models/message.rb', line 14 def bot? false end |
#outcome ⇒ Object
41 42 43 |
# File 'lib/wit_bot/models/message.rb', line 41 def outcome outcomes.first end |
#params(p = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/wit_bot/models/message.rb', line 18 def params(p=nil) params = { q: text, msg_id: id, thread_id: thread.id } params[:context] = JSON.dump thread.context.as_json unless thread.context.empty? p ? params.merge(p) : params end |
#send(n = 1, keep_context = true) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wit_bot/models/message.rb', line 28 def send(n=1, keep_context=true) response = MessageRequest.new.request(self, n) @sent = true thread.reset_context unless keep_context @_text = response['_text'] @_outcomes = response['outcomes'] @outcomes = @_outcomes.each_with_index.map { |outcome, i| Outcome.new self, outcome, i } self end |