Skip to content

Commit

Permalink
support custom slot types
Browse files Browse the repository at this point in the history
  • Loading branch information
joshskeen committed May 20, 2016
1 parent 261f8fb commit fff2390
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,29 @@ app.intent('sampleIntent',

The slots object is a simple Name:Type mapping. The type must be one of Amazon's supported slot types: LITERAL, NUMBER, DATE, TIME, DURATION

### custom slot types

[Custom slot types](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference#Custom Slot Type Syntax) are supported via the following syntax:

```javascript
app.intent('sampleIntent',
{
"slots":{"CustomSlotName": "CustomSlotType" },
"utterances":[ "airport {information|status} for {-|CustomSlotName}" ]
},
function(request,response) { ... }
);
```

This will result in an utterance list of the following:

```
sampleIntent airport information for {CustomSlotName}
sampleIntent airport status for {CustomSlotName}
```

Note that the "CustomSlotType" type values must be specified in the Skill Interface's Interaction Model for the custom slot type to function correctly.

### utterances

The utterances syntax allows you to generate many (hundreds or even thousands) of sample utterances using just a few samples that get auto-expanded. Any number of sample utterances may be passed in the utterances array. Below are some sample utterances macros and what they will be expanded to.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ alexa.app = function(name, endpoint) {
self.dictionary,
self.exhaustiveUtterances);
list.forEach(function(utterance) {
out += intent.name + "\t" + (utterance.replace(/\s+/g, " ")) + "\n";
out += intent.name + "\t" + (utterance.replace(/\s+/g, " ")).trim() + "\n";
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"license": "MIT",
"dependencies": {
"alexa-utterances": "^0.1.0",
"alexa-utterances": "^0.2.0",
"bluebird": "^2.10.2",
"numbered": "^1.0.0"
},
Expand Down
54 changes: 54 additions & 0 deletions test/test_alexa_app_utterances_schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*jshint expr: true*/
"use strict";
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var mockHelper = require("./helpers/mock_helper");
chai.use(chaiAsPromised);
var expect = chai.expect;
chai.config.includeStack = true;

describe("Alexa", function() {
var Alexa = require("../index");
describe("app", function() {
describe("#utterances", function() {
var app = new Alexa.app("myapp");
app.intent("testIntentTwo", {
"slots": {
"NAME": "LITERAL",
"AGE": "NUMBER"
},
"utterances": ["my {name is|name's} {names|NAME} and {I am|I'm} {1-2|AGE}{ years old|}"]
});
app.intent("testIntent", {
"slots": {
"AirportCode": "FAACODES",
},
"utterances": ["{|flight|airport} {|delays} {|for} {-|AirportCode}"]
});
it("generates expected list of sample utterances", function() {
var subject = app.utterances();
var expected = "testIntentTwo" + "\t" + "my name is {names|NAME} and I am {one|AGE} years old" + "\n";
expected += "testIntentTwo" + "\t" + "my name's {names|NAME} and I am {two|AGE} years old" + "\n";
expected += "testIntentTwo" + "\t" + "my name is {names|NAME} and I'm {one|AGE} years old" + "\n";
expected += "testIntentTwo" + "\t" + "my name's {names|NAME} and I'm {two|AGE} years old" + "\n";
expected += "testIntentTwo" + "\t" + "my name is {names|NAME} and I am {one|AGE}" + "\n";
expected += "testIntentTwo" + "\t" + "my name's {names|NAME} and I am {two|AGE}" + "\n";
expected += "testIntentTwo" + "\t" + "my name is {names|NAME} and I'm {one|AGE}" + "\n";
expected += "testIntentTwo" + "\t" + "my name's {names|NAME} and I'm {two|AGE}" + "\n";
expected += "testIntent" + "\t" + "{AirportCode}" + "\n";
expected += "testIntent" + "\t" + "flight {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "airport {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "delays {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "flight delays {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "airport delays {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "for {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "flight for {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "airport for {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "delays for {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "flight delays for {AirportCode}" + "\n";
expected += "testIntent" + "\t" + "airport delays for {AirportCode}" + "\n";
expect(subject).to.eq(expected);
});
});
});
});

0 comments on commit fff2390

Please sign in to comment.