class AlexaWebService::Response

Attributes

card[RW]
directives[RW]
end_session[RW]
reprompt_text[RW]
session_attributes[RW]
speech_type[RW]
spoken_response[RW]
text_type[RW]

Public Class Methods

new() click to toggle source
# File lib/alexa_web_service/response.rb, line 7
def initialize
  @session_attributes = {}
  @speech_type        = "PlainText"
  @spoken_response    = ''
  @reprompt_text      = ''
  @text_type          = "text"
  @end_session        = 'true'
  @card               = nil
  @directives         = []
end

Public Instance Methods

add_attribute(key, value) click to toggle source
# File lib/alexa_web_service/response.rb, line 18
def add_attribute(key, value)
  @session_attributes.merge!(key => value)
end
add_card(card) click to toggle source
# File lib/alexa_web_service/response.rb, line 38
def add_card(card)
  self.card = card
end
add_directive(directive) click to toggle source
# File lib/alexa_web_service/response.rb, line 30
def add_directive(directive)
  if directive[:type] == "Display.RenderTemplate"|| directive[:type] == "Hint"
    self.directives << directive if $display_support == true
  else
    self.directives << directive
  end
end
append_attribute(key, value) click to toggle source
# File lib/alexa_web_service/response.rb, line 26
def append_attribute(key, value)
  @session_attributes[key] << value if @session_attributes[key] != nil
end
delete_attribute(key) click to toggle source
# File lib/alexa_web_service/response.rb, line 22
def delete_attribute(key)
  @session_attributes.delete(key)
end
post() click to toggle source
# File lib/alexa_web_service/response.rb, line 42
def post
  {
    "version": "1.0",
    "sessionAttributes": @session_attributes,  
    "response": {
      "outputSpeech": {
        "type": speech_type,
        "#{text_type}": spoken_response
      },
      "card": card,
      "reprompt": {
        "outputSpeech": {
          "type": speech_type,
          "text": reprompt_text
        }
      },
      "directives": @directives,
      "shouldEndSession": end_session
    }
  }.to_json
end