artyom.newPrompt({
question:"We have no cheese, you want it without cheese anyway ?",
options:["Yes","No","Buy some cheese"],
beforePrompt: () => {
console.log("Before ask");
},
onStartPrompt: () => {
console.log("The prompt is being executed");
},
onEndPrompt: () => {
console.log("The prompt has been executed succesfully");
},
onMatch: (i) => { // i returns the index of the given options
var action;
if(i == 0){
action = () => {
artyom.say("Your sandwich will be ready in a minute");
}
}
if(i == 1){
action = () => {
artyom.say("You may consider to order some cheese later");
}
}
if(i == 2){
action = () => {
artyom.say("I'll order some cheese via eBay");
}
}
// A function needs to be returned in onMatch event
// in order to accomplish what you want to execute
return action;
}
});
Smart 例子
提示同样支持 smart 命令:
artyom.newPrompt({
question:"How many centimeters should I cut?",
//We set the smart property to true to accept wildcards
smart:true,
options:["Cut * centimeters","Remove * centimeters"],
beforePrompt: () => {
console.log("Before ask");
},
onStartPrompt: () => {
console.log("The prompt is being executed");
},
onEndPrompt: () => {
console.log("The prompt has been executed succesfully");
},
onMatch: (i,wildcard) => {// i returns the index of the given options
var action;
var totalCentimeters = parseInt(wildcard);
action = () => {
alert(wildcard + " centimeters will be removed of your sandwich!");
};
// A function needs to be returned in onMatch event
// in order to accomplish what you want to execute
return action;
}
});