alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

feat(ask-sdk-core/util) Add new helper function to get user id #546

Closed hideokamoto closed 5 years ago

hideokamoto commented 5 years ago

We can get user id from the SDK.

Description

Add the getUserId function into the utils. We can get the user id more easier.

Motivation and Context

Now we can get the requested user's device id by the SDK. But we want to get the user id too.

Before

const userId = handlerInput.requestEnvelope.context.System.user.userId 

Our code will be too long line :(

After

const userId = getUserId(handlerInput.requestEnvelope)

It is the simplest way to get the user ID :)

Testing

To run unit test by gulp.

$ lerna bootstrap
$ lerna --scope ask-sdk-core run gulp -- test
  110 passing (76ms)

=============================== Coverage summary ===============================
Statements   : 100% ( 351/351 )
Branches     : 100% ( 88/88 )
Functions    : 96.26% ( 103/107 )
Lines        : 100% ( 330/330 )
================================================================================

[09:57:52] Finished 'test' after 1.76 s
lerna success run Ran npm script 'gulp' in 1 package in 2.9s:
lerna success - ask-sdk-core

Screenshots (if appropriate)

Types of changes

Checklist

License

kun432 commented 5 years ago

:+1:

ShenChen93 commented 5 years ago

Hi @hideokamoto

The code looks good. Before I merge it in, could you please modify the commit name to "feat: add getUserId util function", In order to fit conventional commits structure.

Thanks, Shen

hideokamoto commented 5 years ago

I've rebased my commits.

ShenChen93 commented 5 years ago

Hi, @hideokamoto

Thanks for the PR! Merging this in. It will be included in the next SDK release.

Regards, Shen