Socket
Socket
Sign inDemoInstall

@warren-bank/alexa-skill-library-audio-player-http-request-headers

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @warren-bank/alexa-skill-library-audio-player-http-request-headers

Add API methods missing from Alexa ResponseBuilder to configure HTTP headers to include in requests for audio stream URLs


Version published
Weekly downloads
5
decreased by-44.44%
Maintainers
1
Install size
25.8 kB
Created
Weekly downloads
 

Readme

Source

Alexa skill library: audio-player-http-request-headers

Add API methods missing from Alexa ResponseBuilder to configure HTTP headers to include in requests for audio stream URLs

Install:
npm install --save "@warren-bank/alexa-skill-library-audio-player-http-request-headers"
Usage:
const {AddAudioPlayerHttpHeadersRequestInterceptor, SetDefaultAudioPlayerHttpHeadersRequestInterceptor} = require('@warren-bank/alexa-skill-library-audio-player-http-request-headers')

const PlayAudioIntentHandler = {
  canHandle(handlerInput) {
    return (
      (Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest') &&
      (
        (Alexa.getIntentName(handlerInput.requestEnvelope) === 'PlayAudioIntent') ||
        (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.ResumeIntent')
      )
    );
  },
  handle(handlerInput) {
    const speakOutput    = 'Playing the audio stream.';
    const playBehavior   = 'REPLACE_ALL';

    // https://requestbin.com/
    // https://requestbin.com/r
    // https://requestbin.com/r/en0m33feca4osq
    const audioStreamUrl = 'https://en0m33feca4osq.x.pipedream.net/audio_track.mp3';

    return handlerInput.responseBuilder
      .speak(speakOutput)
      .addAudioPlayerPlayDirective(
        playBehavior,
        audioStreamUrl,
        'mytoken',
        0
      )
  //  .removeAudioPlayerHttpHeaders()
      .addAudioPlayerHttpHeaders([{
        "name":  "X-Alexa-Issue",
        "value": "https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/610#issuecomment-1483729767"
      }])
      .getResponse();
  }
};

exports.handler = Alexa.SkillBuilders.custom()
  .addRequestHandlers(
    PlayAudioIntentHandler
  )
  .addRequestInterceptors(
    AddAudioPlayerHttpHeadersRequestInterceptor,
    SetDefaultAudioPlayerHttpHeadersRequestInterceptor([{
      "name":  "X-Alexa-Skill-Demo",
      "value": "https://github.com/warren-bank/Alexa-skill-demos/tree/alexa-samples/skill-sample-nodejs-audio-player/e93ec39"
    },{
      "name":  "X-Alexa-Skill-Library",
      "value": "https://github.com/warren-bank/Alexa-skill-libraries/tree/master/audio-player-http-request-headers"
    }])
  )
  .lambda();
Demo:

The code for the previous usage example is taken from this minimal but complete skill demo.

Issue this library solves:
  • this issue for the the official javascript library has been open for over 3 years
  • AudioPlayer v1.5 added support for user-defined HTTP request headers
    • however, the javascript API hasn't been updated to expose this functionality
  • a quick test of my proposed workaround proved it effective
    • the purpose for this library is to package this methodology into ResponseBuilder, so its usage is easy and follows the familiar pattern
API:
  • ResponseBuilder.addAudioPlayerHttpHeaders(headers_collections, only_update_last_directive)

    • headers_collections can be:
      • an Object
        • having one or more of the following keys: ['key', 'manifest', 'audioSegment', 'all']
        • having an Array of {name, value} Objects for each key
      • an Array
        • of {name, value} Objects
        • which will be assigned to the key: 'all'
    • only_update_last_directive is:
      • a boolean
      • a truthy value indicates:
        • the provided headers should only be applied to the directive added by the most recent call to: ResponseBuilder.addAudioPlayerPlayDirective(...)
      • a non-truthy value indicates:
        • the provided headers should be applied to all directives added by previous calls to: ResponseBuilder.addAudioPlayerPlayDirective(...)
  • ResponseBuilder.removeAudioPlayerHttpHeaders(header_names, only_update_last_directive)

    • header_names can be:
      • a headers_collections Object
        • having one or more of the following keys: ['key', 'manifest', 'audioSegment', 'all']
        • having any of the following non- headers_collections Object types for each key
        • that is applied to only the specified header collection(s)
      • a non- headers_collections Object type:
        • that matches one or more particular headers by name to selectively remove
          • String
          • Array
          • Object
            • having the key: 'name'
          • Array
            • each array item having the key: 'name'
          • that is not selective and will result in removal of all previously added headers
            • any other value, for example: null
          • that is applied to all of the header collections: ['key', 'manifest', 'audioSegment', 'all']
          • only_update_last_directive is:
            • a boolean
            • a truthy value indicates:
              • the provided header names should only be removed from the directive added by the most recent call to: ResponseBuilder.addAudioPlayerPlayDirective(...)
            • a non-truthy value indicates:
              • the provided header names should be removed from all directives added by previous calls to: ResponseBuilder.addAudioPlayerPlayDirective(...)
          • Details:
            • AddAudioPlayerHttpHeadersRequestInterceptor can be used without SetDefaultAudioPlayerHttpHeadersRequestInterceptor
            • AddAudioPlayerHttpHeadersRequestInterceptor is required to use SetDefaultAudioPlayerHttpHeadersRequestInterceptor
              • and its request interceptor needs to be added first
            • SetDefaultAudioPlayerHttpHeadersRequestInterceptor is applied to each directive immediately after its being added by a call to: ResponseBuilder.addAudioPlayerPlayDirective(...)
              • ResponseBuilder.removeAudioPlayerHttpHeaders(null, true) can be called immediately after ResponseBuilder.addAudioPlayerPlayDirective(...) to selectively prevent default headers from being included in a particular directive

FAQs

Last updated on 26 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc