The action
The action file is a pre-processor that gathers information and then calls the plugin's Script file.
Simple action
If the intention is satisfactorily resolved, the action proposed by Plugin Studio
generally covers 90% of needs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Personalized action
Below are the possible default values for state.action
:
Object | Type | Mandatory | Description |
---|---|---|---|
module |
string | no | The name of the plugin to call. If module key is not defined:- tts key must be present.- The script file must exist but will not be executed. |
command |
string | no | The method to be used. The module key must be present. |
tts |
string ou array |
no | A sentence or an array of sentences (one of which will be chosen at random) that A.V.A.T.A.R will speak before calling the script. |
end |
boolean | no | true by defaulttrue : After speaking the tts sentence, listening to the client is restored.false : After speaking the tts sentence, listening to the client is not restored. |
The formatting of an action is not fixed. The choice depends on the complexity of your project.
It is entirely possible to perform pre-processing before calling the script, or even to do everything in the action file, as in the example of a little time
plugin below, in which we make A.V.A.T.A.R answer the question: what time it is
.
import moment from 'moment'
import * as _helpers from '../../ia/node_modules/ava-ia/helpers/index.js'
/**
* basic location of messages
* not a good way, this is just for the example
* prefer language.pak files for the localization of the messages
* @private
*/
const msg = {
'en': {
'sentence': 'it is',
'hour': 'hour'
},
'fr': {
'sentence': 'il est',
'hour': 'heure'
}
}
/**
* @private
* @param {string} lang - short language code
* @return {object} messages
*/
function getValues (lang) {
return { ...msg[lang] }
}
export default function (state) {
return new Promise(async (resolve) => {
moment.locale(Config.language);
const tts = getValues(Config.language);
const hour = moment().format(`[${tts.sentence}] H [${tts.hour}] m`);
setTimeout(() => {
state.action = {
tts: hour, // Sentence to speak
end: true // Restores listening after speaking
}
resolve(state);
}, Config.waitAction.time);
});
};
// Nothing inside but must exist
export function action (data, callback) {
callback();
}
What's important to remember?
- Except in specific cases, the action file created by Plugin Studio is the most widely used.
- Nothing is set in stone. You can modify the action.myFirstPlugin.js file as you wish.