alexa-skills-updated

0.3.0 • Public • Published

Alexa-skills-updated

Alexa Skills for Node

Alexa Skills for Node simplifies the process of creating new skills for Alexa, this pacakge is frok alexa-skills with updated x509 pacakge to make it working with node 10.x and 12.x.

Install

npm install alexa-skills-updated

This module relies on the node-x509 module for verifying that the request is coming from Amazon. If you are developing on a Windows machine, you will need to install OpenSSL to the default location, "C:\OpenSSL-Win32" or "C:\OpenSSL-Win64", before installing alexa-skills. OpenSSL is required for node-x509 to compile.

Supported Card Types

Simple Card

buildSimpleCard(title, content)

Standard Card

buildStandardCard(title, text, smallImageUrl,largeImageUrl)

Account Link Card

buildLinkAccountCard(text)

Supported Output Types

PlainText

var phrase = "Hello World!";
var options = {
  shouldEndSession: true,
  outputSpeech: phrase,
  card: alexa.buildCard("Card Title", phrase)
};

SSML

var phrase = '<speak><say-as interpret-as="spell-out">hello</say-as></speak>';
var options = {
  shouldEndSession: true,
  outputSSML: phrase
};

Session Manipulation

You can access session attributes from the 4th paramter passed to your intent function, sessionAttributes. Remember to pass it back as the 3rd paramter to alexa.send(...).

Example

Assumes you have an intent called SessionIntent with a slot called city.

alexa.intent("SessionTest", function(req, res, slots, sessionAttributes) {
  var phrase = "";
  if (sessionAttributes.previous) {
    phrase =
      'You previously said "' +
      sessionAttributes.previous +
      '". I have replaced that with "' +
      slots.city.value +
      '". Please say another city name.';
  } else {
    phrase =
      'You said "' + slots.city.value + '". Please say another city name.';
  }

  sessionAttributes.previous = slots.city.value;

  var options = {
    shouldEndSession: false,
    outputSpeech: phrase
  };

  alexa.send(req, res, options, sessionAttributes);
});

Example

var express = require("express"),
  AlexaSkills = require("alexa-skills"),
  app = express(),
  port = process.env.PORT || 8080,
  alexa = new AlexaSkills({
    express: app, // required
    route: "/", // optional, defaults to "/"
    applicationId: "your_alexa_app_id" // optional, but recommended. If you do not set this leave it blank
  });

alexa.launch(function(req, res) {
  var phrase = "Welcome to my app!";
  var options = {
    shouldEndSession: false,
    outputSpeech: phrase,
    reprompt: "What was that?"
  };

  alexa.send(req, res, options);
});

alexa.intent("Hello", function(req, res, slots) {
  console.log(slots);

  var phrase = "Hello World!";
  var options = {
    shouldEndSession: true,
    outputSpeech: phrase,
    card: alexa.buildCard("Card Title", phrase)
  };

  alexa.send(req, res, options);
});

alexa.intent("Spell hello", function(req, res, slots) {
  console.log(slots);

  var phrase =
    '<speak><say-as interpret-as="spell-out">hello</say-as></speak>!';
  var options = {
    shouldEndSession: true,
    outputSSML: phrase
  };

  alexa.send(req, res, options);
});

alexa.ended(function(req, res, reason) {
  console.log(reason);
});

app.listen(port);

Package Sidebar

Install

npm i alexa-skills-updated

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

11.5 kB

Total Files

6

Last publish

Collaborators

  • adiii717