Skip to content

Commit

Permalink
fix: update getDeviceId to check for optional device field (#535)
Browse files Browse the repository at this point in the history
This commit includes the following changes:
- update getDeviceId method to check for optional device field
- update ask-sdk-model package version in some packages' dev dependencies
- update doc to include a ASK-SDK-Utilities page (fixes #532)
  • Loading branch information
tianrenz committed Apr 3, 2019
1 parent aae6e5b commit 884a904
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ask-sdk-core/lib/util/RequestEnvelopeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions ask-sdk-core/tst/util/RequestEnvelopeUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down Expand Up @@ -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');
});
Expand Down
2 changes: 1 addition & 1 deletion ask-sdk-dynamodb-persistence-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ask-sdk-s3-persistence-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 54 additions & 0 deletions docs/en/ASK-SDK-Utilities.rst
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Managing-Attributes
Calling-Alexa-Service-APIs
Configuring-Skill-Instance
ASK-SDK-Utilities

.. toctree::
:caption: TYPEDOC REFERENCE
Expand Down Expand Up @@ -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?
=============
Expand All @@ -149,3 +155,4 @@ Request and vote for Alexa features `here <https://alexa.uservoice.com/forums/90
.. _Managing Attributes: Managing-Attributes.html
.. _Calling Alexa Service APIs: Calling-Alexa-Service-APIs.html
.. _Configuring Skill Instance: Configuring-Skill-Instance.html
.. _ASK SDK Utilities: ASK-SDK-Utilities.html

0 comments on commit 884a904

Please sign in to comment.