Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-wit

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-wit - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

LICENSE

39

lib/wit.js

@@ -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();
});
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc