diff --git a/ask-sdk-core/lib/util/RequestEnvelopeUtils.ts b/ask-sdk-core/lib/util/RequestEnvelopeUtils.ts index a97f2f84..5ba2e720 100644 --- a/ask-sdk-core/lib/util/RequestEnvelopeUtils.ts +++ b/ask-sdk-core/lib/util/RequestEnvelopeUtils.ts @@ -108,7 +108,7 @@ export function getApiAccessToken(requestEnvelope : RequestEnvelope) : string { * @return {string} */ export function getDeviceId(requestEnvelope : RequestEnvelope) : string { - return requestEnvelope.context.System.device.deviceId; + return requestEnvelope.context.System.device ? requestEnvelope.context.System.device.deviceId : null; } /** diff --git a/ask-sdk-core/tst/util/RequestEnvelopeUtil.spec.ts b/ask-sdk-core/tst/util/RequestEnvelopeUtil.spec.ts index 62bb6b20..6021dcf6 100644 --- a/ask-sdk-core/tst/util/RequestEnvelopeUtil.spec.ts +++ b/ask-sdk-core/tst/util/RequestEnvelopeUtil.spec.ts @@ -64,6 +64,9 @@ describe('RequestEnvelopeUtils', () => { const outOfSessionRequest : RequestEnvelope = JsonProvider.requestEnvelope(); delete outOfSessionRequest.session; + const requestEnvelopeWithNoDevice : RequestEnvelope = JsonProvider.requestEnvelope(); + delete requestEnvelopeWithNoDevice.context.System.device; + it('should be able to get locale', () => { expect(getLocale(requestEnvelope)).eq('en-US'); }); @@ -94,6 +97,10 @@ describe('RequestEnvelopeUtils', () => { expect(getDeviceId(requestEnvelope)).eq('mockDeviceId'); }); + it('should return null if there is no device info', () => { + expect(getDeviceId(requestEnvelopeWithNoDevice)).eq(null); + }); + it('should be able to get dialog state', () => { expect(getDialogState(intentRequestEnvelope)).eq('STARTED'); }); diff --git a/ask-sdk-dynamodb-persistence-adapter/package.json b/ask-sdk-dynamodb-persistence-adapter/package.json index 16aff15b..f25fbe5a 100644 --- a/ask-sdk-dynamodb-persistence-adapter/package.json +++ b/ask-sdk-dynamodb-persistence-adapter/package.json @@ -34,7 +34,7 @@ "@types/mocha": "^5.0.0", "@types/node": "^9.6.1", "ask-sdk-core": "^2.5.1", - "ask-sdk-model": "^1.0.0", + "ask-sdk-model": "^1.9.0", "aws-sdk-mock": "^4.1.0", "chai": "^4.1.2", "del": "^3.0.0", diff --git a/ask-sdk-s3-persistence-adapter/package.json b/ask-sdk-s3-persistence-adapter/package.json index 9cd1be6f..9d3ed0d6 100644 --- a/ask-sdk-s3-persistence-adapter/package.json +++ b/ask-sdk-s3-persistence-adapter/package.json @@ -30,7 +30,7 @@ "@types/mocha": "^5.0.0", "@types/node": "^9.6.1", "ask-sdk-core": "^2.5.1", - "ask-sdk-model": "^1.0.0", + "ask-sdk-model": "^1.9.0", "aws-sdk-mock": "^4.1.0", "chai": "^4.1.2", "del": "^3.0.0", diff --git a/docs/en/ASK-SDK-Utilities.rst b/docs/en/ASK-SDK-Utilities.rst new file mode 100644 index 00000000..46fc4dc9 --- /dev/null +++ b/docs/en/ASK-SDK-Utilities.rst @@ -0,0 +1,54 @@ +***************** +ASK SDK Utilities +***************** + +The SDK provides mutiple utility functions that aims to reduce boilerplate code so that you can focus on skill business logic. + +RequestEnvelopeUtils +==================== + +The ``RequestEnvelopeUtils`` provides functions for getting frequently used attributes from the ``RequestEnvelope`` with error checking logic. + +Available Methods +----------------- + +.. code-block:: typescript + + getLocale(requestEnvelope: RequestEnvelope): string; + getRequestType(requestEnvelope: RequestEnvelope): string; + getIntentName(requestEnvelope: RequestEnvelope): string; + getAccountLinkingAccessToken(requestEnvelope: RequestEnvelope): string; + getApiAccessToken(requestEnvelope: RequestEnvelope): string; + getDeviceId(requestEnvelope: RequestEnvelope): string; + getDialogState(requestEnvelope: RequestEnvelope): string; + getSlot(requestEnvelope: RequestEnvelope, slotName: string): Slot; + getSlotValue(requestEnvelope: RequestEnvelope, slotName: string): string; + getSupportedInterfaces(requestEnvelope: RequestEnvelope): SupportedInterfaces; + isNewSession(requestEnvelope: RequestEnvelope): boolean; + +SsmlUtils +========= + +The ``SsmlUtils`` provides a function for escaping invalid SSML characters in a speech string. + +Available Methods +----------------- + +.. code-block:: typescript + + escapeXmlCharacters(input: string): string + +ViewportUtils +============= + +The ``ViewportUtils`` provides functions for checking the viewport profile and other device characteristics such as display size or dpi in the ``RequestEnvelope``. + +Available Methods +----------------- + +.. code-block:: typescript + + getViewportOrientation(width: number, height: number): ViewportOrientation; + getViewportSizeGroup(size: number): ViewportSizeGroup; + getViewportDpiGroup(dpi: number): ViewportDpiGroup; + getViewportProfile(requestEnvelope: RequestEnvelope): ViewportProfile; \ No newline at end of file diff --git a/docs/en/index.rst b/docs/en/index.rst index 68c11f26..ec8e35a7 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -15,6 +15,7 @@ Managing-Attributes Calling-Alexa-Service-APIs Configuring-Skill-Instance + ASK-SDK-Utilities .. toctree:: :caption: TYPEDOC REFERENCE @@ -135,6 +136,11 @@ Covers how to use service clients in your skill to access Alexa APIs. Covers how to configure and construct a skill instance. +`ASK SDK Utilities`_ +-------------------- + +Covers how to use utility function provided by ASK SDK + Got Feedback? ============= @@ -149,3 +155,4 @@ Request and vote for Alexa features `here