alexa-samples / skill-sample-nodejs-audio-player

An Alexa Skill Sample showing how to play long form audio in 3P-skills
Other
470 stars 319 forks source link

Way to pass Alexa Skil lId to audioAssets.js? #72

Closed nealrs closed 6 years ago

nealrs commented 6 years ago

Hola! I'd like to run multiple unique audio skills using the same lambda.

Is there was a way to pass the application id (skill id) from index.js to audioAssets.js, so that I can choose which audio to use based on the alexa skill calling my function?

sebsto commented 6 years ago

The full JSON request is available from the intent handler, including the skill id

this.event.session.application.applicationId or this.event.system.application.applicationId should do it.

Then at this line you can decide which URL to use depending on the skill ID.

{
  "version": "1.0",
  "session": {
    "new": true,
    "sessionId": "amzn1.echo-api.session.123",
    "application": {
      "applicationId": "amzn1.ask.skill.123"
    },
    "user": {
      "userId": "amzn1.ask.account.123"
    }
  },
  "context": {
    "AudioPlayer": {
      "offsetInMilliseconds": 3160,
      "token": "0",
      "playerActivity": "STOPPED"
    },
    "System": {
      "application": {
        "applicationId": "amzn1.ask.skill.123"
      },
      "user": {
        "userId": "amzn1.ask.account.123"
      },
      "device": {
        "supportedInterfaces": {
          "AudioPlayer": {}
        }
      }
    }
  },
  "request": {
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.123",
    "timestamp": "2017-03-04T19:34:05Z",
    "locale": "en-GB",
    "intent": {
      "name": "PlayAudio"
    }
  }
}