npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

v2.0.0

Published

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

Downloads

6

Readme

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

Legal: