Comparing version 1.1.0 to 2.0.0
@@ -19,3 +19,3 @@ /* | ||
var _ = require('underscore'); | ||
var VERSION = "20141119"; | ||
var VERSION = "20150306"; | ||
@@ -33,8 +33,18 @@ var getHeaders = function (access_token, others) { | ||
* @param text the text you want to analyze | ||
* @param [options] json object to be passed to wit. Can include any of 'context', 'verbose', 'n' | ||
* @param callback callback that takes 2 arguments err and the response body | ||
*/ | ||
var captureTextIntent = function (access_token, text, callback) { | ||
var options = { | ||
var captureTextIntent = function (access_token, text, options, callback) { | ||
if(!callback) { | ||
callback = options; | ||
options = undefined; | ||
} | ||
// Set up the query | ||
query_params = _.extend({'q': text}, options); | ||
// Request options | ||
var request_options = { | ||
url: 'https://api.wit.ai/message', | ||
qs: {'q': text}, | ||
qs: query_params, | ||
json: true, | ||
@@ -44,3 +54,4 @@ headers: getHeaders(access_token) | ||
request(options, function (error, response, body) { | ||
// Make the request | ||
request(request_options, function (error, response, body) { | ||
if (response && response.statusCode != 200) { | ||
@@ -58,7 +69,18 @@ error = "Invalid response received from server: " + response.statusCode | ||
* @param content_type The content-type for this audio stream (audio/wav, ...) | ||
* @param [options] json object to be passed to wit. Can include any of 'context', 'verbose', 'n' | ||
* @param callback callback that takes 2 arguments err and the response body | ||
*/ | ||
var captureSpeechIntent = function (access_token, stream, content_type, callback) { | ||
var options = { | ||
var captureSpeechIntent = function (access_token, stream, content_type, options, callback) { | ||
if(!callback) { | ||
callback = options; | ||
options = undefined; | ||
} | ||
// Set up the query (empty b/c not sending 'q') | ||
query_params = _.extend({}, options); | ||
// Request options | ||
var request_options = { | ||
url: 'https://api.wit.ai/speech', | ||
qs: query_params, // may be empty object | ||
method: 'POST', | ||
@@ -69,3 +91,4 @@ json: true, | ||
stream.pipe(request(options, function (error, response, body) { | ||
// Pipe the request | ||
stream.pipe(request(request_options, function (error, response, body) { | ||
if (response && response.statusCode != 200) { | ||
@@ -72,0 +95,0 @@ error = "Invalid response received from server: " + response.statusCode |
{ | ||
"name": "node-wit", | ||
"version": "1.1.0", | ||
"private": false, | ||
"homepage": "https://github.com/wit-ai/node-wit", | ||
"description":"Node module to request Wit.AI", | ||
"repository": "https://github.com/wit-ai/node-wit", | ||
"bugs": { | ||
"url": "https://github.com/wit-ai/node-wit/issues" | ||
"name": "node-wit", | ||
"version": "2.0.0", | ||
"private": false, | ||
"homepage": "https://github.com/wit-ai/node-wit", | ||
"description": "Node module to request Wit.AI", | ||
"repository": "https://github.com/wit-ai/node-wit", | ||
"bugs": { | ||
"url": "https://github.com/wit-ai/node-wit/issues" | ||
}, | ||
"keywords": [ | ||
"wit", | ||
"automation", | ||
"home", | ||
"siri", | ||
"wit.ai", | ||
"nlp", | ||
"speech", | ||
"intent", | ||
"jarvis" | ||
], | ||
"author": { | ||
"name": "Olivier Vaussy", | ||
"email": "oliv@wit.ai" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Anthony Kesich", | ||
"email": "anthony@wit.ai" | ||
}, | ||
"keywords": [ | ||
"wit", | ||
"automation", | ||
"home", | ||
"siri", | ||
"wit.ai", | ||
"nlp", | ||
"speech", | ||
"intent", | ||
"jarvis" | ||
], | ||
"author": { | ||
"name": "Olivier Vaussy", | ||
"email": "oliv@wit.ai" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/mocha/bin/_mocha test/*_test.js --ignore-leaks -t 20000 --reporter spec" | ||
}, | ||
"dependencies": { | ||
"request": "2.42.0", | ||
"underscore": "1.7.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.21.4", | ||
"nock": "0.47.0", | ||
"chai": "1.9.1" | ||
}, | ||
"main": "./index.js" | ||
} | ||
{ | ||
"name": "irfaan", | ||
"email": "github@irfaan.com" | ||
} | ||
], | ||
"scripts": { | ||
"test": "node_modules/mocha/bin/_mocha test/*_test.js --ignore-leaks -t 20000 --reporter spec" | ||
}, | ||
"dependencies": { | ||
"request": "2.42.0", | ||
"underscore": "1.7.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.21.4", | ||
"nock": "0.47.0", | ||
"chai": "1.9.1" | ||
}, | ||
"main": "./index.js" | ||
} |
@@ -18,8 +18,6 @@ ## Quick start | ||
Add node-wit as a dependencies in your package.json | ||
Install and add node-wit as a dependencies in your package.json : | ||
```json | ||
"dependencies": { | ||
"node-wit": "1.1.0" | ||
}, | ||
```bash | ||
npm install --save node-wit | ||
``` | ||
@@ -110,5 +108,6 @@ | ||
The `captureTextIntent` function returns the meaning extracted from the text | ||
input. The function takes 3 parameters: | ||
input. The function takes 4 parameters: | ||
- `access_token`: Your access token for your instance | ||
- `text`: The text input you want to extract the meaning of | ||
- `options`: [optional] A json object containing any call options such as `verbose` or `context` | ||
- `callback(error, response)`: A callback function get 2 arguments: | ||
@@ -130,3 +129,3 @@ 1. An `error` when applicable | ||
The `captureSpeechIntent` function returns the meaning extracted from the audio | ||
input. The function takes 4 arguments: | ||
input. The function takes 5 arguments: | ||
- `access_token`: Your access token for your instance | ||
@@ -136,2 +135,3 @@ - `stream`: The audio stream you want to extract the meaning of | ||
`audio/raw;encoding=unsigned-integer;bits=16;rate=8000;endian=big`, ...) | ||
- `options`: [optional] A json object containing any call options such as `verbose` or `context` | ||
- `callback(error, response)`: A callback function get 2 arguments: | ||
@@ -150,2 +150,2 @@ 1. An `error` when applicable | ||
}); | ||
``` | ||
``` |
@@ -31,3 +31,3 @@ /* | ||
'Authorization': 'Bearer 1234', | ||
'Accept': 'application/vnd.wit.20141119' | ||
'Accept': 'application/vnd.wit.20150306' | ||
} | ||
@@ -54,2 +54,17 @@ }).get('/message?q=set%20alarm%20tomorrow%20at%205pm') | ||
}); | ||
it('should send options as given in parameter', function (done) { | ||
var scope = nock('https://api.wit.ai/', { | ||
reqheaders: { | ||
'Authorization': 'Bearer 1234', | ||
'Accept': 'application/vnd.wit.20150306' | ||
} | ||
}).get('/message?q=set%20alarm%20tomorrow%20at%205pm&verbose=true&context%5Btest%5D=1') | ||
.reply(200, wit_response); | ||
wit.captureTextIntent("1234", "set alarm tomorrow at 5pm", {"verbose": true, "context": {"test" : "1"}}, function (err, res) { | ||
assert.isNull(err, "error should be undefined"); | ||
assert.deepEqual(res, wit_response); | ||
scope.done(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -63,3 +78,3 @@ | ||
'Authorization': 'Bearer 1234', | ||
'Accept': 'application/vnd.wit.20141119', | ||
'Accept': 'application/vnd.wit.20150306', | ||
'Content-Type': "audio/wav" | ||
@@ -87,4 +102,20 @@ } | ||
}) | ||
}) | ||
}); | ||
it('should send options as given in parameter', function (done) { | ||
var stream = fs.createReadStream(path.join(resourceDir, 'sample.wav')); | ||
var scope = nock('https://api.wit.ai/', { | ||
reqheaders: { | ||
'Authorization': 'Bearer 1234', | ||
'Accept': 'application/vnd.wit.20150306' | ||
} | ||
}).post('/speech?verbose=true&context%5Btest%5D=1') | ||
.reply(200, wit_response); | ||
wit.captureSpeechIntent("1234", stream, "audio/wav", {"verbose": true, "context": {"test" : "1"}}, function (err, res) { | ||
assert.isNull(err, "error should be undefined"); | ||
assert.deepEqual(res, wit_response); | ||
scope.done(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108273
235
147
3
80
1