-
-
Notifications
You must be signed in to change notification settings - Fork 76
Adding Skills
Add a skill by creating a new folder with the name of your new skill and adding an index.js
.
There are two types of skill, hard rule skills and intent skills. Hard rule skills use manually parse the query to see if it matches its criteria, whereas intent skills provide examples and the natural language classifier does a best guess.
There are several optional functions a new skill can export, many are expected to be generators. (function * name()). Except hard_rule which is expected to be quick to return. Exported functions are expected to be part of module.exports.
Intents are used by the classifier and are necessary if you want your skill to be parsed by the classifier rather than using hard rules. 'qqqq' is a substitution that should be used where there's an unknown word or number of words. Keyword phrases should be similar as possible. This function is not a generator. Example:
function intent() { keywords:['what time is it', 'what is the time qqqq'] }
These are used mainly if your skill implements something vague and difficult to classify, such as the play command where the information on what to play may be longer than the command. 'query' will be supplied in all lower case without an punctuation. If your code can be certain it is your skill specified in the query than return true. Example:
function hard_rule(query, breakdown) { return query.startsWith('play a song') }
This function is called if the classifier chooses your module based on the query, or if the hard_rule function returns true. 'query' is all lower case and without punctuation. 'user' is the user that executed the query, it can be passed to database functions to get user specific settings.
The return value should be a class containing the following:
- (Required) text: This should be a textual response to the query.
- (Optional) url: If this is set clients will attempt to open this URL automatically.
- (Optional) silent: If this is set and true than the text will not be spoken.
If your get function throws an error then the core will respond that it cannot understand the query.
Example:
function * get(query, breakdown, user) { return {text: 'Hello world!'} }
This optional but recommended function contains an array of strings. These examples will be used to verify that classification is working correctly. In a hard_rule based skill it's expected these will all work, if they do not then the server will shutdown. In an intent based skill, if some do not work they will be re-used as additional classification data until they do work. Example:
function examples() { return ["What's the weather today?", "What's the weather tomorrow?"] }
This is called whenever a new socket connection is established. It accepts the parameters 'socket' and 'user'. 'socket' is a socket.io connection. 'user' is an object containing the username and user_id that can be passed to the database module for retrieving settings. This function may be used for greeting the user on connection.
When emitting from a socket and pushing a response to a user the type is expected to be 'response' and the class must be in the format below, where anything inside 'msg' can be the same as the return value from get.
function * registerClient(socket, user) { socket.emit('response', {type: 'greeting', msg: {text: 'Hello user!'}}) }
A basic example of an intent based skill can be found under skills/hello.