Skip to content

APMG/skill-share

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alexa Skill Share

This library is intended to provide some tools to reduce boilerplate and make it easy to compose various intents and state handlers into an Alexa lambda handler.

In theory you should be able to make a basic streaming skill with the following:

// index.js

var skillShare = require('skill-share')

var config = {
  APP_ID: 'your-app-id',
  STREAM_NAME: 'Stream Name',
  STREAM_URL: 'www.yourstream.url/goes/here.mp3',
}

// The first param here is the state name. Passing an empty string
// means the given intents will apply to the default state
var stateHandler = skillShare.stateHandler('', [
  skillShare.intents.defaultBuiltIns,
  skillShare.intents.builtInAudio
])

exports.handler = skillShare
  .skill(config)
  .addHandler(stateHandler)
  .create()

Why Might This Be Important?

It establishes a convention that should make it very easy for different organizations to create and share reusable intents and state handlers. If your project contains a file that exports a skill-share intent, my project can use it.

Creating Custom Intents

An intent here is defined as a function that accepts a config object (you don't have to use it but you're going to get it anyway) and returns an object in which the keys are intent names and the values are callbacks:

// my-custom-intent.js

module.exports = function(config) {
  return {
    'MyCustomIntent': function() {
      this.emit(':tell', 'You are listening to ' + config.STREAM_NAME)
    }
  }
}

This can contain as many intent handlers as you like.

Overriding Intents in a State Handler

Say you want to override a default intent in a particular state handler. If multiple intents are added with the same name, the one added last will be used.

First create the intent ...

// my-help-intent.js

module.exports = function(config) {
  return {
    'AMAZON.HelpIntent': function() {
      // custom implementation
    }
  }
}

Then add it to the state handler

var skillShare = require('skill-share')
var myHelpIntent = require('./my-help-intent.js')

var stateHandler = skillShare.stateHandler('', [
  skillShare.intents.defaultBuiltIns,
  myHelpIntent
])

You could also add it later

var stateHandler = skillShare.stateHandler('', [
  skillShare.intents.defaultBuiltIns
])

stateHandler.addIntents([myHelpIntent])

Using Multiple States

All handlers are passed through Alexa.CreateStateHandler. So to have them apply to a state, just give them a state name.

// index.js

var skillShare = require('skill-share')
var config = {...}

var fooHandler = skillShare.stateHandler('_FOO_STATE', [...])
var barHandler = skillShare.stateHandler('_BAR_STATE', [...])

exports.handler = skillShare
  .skill(config)
  .addHandler(fooHandler)
  .addHandler(barHandler)
  .create()

You can also pass handlers directly to the skill method

exports.handler = skillShare
  .skill(config, [fooHandler, barHandler])
  .create()

About

A base library to make it easier to compose Alexa skill handlers use each other's intents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published