Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var err = new Error('Wit.ai is not setup.'+
'Could not find access token.');
donna.logger.warn(err);
return cb(err);
}
// Get textual form of input
var data = input.getData();
// Data Types are unique and each have their own
// specific object format.
// In this case, a 'text' data type is a simple
// object with the field 'text'.
var text = data.text; // Extract text format from data
wit.captureTextIntent(accessToken, text, function (err, res) {
// console.log("Response from Wit for text input: ", res);
if (err) {
cb(err)
} else {
var outcomes = res.outcomes;
// Iterate thru all intents in response
var intents = [];
for (var i = 0, len=outcomes.length; i
function listen(phrase) {
light(LED1, 1);
console.log('Sending phrase: "'+ phrase +'" to Wit.AI');
wit.captureTextIntent(ACCESS_TOKEN, phrase, function (err, res) {
//console.log("Response from Wit for text input: ");
if (err) {
console.log("Wit.AI error: ", err);
} else {
console.log(JSON.stringify(res, null, " "));
processWit(res);
}
});
light(LED1, 1);
}
router.post('/api/v1/intent', function(req, res) {
var query = req.body.query;
wit.captureTextIntent(ACCESS_TOKEN, query, function (err, response) {
console.log('Response from Wit:');
if (err) {
console.log('Error: ', err);
return;
}
if (response['outcomes'].length == 0) {
console.log('Invalid Wit.ai response');
return;
}
var result = response['outcomes'][0];
res.send(result);
});
});
var wit = require('node-wit');
var fs = require('fs');
var ACCESS_TOKEN = "IQ77NWUPUMNBYEUEKRTWU3VDR5YSLHTA";
console.log("Sending text & audio to Wit.AI");
wit.captureTextIntent(ACCESS_TOKEN, "Hello world", function (err, res) {
console.log("Response from Wit for text input: ");
if (err) console.log("Error: ", err);
console.log(JSON.stringify(res, null, " "));
});
var stream = fs.createReadStream('sample.wav');
wit.captureSpeechIntent(ACCESS_TOKEN, stream, "audio/wav", function (err, res) {
console.log("Response from Wit for audio stream: ");
if (err) console.log("Error: ", err);
console.log(JSON.stringify(res, null, " "));
});
middleware.receive = function(bot, message, next) {
if (message.text) {
wit.captureTextIntent(config.token, message.text, function(err, res) {
if (err) {
next(err);
} else {
console.log(JSON.stringify(res));
message.intents = res.outcomes;
next();
}
});
}
else if (message.attachments) {
message.intents = [];
next();
}
};