// Process a JSON command. // This processes JSON HTTP POST requests to the /rest/api/command endpoint. state ProcessJSON { case input answer processJSON(); function processJSON() { // The JSON parameter is the input variable of the input object. var json = input.input; // Ignore NLP. if (json.has(#instantiation, #sentence)) { return null; } var result = new Object(); if (json.type == "report") { // Example response that returns the date. result.date = Date.date(); result.status = "ok"; } else if (json.type == "message") { // Example response that echos the input message. result.message = json.message; } else if (json.type == "greet") { // Example response that returns a string. result.message = "hello world"; } else { // Example response that echos the input JSON. result = json; } // The JSON response must be set as a command object, and text returned from the function to tell the NLP system the state processed the input. Avatar.setCommand(result); return "success"; } }