He Spoke Bespoke
You’ve now see a couple of different built in slot types and used them in a mini chat bot. There are a lot more of these built in slot types - several dozen or so, with more coming. For the latest list see the bottom of the README.md file of the vui-ad-hoc-alexa-recognizer. However, no system can hope to provide built in slot types for every conceivable use. When you need a special slot type you will turn to custom slot types. Here we will go through the most common way to create one.
Before we proceed, as in the previous tutorials, ensure that you have node and npm installed, create a new directory and initialize npm project there (accepting default values):
Note: if you don’t want to type in all the source code, you don’t have to. This tutorial is available as an npm module. Simply load the module, then copy all the files to your current directory:
If you decide not to install the tutorial module then don’t forget to install vui-ad-hoc-alexa-recognizer:
The simplest type of a custom slot is a list based custom slot. What that means is that you can provide a list of possible values for a slot type and give it a slot type name and, voila - you have a custom slot type. For example, let’s say you want to have a slot type of ice cream flavors. You can create a list of such flavors and give it a slot type name of ICECREAMFLAVOR (or any other acceptable name you like) and you’ll have a custom slot type that you can use in your app, skill, or chat bot.
You will use your config file to specify a custom slot, like this:
Now you could define an intent and use this slot type in it by inserting the following into intents.json:
and don’t forget to update the utterances:
if you haven’t downloaded the tutorial module don’t forget to regenerate recognizer.json:
Now if you run the index.js you can to verify that you are getting your values back:
So, as you can see it’s very easy to define a list based custom slot type. The only annoying part is that the values have to be entered into the config file. Luckily, you can specify the extra values in a separate text file (one value per line) and simply reference that file within the config file. In fact, you can even combine the two methods - specify some values in the config file itself and others in a separate text file. Whatever works for you!
So, let’s add a few more flavors using ice_cream_flavors.txt:
and update the config.json too:
So, let’s verify that this works. First, make sure you have regenerated the recognizer.json file:
Note the “–sourcebase .” arguments. What that means is “use the current directory - ‘.’ - as the source directory to look for other files”. Any files specified on the command line or in the config.json file will be relative to this directory.
Now, if everything went well, you should have a brand new recognizer.json file in your current directory. (If you got an error, make sure you have installed at least v1.0.621 version of vui-ad-hoc-alexa-recognizer as prior versions don’t fully support –sourcebase argument). So, go ahead and test your project:
Now, if you’d like go ahead and update talk.js to respond to this new intent.