Class: Pandorified::Session
- Inherits:
-
Object
- Object
- Pandorified::Session
- Defined in:
- lib/pandorified/session.rb
Overview
Represents a session (or conversation) for interacting with a bot.
Instance Method Summary collapse
-
#initialize(botid, custid = nil) ⇒ Session
constructor
A new session for conversing with a bot.
-
#talk(input) ⇒ Pandorified::Result
Send a message to this session’s bot and receive a response.
-
#talk!(input) ⇒ String
Send a message to this session’s bot and receive a response (if successful).
Constructor Details
#initialize(botid, custid = nil) ⇒ Session
Note:
If you choose not to specify a custid, one will be automatically chosen and remembered throughout the session.
A new session for conversing with a bot.
23 24 25 26 |
# File 'lib/pandorified/session.rb', line 23 def initialize(botid, custid = nil) @botid = botid @custid = custid end |
Instance Method Details
#talk(input) ⇒ Pandorified::Result
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pandorified/session.rb', line 39 def talk(input) response_body = post_talk_xml!( botid: @botid, custid: @custid, input: input ) result = Pandorified::Result.new(response_body) @custid ||= result.custid if result.success? result end |
#talk!(input) ⇒ String
Send a message to this session’s bot and receive a response (if successful).
If Pandorabots API responds with an error, PandorabotsError is raised with the specific error message.
If you’d like to check for and handle the error yourself, you can use #talk instead of this method.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pandorified/session.rb', line 65 def talk!(input) result = talk(input) if result.error? msg = "Pandorabots returned status #{result.status}: #{result.}" raise Pandorified::PandorabotsError, msg end result.that end |