Class: Punchblock::Component::Tropo::Say

Inherits:
ComponentNode show all
Includes:
MediaContainer
Defined in:
lib/punchblock/component/tropo/say.rb

Direct Known Subclasses

Transfer::Ring

Defined Under Namespace

Classes: Complete, Pause, Resume

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 included from MediaContainer

#inspect_attributes, #ssml, #ssml=, #voice, #voice=

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, #inspect_attributes, register, #source

Constructor Details

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

Class Method Details

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

Creates an Rayo Say command

Examples:

say :text => 'Hello brown cow.'

returns:
  <say xmlns="urn:xmpp:tropo:say:1">Hello brown cow.</say>

Parameters:

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

Options Hash (options):

  • :text (String, Optional)

    to speak back

  • :voice (String, Optional)

    with which to render TTS

  • :ssml (String, Optional)

    document to render TTS

Returns:

  • (Command::Say)

    an Rayo “say” command



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/punchblock/component/tropo/say.rb', line 25

def self.new(options = {})
  super().tap do |new_node|
    case options
    when Hash
      new_node.voice = options.delete(:voice) if options[:voice]
      new_node.ssml = options.delete(:ssml) if options[:ssml]
      new_node << options.delete(:text) if options[:text]
    when Nokogiri::XML::Element
      new_node.inherit options
    end
  end
end

Instance Method Details

#pause!Object

Sends an Rayo pause message for the current Say

Raises:



64
65
66
67
68
69
70
# File 'lib/punchblock/component/tropo/say.rb', line 64

def pause!
  raise InvalidActionError, "Cannot pause a Say that is not executing" unless executing?
  pause_action.tap do |action|
    result = write_action action
    paused! if result
  end
end

#pause_actionCommand::Say::Pause

Pauses a running Say

Examples:

say_obj.pause_action.to_xml

returns:
  <pause xmlns="urn:xmpp:tropo:say:1"/>

Returns:

  • (Command::Say::Pause)

    an Rayo pause message for the current Say



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

def pause_action
  Pause.new :component_id => component_id, :call_id => call_id
end

#resume!Object

Sends an Rayo resume message for the current Say

Raises:



89
90
91
92
93
94
95
# File 'lib/punchblock/component/tropo/say.rb', line 89

def resume!
  raise InvalidActionError, "Cannot resume a Say that is not paused." unless paused?
  resume_action.tap do |action|
    result = write_action action
    resumed! if result
  end
end

#resume_actionCommand::Say::Resume

Create an Rayo resume message for the current Say

Examples:

say_obj.resume_action.to_xml

returns:
  <resume xmlns="urn:xmpp:tropo:say:1"/>

Returns:

  • (Command::Say::Resume)

    an Rayo resume message



82
83
84
# File 'lib/punchblock/component/tropo/say.rb', line 82

def resume_action
  Resume.new :component_id => component_id, :call_id => call_id
end