Class: Punchblock::Component::Tropo::Ask

Inherits:
ComponentNode show all
Defined in:
lib/punchblock/component/tropo/ask.rb

Defined Under Namespace

Classes: Choices, Complete, Prompt

Instance Attribute Summary

Attributes inherited from ComponentNode

#complete_event

Attributes inherited from RayoNode

#call_id, #client, #component_id, #connection, #original_component

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComponentNode

#add_event, #initialize, #register_event_handler, #register_initial_handlers, #response=, #stop!, #stop_action, #write_action

Methods inherited from Punchblock::CommandNode

#initialize, #response, #response=, #write_attr

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, register, #source

Constructor Details

This class inherits a constructor from Punchblock::Component::ComponentNode

Class Method Details

.new(options = {}) ⇒ Command::Ask

Create an ask message

Examples:

ask :prompt      => {:text => 'Please enter your postal code.', :voice => 'simon'},
    :choices     => {:value => '[5 DIGITS]'},
    :timeout     => 30,
    :recognizer  => 'es-es'

returns:
  <ask xmlns="urn:xmpp:tropo:ask:1" timeout="30" recognizer="es-es">
    <prompt voice='simon'>Please enter your postal code.</prompt>
    <choices content-type="application/grammar+voxeo">[5 DIGITS]</choices>
  </ask>

Parameters:

  • options (Hash) (defaults to: {})

    for asking/prompting a specific call

Options Hash (options):

  • :choices (Choices, Hash)

    to allow the user to input

  • :prompt (Prompt, Hash, Optional)

    to play/read to the caller as the question

  • :mode (Symbol, Optional)

    by which to accept input. Can be :speech, :dtmf or :any

  • :timeout (Integer, Optional)

    to wait for user input

  • :bargein (Boolean, Optional)

    wether or not to allow the caller to begin their response before the prompt finishes

  • :recognizer (String, Optional)

    to use for speech recognition

  • :terminator (String, Optional)

    by which to signal the end of input

  • :min_confidence (Float, Optional)

    with which to consider a response acceptable

Returns:

  • (Command::Ask)

    a formatted Rayo ask command



34
35
36
37
38
# File 'lib/punchblock/component/tropo/ask.rb', line 34

def self.new(options = {})
  super().tap do |new_node|
    options.each_pair { |k,v| new_node.send :"#{k}=", v }
  end
end

Instance Method Details

#bargeinBoolean

Returns wether or not to allow the caller to begin their response before the prompt finishes.

Returns:

  • (Boolean)

    wether or not to allow the caller to begin their response before the prompt finishes



43
44
45
# File 'lib/punchblock/component/tropo/ask.rb', line 43

def bargein
  read_attr(:bargein) == "true"
end

#bargein=(bargein) ⇒ Object

Parameters:

  • bargein (Boolean)

    wether or not to allow the caller to begin their response before the prompt finishes



50
51
52
# File 'lib/punchblock/component/tropo/ask.rb', line 50

def bargein=(bargein)
  write_attr :bargein, bargein.to_s
end

#choicesChoices

Returns the choices available.

Returns:

  • (Choices)

    the choices available



149
150
151
# File 'lib/punchblock/component/tropo/ask.rb', line 149

def choices
  Choices.new find_first('ns:choices', :ns => self.class.registered_ns)
end

#choices=(choices) ⇒ Object

Parameters:

Options Hash (choices):

  • :content_type (String)
  • :value (String)

    the choices available



158
159
160
161
162
# File 'lib/punchblock/component/tropo/ask.rb', line 158

def choices=(choices)
  remove_children :choices
  choices = Choices.new(choices) unless choices.is_a?(Choices)
  self << choices
end

#inspect_attributesObject

:nodoc:



164
165
166
# File 'lib/punchblock/component/tropo/ask.rb', line 164

def inspect_attributes # :nodoc:
  [:bargein, :min_confidence, :mode, :recognizer, :terminator, :timeout, :prompt, :choices] + super
end

#min_confidenceFloat

Returns Confidence with which to consider a response acceptable.

Returns:

  • (Float)

    Confidence with which to consider a response acceptable



57
58
59
# File 'lib/punchblock/component/tropo/ask.rb', line 57

def min_confidence
  read_attr 'min-confidence', :to_f
end

#min_confidence=(min_confidence) ⇒ Object

Parameters:

  • min_confidence (Float)

    with which to consider a response acceptable



64
65
66
# File 'lib/punchblock/component/tropo/ask.rb', line 64

def min_confidence=(min_confidence)
  write_attr 'min-confidence', min_confidence
end

#modeSymbol

Returns mode by which to accept input. Can be :speech, :dtmf or :any.

Returns:

  • (Symbol)

    mode by which to accept input. Can be :speech, :dtmf or :any



71
72
73
# File 'lib/punchblock/component/tropo/ask.rb', line 71

def mode
  read_attr :mode, :to_sym
end

#mode=(mode) ⇒ Object

Parameters:

  • mode (Symbol)

    by which to accept input. Can be :speech, :dtmf or :any



78
79
80
# File 'lib/punchblock/component/tropo/ask.rb', line 78

def mode=(mode)
  write_attr :mode, mode
end

#promptPrompt

Returns the prompt by which to introduce the question.

Returns:

  • (Prompt)

    the prompt by which to introduce the question



127
128
129
# File 'lib/punchblock/component/tropo/ask.rb', line 127

def prompt
  Prompt.new find_first('//ns:prompt', :ns => self.registered_ns)
end

#prompt=(p) ⇒ Object

Parameters:

Options Hash (p):

  • :text (String)

    to read the caller via TTS as the question

  • :voice (String)

    to use for speech synthesis



136
137
138
139
140
# File 'lib/punchblock/component/tropo/ask.rb', line 136

def prompt=(p)
  remove_children :prompt
  p = Prompt.new(p) unless p.is_a?(Prompt)
  self << p
end

#recognizerString

Returns recognizer to use for speech recognition.

Returns:

  • (String)

    recognizer to use for speech recognition



85
86
87
# File 'lib/punchblock/component/tropo/ask.rb', line 85

def recognizer
  read_attr :recognizer
end

#recognizer=(recognizer) ⇒ Object

Parameters:

  • recognizer (String)

    to use for speech recognition



92
93
94
# File 'lib/punchblock/component/tropo/ask.rb', line 92

def recognizer=(recognizer)
  write_attr :recognizer, recognizer
end

#terminatorString

Returns terminator by which to signal the end of input.

Returns:

  • (String)

    terminator by which to signal the end of input



99
100
101
# File 'lib/punchblock/component/tropo/ask.rb', line 99

def terminator
  read_attr :terminator
end

#terminator=(terminator) ⇒ Object

Parameters:

  • terminator (String)

    by which to signal the end of input



106
107
108
# File 'lib/punchblock/component/tropo/ask.rb', line 106

def terminator=(terminator)
  write_attr :terminator, terminator
end

#timeoutInteger

Returns timeout to wait for user input.

Returns:

  • (Integer)

    timeout to wait for user input



113
114
115
# File 'lib/punchblock/component/tropo/ask.rb', line 113

def timeout
  read_attr :timeout, :to_i
end

#timeout=(timeout) ⇒ Object

Parameters:

  • timeout (Integer)

    to wait for user input



120
121
122
# File 'lib/punchblock/component/tropo/ask.rb', line 120

def timeout=(timeout)
  write_attr :timeout, timeout
end