Permalink
Browse files

Added support for custom slot types.

  • Loading branch information...
1 parent 9d838c9 commit feb10bcd04951a872c52887adfbc9333e91764a9 @primaryobjects committed Sep 29, 2016
Showing with 72 additions and 5 deletions.
  1. +25 −0 favoritecolor.js
  2. +8 −0 lib/chatskills.js
  3. +2 −2 package.json
  4. +35 −2 readme.md
  5. +2 −1 test.js
View
@@ -0,0 +1,25 @@
+var chatskills = require('./lib/chatskills');
+
+// Create a new skill.
+var favoritecolor = chatskills.add('favoritecolor');
+
+favoritecolor.intent('run', {
+ "slots": {},
+ "utterances": ["{to|} {run|start|go|launch}"]
+ }, function(req, res) {
+ var prompt = "What is your favorite color?";
+ res.say(prompt).reprompt(prompt).shouldEndSession(false);
+ }
+);
+
+// Using the Custom Slot Type "ColorType".
+favoritecolor.intent('color',{
+ "slots":{"ColorType":"COLORTYPE"}
+ ,"utterances":["my favorite color is {-|ColorType}",
+ "{-|ColorType}"]
+ },
+ function(req,res) {
+ res.say("My favorite color is " + req.slot('ColorType') + ' too!');
+ res.shouldEndSession(true);
+ }
+);
View
@@ -337,6 +337,14 @@ var ChatSkillsManager = {
break;
}
}
+ else if (token && /^(\{.+\})$/.test(token)) {
+ // token is a custom slot type {SomeType}.
+ var name = token.substring(1, token.length - 1);
+ if (slots[name]) {
+ // This is a valid custom slot type.
+ result.pairs.push({ name: name, value: word });
+ }
+ }
else {
result.isValid = false;
break;
View
@@ -1,6 +1,6 @@
{
"name": "chatskills",
- "version": "0.0.11",
+ "version": "0.0.12",
"description": "Run Alexa apps on the command-line. Run them in Slack. Run them anywhere! Supports Amazon Alexa skills and intents.",
"author": {
"name": "Kory Becker",
@@ -47,6 +47,6 @@
"AI",
"artificial intelligence"
],
- "_id": "chatskills@0.0.11",
+ "_id": "chatskills@0.0.12",
"_from": "chatskills"
}
View
@@ -294,11 +294,44 @@ app.intent('sampleIntent',
);
```
-#### slots
+#### Slots
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
-#### utterances
+#### Custom Slot Types
+
+As a replacement for the `LITERAL` slot type, which is no longer being supported by Amazon, it is recommended to use custom slot types in its place. Here is an example of defining a custom slot type for `DragonType`.
+
+```javascript
+app.intent('attack',
+ {
+ 'slots': { 'DragonType': 'DRAGONTYPE' },
+ 'utterances': ['{attack|fight|hit|use} {sword|dagger|wand} on {-|DragonType} dragon']
+ }, function(request,response) {
+ response.say('You are attacking the ' + request.slot('DragonType') + ' dragon!');
+ }
+);
+```
+
+You can include custom slot types within utterances by using the syntax `{-|CustomTypeName}`. This indicates that the term should come from a list of values for the custom slot type. In the example above, the utterance uses the term `{-|DragonType}`, indicating a term should come from the list of values (shown below). For chatskills, a list of values does not need to be provided - any word will be accepted for a custom slot type and used as its value.
+
+If publishing to the Amazon Alexa service, you would provide the custom slot types for `DragonType` by specifying the type name and a list of values. For example:
+
+Type:
+`DRAGONTYPE`
+
+Values:
+```
+golden
+fire
+ice
+water
+snow
+```
+
+Note, chatskills and Amazon Alexa will actually accept any word for the custom slot value. It doesn't have to match a word from the list of values. In this manner, custom slot types are similar to `LITERAL`.
+
+#### 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.
View
@@ -17,8 +17,9 @@ hello.intent('helloWorld', {
// Include some other skills.
require('./funny');
require('./horoscope');
+require('./favoritecolor');
-console.log('Welcome, here are some available commands to try:\nchatskills, ask hello to say hi\nchatskills, ask horoscope for Aries\nchatskills, ask funny to tell a joke\n');
+console.log('Welcome, here are some available commands to try:\nchatskills, ask hello to say hi\nchatskills, ask horoscope for Aries\nchatskills, ask funny to tell a joke\nchatskills, ask favoritecolor to run\n');
// Example client.
var text = ' ';

0 comments on commit feb10bc

Please sign in to comment.