Class: Clova::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/clova-speech/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
# File 'lib/clova-speech/response.rb', line 5

def initialize
  @default_language = 'ja'
  @version = Clova::VERSION
  @output_speech = OutputSpeech.new
  @session_attributes = {}
  @directives = []
  @should_end_session = false
  @card = {}
  @reprompt_speech = OutputSpeech.new
end

Instance Attribute Details

#cardObject

Returns the value of attribute card.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def card
  @card
end

#default_languageObject

Returns the value of attribute default_language.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def default_language
  @default_language
end

#directivesObject

Returns the value of attribute directives.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def directives
  @directives
end

#output_speechObject

Returns the value of attribute output_speech.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def output_speech
  @output_speech
end

#reprompt_speechObject

Returns the value of attribute reprompt_speech.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def reprompt_speech
  @reprompt_speech
end

#session_attributesObject

Returns the value of attribute session_attributes.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def session_attributes
  @session_attributes
end

#should_end_sessionObject

Returns the value of attribute should_end_session.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def should_end_session
  @should_end_session
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def type
  @type
end

#versionObject

Returns the value of attribute version.



3
4
5
# File 'lib/clova-speech/response.rb', line 3

def version
  @version
end

Instance Method Details

#add_reprompt(value, type: 'PlainText') ⇒ Object



33
34
35
# File 'lib/clova-speech/response.rb', line 33

def add_reprompt(value, type: 'PlainText')
  @reprompt_speech.add_speech(value: value, type: type)
end

#add_session_attribute(key:, value:) ⇒ Object



24
25
26
# File 'lib/clova-speech/response.rb', line 24

def add_session_attribute(key:, value:)
  @session_attributes[key] = value
end

#add_speech(value, type: 'PlainText', language: @default_language) ⇒ Object

type either is ‘PlainText’ or ‘URL’



29
30
31
# File 'lib/clova-speech/response.rb', line 29

def add_speech(value, type:'PlainText', language: @default_language)
  @output_speech.add_speech(value: value, type: type, language: language)
end

#as_jsonObject



16
17
18
19
20
21
22
# File 'lib/clova-speech/response.rb', line 16

def as_json
  {
      version: version,
      sessionAttributes: session_attributes,
      response: response
  }
end

#responseObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/clova-speech/response.rb', line 41

def response
  hash = {
      outputSpeech: output_speech.as_json,
      card: card,
      directives: directives,
      shouldEndSession: should_end_session
  }

  if !@reprompt_speech.empty?
    hash[:reprompt] = {outputSpeech: reprompt_speech.as_json}
  end
  hash
end