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.
19 20 21 22 |
# File 'lib/pandorified/session.rb', line 19 def initialize(botid, custid = nil) @botid = botid @custid = custid end |
Instance Method Details
#talk(input) ⇒ Pandorified::Result
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pandorified/session.rb', line 35 def talk(input) result = Pandorified::Result.new( botid: @botid, custid: @custid, input: input ) @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.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pandorified/session.rb', line 60 def talk!(input) result = talk(input) if result.error? msg = "Pandorabots returned status #{result.status}: #{result.}" raise Pandorified::PandorabotsError, msg end result.that end |