Search code examples
amazon-web-servicesauthenticationalexa-skills-kit

Play media from external sources that need headers in Alexa


I am developing an Alexa skill where I need to play media that I will be getting from my own API.

According to the documentation, I have to send to Alexa the url of media to be played:

{
  "version": "1.0",
  "sessionAttributes": {},
  "response": {
    "outputSpeech": {},
    "card": {},
    "reprompt": {},
    "shouldEndSession": true,
    "directives": [
      {
        "type": "AudioPlayer.Play",
        "playBehavior": "ENQUEUE",
        "audioItem": {
          "stream": {
            "url": "https://cdn.example.com/url-of-the-mp3-to-play/audiofile.mp3",
            "token": "1234AAAABBBBCCCCCDDDDEEEEEFFFF",
            "expectedPreviousToken": "9876ZZZZZZZYYYYYYYYYXXXXXXXXXXX",
            "offsetInMilliseconds": 0
          },
          "metadata": {
            "title": "My opinion: how could you diss-a-brie?",
            "subtitle": "Vince Fontana",
            "art": {
              "sources": [
                {
                  "url": "https://cdn.example.com/url-of-the-skill-image/brie-album-art.png"
                }
              ]
            },
            "backgroundImage": {
              "sources": [
                {
                  "url": "https://cdn.example.com/url-of-the-skill-image/brie-background.png"
                }
              ]
            }
          }
        }
      }
    ]
  }
}

The thing is:

My API needs Authorization header, and Alexa seems to be only getting the source I pass in url, how can I instruct Alexa to insert an Authorization header in the request?


Solution

  • After contacting with AWS Alexa team, They clarified that:

    Audio files to be played using the AudioPlayer must be hosted on an Internet-accessible HTTPS endpoint on port 443 - authorization isn't supported at this time, as per the documentation on audioItem.stream.url below: https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html#play-params

    So in the meantime, we can't use audio files that need authorization.