I'm trying to integrate my lambda function with IBM Tone_chat sentiment analyzer. I'm getting an error of:
"errorMessage": "The first argument must be one of type string or Buffer. Received type undefined"
here is my event:
{ "utterances": [
{"text": "Hello, can you help me", "user": "customer"},
{"text": "How are you ?", "user": "agent"},
{"text": "Nothing is working", "user": "customer"},
{"text": "Sorry to hear this", "user": "agent"}
]}
If I change the event to:
{"text":"hello, this is test test, Happy sad"}
I get an error of: "{\"code\":400,\"sub_code\":\"C00012\",\"error\":\"Invalid JSON input at line 1, column 2\"}"
Here is my code:
const AWS = require('aws-sdk');
var http = require('https');
exports.handler = (event, context, callback) => {
var text = event.text;
var options = {
method: process.env.method,
hostname: process.env.watson_hostname,
port: null,
path: process.env.path,
headers: {
'content-type': process.env.content_type,
authorization: process.env.authorization,
'cache-control': process.env.cache_control,
'X-Watson-Learning-Opt-Out': 'true'
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var sentimentResponse = JSON.parse(Buffer.concat(chunks));
console.log("Sent respose");
callback(null, JSON.stringify(sentimentResponse));
});
})
req.write(text);
req.end()
}
Can anyone please help me, I'm new to this, and I'm stuck on this for a while now!
Thank you