diff --git a/fixtures/response-dialogConfirmIntentDirective.json b/fixtures/response-dialogConfirmIntentDirective.json new file mode 100644 index 0000000..8f02149 --- /dev/null +++ b/fixtures/response-dialogConfirmIntentDirective.json @@ -0,0 +1,26 @@ +{ + "version": "1.0", + "response": { + "directives": [ + { + "type": "Dialog.ConfirmIntent", + "updatedIntent": { + "name": "GetZodiacHoroscopeIntent", + "confirmationStatus": "NONE", + "slots": { + "City": { + "name": "City", + "confirmationStatus": "NONE" + }, + "ZodiacSign": { + "name": "ZodiacSign", + "value": "virgo", + "confirmationStatus": "NONE" + } + } + } + } + ], + "shouldEndSession" :true + } +} diff --git a/fixtures/response-dialogConfirmSlotDirective.json b/fixtures/response-dialogConfirmSlotDirective.json new file mode 100644 index 0000000..52b4009 --- /dev/null +++ b/fixtures/response-dialogConfirmSlotDirective.json @@ -0,0 +1,27 @@ +{ + "version": "1.0", + "response": { + "directives": [ + { + "type": "Dialog.ConfirmSlot", + "slotToConfirm": "ZodiacSign", + "updatedIntent": { + "name": "GetZodiacHoroscopeIntent", + "confirmationStatus": "NONE", + "slots": { + "City": { + "name": "City", + "confirmationStatus": "NONE" + }, + "ZodiacSign": { + "name": "ZodiacSign", + "value": "virgo", + "confirmationStatus": "NONE" + } + } + } + } + ], + "shouldEndSession" :true + } +} diff --git a/fixtures/response-dialogDelegateDirective.json b/fixtures/response-dialogDelegateDirective.json new file mode 100644 index 0000000..00f61e8 --- /dev/null +++ b/fixtures/response-dialogDelegateDirective.json @@ -0,0 +1,26 @@ +{ + "version": "1.0", + "response": { + "directives": [ + { + "type": "Dialog.Delegate", + "updatedIntent": { + "name": "GetZodiacHoroscopeIntent", + "confirmationStatus": "NONE", + "slots": { + "City": { + "name": "City", + "confirmationStatus": "NONE" + }, + "ZodiacSign": { + "name": "ZodiacSign", + "value": "virgo", + "confirmationStatus": "NONE" + } + } + } + } + ], + "shouldEndSession" :true + } +} diff --git a/fixtures/response-dialogElicitSlotDirective.json b/fixtures/response-dialogElicitSlotDirective.json new file mode 100644 index 0000000..3e192b1 --- /dev/null +++ b/fixtures/response-dialogElicitSlotDirective.json @@ -0,0 +1,27 @@ +{ + "version": "1.0", + "response": { + "directives": [ + { + "type": "Dialog.ElicitSlot", + "slotToElicit": "City", + "updatedIntent": { + "name": "GetZodiacHoroscopeIntent", + "confirmationStatus": "NONE", + "slots": { + "City": { + "name": "City", + "confirmationStatus": "NONE" + }, + "ZodiacSign": { + "name": "ZodiacSign", + "value": "virgo", + "confirmationStatus": "NONE" + } + } + } + } + ], + "shouldEndSession" :true + } +} diff --git a/fixtures/sample-Intent.json b/fixtures/sample-Intent.json new file mode 100644 index 0000000..f51bbf5 --- /dev/null +++ b/fixtures/sample-Intent.json @@ -0,0 +1,15 @@ +{ + "name": "GetZodiacHoroscopeIntent", + "confirmationStatus": "NONE", + "slots": { + "City": { + "name": "City", + "confirmationStatus": "NONE" + }, + "ZodiacSign": { + "name": "ZodiacSign", + "value": "virgo", + "confirmationStatus": "NONE" + } + } +} diff --git a/fixtures/sample-IntentRequest.json b/fixtures/sample-IntentRequest.json index 095dba1..23b8900 100644 --- a/fixtures/sample-IntentRequest.json +++ b/fixtures/sample-IntentRequest.json @@ -19,12 +19,14 @@ "requestId": "amzn1.echo-api.request.6919844a-733e-4e89-893a-fdcb77e2ef0d", "intent": { "name": "GetZodiacHoroscopeIntent", + "confirmationStatus": "NONE", "slots": { "ZodiacSign": { "name": "ZodiacSign", - "value": "virgo" + "value": "virgo", + "confirmationStatus": "NONE" } } } } -} \ No newline at end of file +} diff --git a/lib/alexa_rubykit/request.rb b/lib/alexa_rubykit/request.rb index 4a18dae..f79d5a3 100644 --- a/lib/alexa_rubykit/request.rb +++ b/lib/alexa_rubykit/request.rb @@ -6,7 +6,7 @@ module AlexaRubykit class Request require 'json' require 'alexa_rubykit/session' - attr_accessor :version, :type, :session, :json # global + attr_accessor :version, :type, :session, :json, :dialog_state# global attr_accessor :request_id, :locale # on request def initialize(json_request) @@ -15,6 +15,7 @@ def initialize(json_request) @version = json_request['version'] @locale = json_request['request']['locale'] @json = json_request + @dialog_state = json_request['request']['dialogState'] # TODO: We probably need better session handling. @session = AlexaRubykit::Session.new(json_request['session']) diff --git a/lib/alexa_rubykit/response.rb b/lib/alexa_rubykit/response.rb index 58d807d..b08bb0b 100644 --- a/lib/alexa_rubykit/response.rb +++ b/lib/alexa_rubykit/response.rb @@ -24,7 +24,7 @@ def add_speech(speech_text, ssml = false) end @speech end - + def add_audio_url(url, token='', offset=0) @directives << { 'type' => 'AudioPlayer.Play', @@ -39,6 +39,36 @@ def add_audio_url(url, token='', offset=0) } end + def add_dialog_delegate_directive(intent:) + @directives << { + 'type' => 'Dialog.Delegate', + 'updatedIntent' => intent + } + end + + def add_dialog_elicit_slot_directive(slot_to_elicit:, intent:) + @directives << { + 'type' => 'Dialog.ElicitSlot', + 'slotToElicit' => slot_to_elicit, + 'updatedIntent' => intent + } + end + + def add_dialog_confirm_slot_directive(slot_to_confirm:, intent:) + @directives << { + 'type' => 'Dialog.ConfirmSlot', + 'slotToConfirm' => slot_to_confirm, + 'updatedIntent' => intent + } + end + + def add_dialog_confirm_intent_directive(intent:) + @directives << { + 'type' => 'Dialog.ConfirmIntent', + 'updatedIntent' => intent + } + end + def add_reprompt(speech_text, ssml = false) if ssml @reprompt = { "outputSpeech" => { :type => 'SSML', :ssml => check_ssml(speech_text) } } @@ -48,7 +78,6 @@ def add_reprompt(speech_text, ssml = false) @reprompt end - # #"type": "string", # "title": "string", # "subtitle": "string", @@ -128,4 +157,4 @@ def check_ssml(ssml_string) ssml_string.strip[-8..1] == "" ? ssml_string : ssml_string + "" end end -end \ No newline at end of file +end diff --git a/lib/alexa_rubykit/version.rb b/lib/alexa_rubykit/version.rb index 304602e..e05577e 100644 --- a/lib/alexa_rubykit/version.rb +++ b/lib/alexa_rubykit/version.rb @@ -1,3 +1,3 @@ module AlexaRubykit - VERSION = '1.3.0' + VERSION = '1.3.1' end diff --git a/spec/response_spec.rb b/spec/response_spec.rb index 8b3d742..e690b1b 100644 --- a/spec/response_spec.rb +++ b/spec/response_spec.rb @@ -113,7 +113,7 @@ sample_json = JSON.parse(File.read('fixtures/response-sessionAtt.json')).to_json expect(response_json).to eq(sample_json) end - + it 'should create a valid response with an audio stream directive' do response = AlexaRubykit::Response.new response.add_audio_url('http://test/url.mp3','token',100) @@ -123,4 +123,48 @@ expect(response_json).to eq(sample_json) end -end \ No newline at end of file + it 'should create a valid response with a dialog delegate directive' do + response = AlexaRubykit::Response.new + intent = JSON.parse(File.read('fixtures/sample-Intent.json')) + response.add_dialog_delegate_directive(intent: intent) + response.build_response_object + response_json = response.build_response + sample_json = JSON.parse(File.read('fixtures/response-dialogDelegateDirective.json')).to_json + expect(response_json).to eq(sample_json) + end + + it 'should create a valid response with a dialog confirm intent directive' do + response = AlexaRubykit::Response.new + intent = JSON.parse(File.read('fixtures/sample-Intent.json')) + response.add_dialog_confirm_intent_directive(intent: intent) + response.build_response_object + response_json = response.build_response + sample_json = JSON.parse(File.read('fixtures/response-dialogConfirmIntentDirective.json')).to_json + expect(response_json).to eq(sample_json) + end + + it 'should create a valid response with a dialog confirm slot directive' do + response = AlexaRubykit::Response.new + intent = JSON.parse(File.read('fixtures/sample-Intent.json')) + response.add_dialog_confirm_slot_directive(slot_to_confirm: 'ZodiacSign', intent: intent) + response.build_response_object + response_json = response.build_response + sample_json = JSON.parse(File.read('fixtures/response-dialogConfirmSlotDirective.json')).to_json + puts '' + puts response_json + puts sample_json + expect(response_json).to eq(sample_json) + end + + it 'should create a valid response with a dialog elicit slot directive' do + response = AlexaRubykit::Response.new + intent = JSON.parse(File.read('fixtures/sample-Intent.json')) + response.add_dialog_elicit_slot_directive(slot_to_elicit: 'City', intent: intent) + response.build_response_object + response_json = response.build_response + sample_json = JSON.parse(File.read('fixtures/response-dialogElicitSlotDirective.json')).to_json + expect(response_json).to eq(sample_json) + end + + +end