Skip to content

Commit

Permalink
Support for Echo Show version 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
odintsovamz committed Jun 29, 2017
1 parent 40ab702 commit 4916e9a
Show file tree
Hide file tree
Showing 61 changed files with 2,620 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.amazon.alexa</groupId>
<artifactId>alexa-skills-kit</artifactId>
<packaging>jar</packaging>
<version>1.3.1</version>
<version>1.4.0</version>
<name>Alexa Skills Kit</name>
<description>Contains classes used by the Alexa Skills Kit.</description>
<url>http://developer.amazon.com/ask</url>
Expand Down
2 changes: 1 addition & 1 deletion src/com/amazon/speech/Sdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public final class Sdk {
/**
* The version number for this library.
* The version number for request and response layout.
*/
public static final String VERSION = "1.0";

Expand Down
2 changes: 1 addition & 1 deletion src/com/amazon/speech/json/ContextDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Context deserialize(JsonParser parser, DeserializationContext context)
Context.Builder contextBuilder = Context.builder();

for (SerializedInterface interfaceName : SerializedInterface.values()) {
if (messageNode.has(interfaceName.name())) {
if (messageNode.has(interfaceName.name()) && (interfaceName.getStateClass() != null)) {
State<?> state =
underlyingMapper.convertValue(messageNode.get(interfaceName.name()),
interfaceName.getStateClass());
Expand Down
13 changes: 10 additions & 3 deletions src/com/amazon/speech/json/SerializedInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,34 @@
import com.amazon.speech.speechlet.State;
import com.amazon.speech.speechlet.interfaces.audioplayer.AudioPlayerInterface;
import com.amazon.speech.speechlet.interfaces.audioplayer.AudioPlayerState;
import com.amazon.speech.speechlet.interfaces.display.DisplayInterface;
import com.amazon.speech.speechlet.interfaces.display.DisplayState;
import com.amazon.speech.speechlet.interfaces.system.SystemInterface;
import com.amazon.speech.speechlet.interfaces.system.SystemState;
import com.amazon.speech.speechlet.interfaces.videoapp.VideoAppInterface;

enum SerializedInterface {
AudioPlayer(AudioPlayerInterface.class, AudioPlayerState.class),
Display(DisplayInterface.class, DisplayState.class),
VideoApp(VideoAppInterface.class, null /* no state */),
System(SystemInterface.class, SystemState.class);

private final Class<? extends Interface> interfaceClass;
private final Class<? extends State> stateClass;
private final Class<? extends State<?>> stateClass;

SerializedInterface(final Class<? extends Interface> interfaceClass,
final Class<? extends State> stateClass) {
final Class<? extends State<?>> stateClass) {
this.interfaceClass = interfaceClass;
this.stateClass = stateClass;
}

@SuppressWarnings("unchecked")
protected <T extends Interface> Class<T> getInterfaceClass() {
return (Class<T>) interfaceClass;
}

protected <T extends State> Class<T> getStateClass() {
@SuppressWarnings("unchecked")
protected <T extends State<?>> Class<T> getStateClass() {
return (Class<T>) stateClass;
}
}
13 changes: 13 additions & 0 deletions src/com/amazon/speech/slu/ConfirmationStatus.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License.
*/

package com.amazon.speech.slu;


Expand Down
8 changes: 7 additions & 1 deletion src/com/amazon/speech/speechlet/Directive.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.amazon.speech.speechlet.interfaces.audioplayer.directive.ClearQueueDirective;
import com.amazon.speech.speechlet.interfaces.audioplayer.directive.PlayDirective;
import com.amazon.speech.speechlet.interfaces.audioplayer.directive.StopDirective;
import com.amazon.speech.speechlet.interfaces.core.directive.HintDirective;
import com.amazon.speech.speechlet.interfaces.display.directive.RenderTemplateDirective;
import com.amazon.speech.speechlet.interfaces.videoapp.directive.LaunchDirective;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

Expand All @@ -29,13 +32,16 @@
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(HintDirective.class),
@JsonSubTypes.Type(PlayDirective.class),
@JsonSubTypes.Type(StopDirective.class),
@JsonSubTypes.Type(ClearQueueDirective.class),
@JsonSubTypes.Type(RenderTemplateDirective.class),
@JsonSubTypes.Type(LaunchDirective.class),
@JsonSubTypes.Type(DelegateDirective.class),
@JsonSubTypes.Type(ElicitSlotDirective.class),
@JsonSubTypes.Type(ConfirmSlotDirective.class),
@JsonSubTypes.Type(ConfirmIntentDirective.class),
@JsonSubTypes.Type(ConfirmIntentDirective.class)
})
public abstract class Directive {
}
3 changes: 2 additions & 1 deletion src/com/amazon/speech/speechlet/IntentRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Date;
import java.util.Locale;

import com.amazon.speech.json.SpeechletRequestEnvelope;
import org.apache.commons.lang3.Validate;

import com.amazon.speech.slu.Intent;
Expand All @@ -25,7 +26,7 @@
/**
* The request object containing an {@link Intent} for {@code SpeechletV2} invocation.
*
* @see SpeechletV2#onIntent
* @see SpeechletV2#onIntent(SpeechletRequestEnvelope)
*/
@JsonTypeName("IntentRequest")
public class IntentRequest extends CoreSpeechletRequest {
Expand Down
1 change: 1 addition & 0 deletions src/com/amazon/speech/speechlet/LaunchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Date;
import java.util.Locale;

import com.amazon.speech.json.SpeechletRequestEnvelope;
import org.apache.commons.lang3.Validate;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
13 changes: 13 additions & 0 deletions src/com/amazon/speech/speechlet/Permissions.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License.
*/

package com.amazon.speech.speechlet;

import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
4 changes: 3 additions & 1 deletion src/com/amazon/speech/speechlet/SessionEndedRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Date;
import java.util.Locale;

import com.amazon.speech.json.SpeechletRequestEnvelope;
import org.apache.commons.lang3.Validate;

import com.amazon.speech.speechlet.interfaces.system.Error;
Expand Down Expand Up @@ -69,7 +70,8 @@ private SessionEndedRequest(final Builder builder) {
private SessionEndedRequest(@JsonProperty("requestId") final String requestId,
@JsonProperty("timestamp") final Date timestamp,
@JsonProperty("locale") final Locale locale,
@JsonProperty("reason") final Reason reason, @JsonProperty("error") final Error error) {
@JsonProperty("reason") final Reason reason,
@JsonProperty("error") final Error error) {
super(requestId, timestamp, locale);
this.reason = reason;
this.error = error;
Expand Down
1 change: 1 addition & 0 deletions src/com/amazon/speech/speechlet/SessionStartedRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Date;
import java.util.Locale;

import com.amazon.speech.json.SpeechletRequestEnvelope;
import org.apache.commons.lang3.Validate;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
2 changes: 1 addition & 1 deletion src/com/amazon/speech/speechlet/Speechlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface Speechlet {
/**
* Callback used to notify that the session ended as a result of the user interacting, or not
* interacting with the device. This method is not invoked if the {@code Speechlet} itself ended
* the session using {@link SpeechletResponse#setShouldEndSession(boolean)}.
* the session using {@link SpeechletResponse#setNullableShouldEndSession(Boolean)}.
*
* @param request
* the end of session request
Expand Down
4 changes: 3 additions & 1 deletion src/com/amazon/speech/speechlet/SpeechletRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.amazon.speech.speechlet.interfaces.audioplayer.request.PlaybackNearlyFinishedRequest;
import com.amazon.speech.speechlet.interfaces.audioplayer.request.PlaybackStartedRequest;
import com.amazon.speech.speechlet.interfaces.audioplayer.request.PlaybackStoppedRequest;
import com.amazon.speech.speechlet.interfaces.display.request.ElementSelectedRequest;
import com.amazon.speech.speechlet.interfaces.playbackcontroller.request.NextCommandIssuedRequest;
import com.amazon.speech.speechlet.interfaces.playbackcontroller.request.PauseCommandIssuedRequest;
import com.amazon.speech.speechlet.interfaces.playbackcontroller.request.PlayCommandIssuedRequest;
Expand Down Expand Up @@ -64,7 +65,8 @@
@Type(value = PauseCommandIssuedRequest.class),
@Type(value = NextCommandIssuedRequest.class),
@Type(value = PreviousCommandIssuedRequest.class),
@Type(value = ExceptionEncounteredRequest.class)
@Type(value = ExceptionEncounteredRequest.class),
@Type(value = ElementSelectedRequest.class)
})
public abstract class SpeechletRequest {
private final String requestId;
Expand Down
30 changes: 25 additions & 5 deletions src/com/amazon/speech/speechlet/SpeechletRequestDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import com.amazon.speech.speechlet.interfaces.audioplayer.request.PlaybackNearlyFinishedRequest;
import com.amazon.speech.speechlet.interfaces.audioplayer.request.PlaybackStartedRequest;
import com.amazon.speech.speechlet.interfaces.audioplayer.request.PlaybackStoppedRequest;
import com.amazon.speech.speechlet.interfaces.display.Display;
import com.amazon.speech.speechlet.interfaces.display.request.DisplayRequest;
import com.amazon.speech.speechlet.interfaces.display.request.ElementSelectedRequest;
import com.amazon.speech.speechlet.interfaces.playbackcontroller.PlaybackController;
import com.amazon.speech.speechlet.interfaces.playbackcontroller.request.NextCommandIssuedRequest;
import com.amazon.speech.speechlet.interfaces.playbackcontroller.request.PauseCommandIssuedRequest;
Expand Down Expand Up @@ -202,6 +205,19 @@ public SpeechletResponseEnvelope dispatchSpeechletCall(
.onExceptionEncountered(typeSpecificRequestEnvelope);
}
}
/** Display **/
} else if (speechletRequest instanceof DisplayRequest) {
if (speechletWithInterfaces instanceof Display) {
Display displaySpeechlet = (Display) speechletWithInterfaces;
if (speechletRequest instanceof ElementSelectedRequest) {
@SuppressWarnings("unchecked")
SpeechletRequestEnvelope<ElementSelectedRequest> typeSpecificRequestEnvelope =
(SpeechletRequestEnvelope<ElementSelectedRequest>) requestEnvelope;
speechletResponse =
displaySpeechlet.onElementSelected(typeSpecificRequestEnvelope);
saveSessionAttributes = shouldSaveSessionAttributes(speechletResponse);
}
}
/** SpeechletV2 **/
} else if (speechletRequest instanceof CoreSpeechletRequest) {
try {
Expand All @@ -223,11 +239,7 @@ public SpeechletResponseEnvelope dispatchSpeechletCall(
speechletResponse = speechlet.onLaunch(parameterizedRequestEnvelope);
}

if (speechletResponse != null) {
saveSessionAttributes = !speechletResponse.getShouldEndSession();
} else {
saveSessionAttributes = true;
}
saveSessionAttributes = shouldSaveSessionAttributes(speechletResponse);
}
} catch (RuntimeException e) {
// Doing this to preserve backwards compatibility if a Speechlet instead of a
Expand Down Expand Up @@ -258,4 +270,12 @@ public SpeechletResponseEnvelope dispatchSpeechletCall(

return responseEnvelope;
}

private boolean shouldSaveSessionAttributes(SpeechletResponse speechletResponse) {
if (speechletResponse != null && speechletResponse.getNullableShouldEndSession() != null) {
return !speechletResponse.getNullableShouldEndSession();
} else {
return true;
}
}
}
47 changes: 44 additions & 3 deletions src/com/amazon/speech/speechlet/SpeechletResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.List;

import com.amazon.speech.json.SpeechletRequestEnvelope;
import com.amazon.speech.ui.Card;
import com.amazon.speech.ui.OutputSpeech;
import com.amazon.speech.ui.Reprompt;
Expand All @@ -32,7 +33,7 @@ public class SpeechletResponse {
private Card card = null;
private List<Directive> directives = null;
private Reprompt reprompt = null;
private boolean shouldEndSession = true;
private Boolean shouldEndSession = true;

/**
* Returns the speech associated with this response.
Expand All @@ -55,10 +56,17 @@ public void setOutputSpeech(final OutputSpeech outputSpeech) {

/**
* Returns whether or not the session should end with this response.
* in case of {@code null} value returns {@code false}
*
* @return whether the session should end
*
* @deprecated with version 1.4.0 replaced with {@link #getNullableShouldEndSession()}
*/
@Deprecated
public boolean getShouldEndSession() {
if(shouldEndSession==null) {
return false;
}
return shouldEndSession;
}

Expand All @@ -67,11 +75,44 @@ public boolean getShouldEndSession() {
*
* @param shouldEndSession
* {@code true} if the session should end with this response
*
* @deprecated with version 1.4.0 {@code null} value is allowed.
* See {@link #setNullableShouldEndSession(Boolean)}
*/
@Deprecated
public void setShouldEndSession(final boolean shouldEndSession) {
this.shouldEndSession = shouldEndSession;
}

/**
* Returns value of shouldEndSession attribute
* <p> {@code false} means session should be kept open and voice command is expected
* <p> {@code true} means session should be terminated
* <p> {@code null} for non-display cases defaults to {@code true} and for display template
* scenarios keeps session open without expecting voice command
* <p> Refer to online documentation for more information
*
* @return value of shouldEndSession attribute
*/
public Boolean getNullableShouldEndSession() {
return shouldEndSession;
}

/**
* Sets value of shouldEndSession attribute
* <p> Set it to {@code true} to end session
* <p> Set it to {@code false} to keep session open and wait for a voice command or response
* <p> Set it to {@code null} to keep session open without waiting for a voice command when
* displaying template. If no template is displayed it will default to
* previous behavior and end session.
* <p> Refer to online documentation for more details.
*
* @param shouldEndSession
* new value of shouldEndSession attribute
*/
public void setNullableShouldEndSession(final Boolean shouldEndSession) {
this.shouldEndSession = shouldEndSession;
}
/**
* Returns the UI card associated with this response.
*
Expand Down Expand Up @@ -146,7 +187,7 @@ public static SpeechletResponse newTellResponse(final OutputSpeech outputSpeech)
}

SpeechletResponse response = new SpeechletResponse();
response.setShouldEndSession(true);
response.setNullableShouldEndSession(true);
response.setOutputSpeech(outputSpeech);
return response;
}
Expand Down Expand Up @@ -200,7 +241,7 @@ public static SpeechletResponse newAskResponse(final OutputSpeech outputSpeech,
}

SpeechletResponse response = new SpeechletResponse();
response.setShouldEndSession(false);
response.setNullableShouldEndSession(false);
response.setOutputSpeech(outputSpeech);
response.setReprompt(reprompt);
return response;
Expand Down
2 changes: 1 addition & 1 deletion src/com/amazon/speech/speechlet/SpeechletV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public interface SpeechletV2 {
/**
* Callback used to notify that the session ended as a result of the user interacting, or not
* interacting with the device. This method is not invoked if the {@code SpeechletV2} itself
* ended the session using {@link SpeechletResponse#setShouldEndSession(boolean)}.
* ended the session using {@link SpeechletResponse#setNullableShouldEndSession(Boolean)}.
*
* @param requestEnvelope
* the end of session request envelope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License.
*/

package com.amazon.speech.speechlet.dialog.directives;

import com.fasterxml.jackson.annotation.JsonTypeName;
Expand Down
Loading

0 comments on commit 4916e9a

Please sign in to comment.