...
Code Block |
---|
msg.payload.orbita.directive= [{ "type": "button", "buttons": [ { "text": "Button with Get Request", "value": "https://randomuser.me/api/", "type" : "ajax", "options": { "method": "get", "contentType": "application/json" }, "responseHandler": //optional `if(error) { console.log("error", error); callback({utterance: "error"}); } else if(result) { console.log("result", result); callback({utterance: "help", data : result.results[0]}); }` } ] }]; return msg; |
Sample Button directive with
...
Patch Request code
Code Block |
---|
msg.payload.orbita.directive= [{ "type": "button", "buttons": [ { "text": "Button with PostPatch request", "value": "http://localhost:3030/api/projects", "type" : "ajax", "options": { "method": "patch", //default method : get "payload": {"q":{"condition":{"isDeleted":false},"sort":{"name":1}}}, "contentType": "application/json", //default contentType 'application/json' }, "responseHandler": `if(error) { console.log("error", error); callback({utterance: "open"}); } else if(result) { console.log("result", result); callback({utterance: "open", data: result}); }`, }, ] }]; return msg; |
...
type: The “type” should be set to the script language. Here we have put “js” for JavaScript.
Sample Button code that executes a JavaScript
Code Block |
---|
msg.payload.orbita.directive= [{ "type": "button", "buttons": [ { "type" : "js", "text": "Button with script", "value": ` if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { console.log("Geolocation is not supported by this browser."); callback({utterance: "help"}); } function showPosition(position) { console.log("Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude); callback({utterance: "help", data: [position.coords.latitude, position.coords.longitude]}); } `, } ] }]; return msg; |
...