Class: Adhearsion::IVRController
- Inherits:
-
CallController
- Object
- CallController
- Adhearsion::IVRController
- Defined in:
- lib/adhearsion-ivr/ivr_controller.rb
Class Attribute Summary collapse
-
.completion_callback ⇒ Object
readonly
Returns the value of attribute completion_callback.
-
.failure_callback ⇒ Object
readonly
Returns the value of attribute failure_callback.
Class Method Summary collapse
-
.max_attempts(num = nil) ⇒ Object
maximum number of attempts to prompt the caller for input.
-
.on_complete(&block) ⇒ Object
called when the caller successfully provides input.
-
.on_failure(&block) ⇒ Object
Called when the caller errors more than the number of allowed attempts.
-
.prompts ⇒ Object
list of prompts to be played to the caller.
Instance Method Summary collapse
- #completion_callback ⇒ Object
- #continue? ⇒ Boolean
- #deliver_prompt ⇒ Object
- #failure_callback ⇒ Object
- #grammar ⇒ Object
- #increment_errors ⇒ Object
- #run ⇒ Object
Class Attribute Details
.completion_callback ⇒ Object (readonly)
Returns the value of attribute completion_callback.
30 31 32 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 30 def completion_callback @completion_callback end |
.failure_callback ⇒ Object (readonly)
Returns the value of attribute failure_callback.
36 37 38 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 36 def failure_callback @failure_callback end |
Class Method Details
.max_attempts(num = nil) ⇒ Object
maximum number of attempts to prompt the caller for input
18 19 20 21 22 23 24 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 18 def max_attempts(num = nil) if num @max_attempts = num else @max_attempts || 3 end end |
.on_complete(&block) ⇒ Object
called when the caller successfully provides input
27 28 29 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 27 def on_complete(&block) @completion_callback = block end |
.on_failure(&block) ⇒ Object
Called when the caller errors more than the number of allowed attempts
33 34 35 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 33 def on_failure(&block) @failure_callback = block end |
.prompts ⇒ Object
list of prompts to be played to the caller. this should have one prompt for each attempt in case there are not enough prompts, the final prompt will be re-used until the max_attempts are exceeded.
13 14 15 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 13 def prompts @prompts ||= [] end |
Instance Method Details
#completion_callback ⇒ Object
110 111 112 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 110 def completion_callback instance_exec @result, &self.class.completion_callback if self.class.completion_callback end |
#continue? ⇒ Boolean
106 107 108 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 106 def continue? @errors < self.class.max_attempts end |
#deliver_prompt ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 73 def deliver_prompt prompt = self.class.prompts[@errors] || self.class.prompts.last prompt = instance_exec(&prompt) if prompt.respond_to? :call logger.debug "Prompt: #{prompt.inspect}" @result = ask prompt, grammar: grammar, mode: :voice logger.debug "Got result #{@result.inspect}" case @result.status when :match match! when :stop logger.info "Prompt was stopped forcibly. Exiting cleanly..." when :hangup logger.info "Call was hung up mid-prompt. Exiting controller flow..." raise Adhearsion::Call::Hangup when :nomatch nomatch! when :noinput noinput! else raise "Unrecognized result status: #{@result.status}" end @result end |
#failure_callback ⇒ Object
114 115 116 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 114 def failure_callback instance_exec &self.class.failure_callback if self.class.failure_callback end |
#grammar ⇒ Object
98 99 100 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 98 def grammar raise NotImplementedError, "You must override #grammar and provide a grammar" end |
#increment_errors ⇒ Object
102 103 104 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 102 def increment_errors @errors += 1 end |
#run ⇒ Object
68 69 70 71 |
# File 'lib/adhearsion-ivr/ivr_controller.rb', line 68 def run @errors = 0 deliver_prompt end |