forked from dialogflow/dialogflow-nodejs-client
-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_example.js
46 lines (36 loc) · 1.27 KB
/
server_example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*!
* apiai
* Copyright(c) 2015 http://api.ai/
* Apache 2.0 Licensed
*/
var http = require('http');
// var apiai = require("../module/apiai");
var apiai = require("apiai")
var app = apiai("YOUR_ACCESS_TOKEN");
var server = http.createServer(function(request, response) {
if (request.method = 'POST' && request.url == '/upload') {
// var outStream = fs.createWriteStream('qwe.wav');
var voiceRequest = app.voiceRequest();
voiceRequest.on('response', function(_response) {
response.end(JSON.stringify(_response));
// var json = JSON.stringify({'resolvedQuery': _response['result']['resolvedQuery']})
// response.end(json);
});
voiceRequest.on('error', function(error) {
console.log(error);
response.end();
});
request.on('data', function(chunk) {
voiceRequest.write(chunk);
});
request.on('end', function() {
voiceRequest.end();
});
} else {
response.writeHead(code, {});
response.end();
}
console.log(request.headers);
});
server.listen(8000);
// cat ann_smith.wav | curl -v -X POST --data-binary @- -H "Transfer-Encoding: chunked" -H "Content-Type: audio/wav" http://localhost:8000/upload