Интеграция IBM Watson Assistant с Watson Tone Analyzer
Я пытаюсь интегрировать помощника Watson с анализатором тонов Watson для анализа пользовательского ввода, но мне кажется, что я что-то упустил, потому что я продолжаю получать сообщение об ошибке в консоли "toneAnalyzer.tone в моем контроллере" не определено. Я разрабатываю веб-приложение, используя angularjs
Ошибка:
ReferenceError: toneAnalyzer is not defined
at Object.toneanalyzer (conversation.service.js:54)
at Conversation.sendMessage.then.data (chat.controller.js:43)
at angular.js:17000
at m.$digest (angular.js:18182)
at m.$apply (angular.js:18480)
at l (angular.js:12501)
at XMLHttpRequest.s.onload (angular.js:12655) "Possibly unhandled
rejection: {}"
вот мой app.js
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
var toneAnalyzer = new ToneAnalyzerV3({
version_date: '2016-05-19',
version: '2017-09-21'
});
вот service.js
function tone_analyzer(contents) {
toneAnalyzer.tone({
text: contents
},
function(err, tone) {
if (err)
console.log(err);
else
var tone = JSON.stringify(tone, null, 2);
//this is the JSON response (tone analysis) that you
can view in terminal
console.log(JSON.stringify(tone, null, 2));
});
return tone;
}
вот мой controller.js
Conversation.sendMessage(message.content).then(data => {
if (data) {
var reply = {};
reply["recipient"] = "watson";
if (data.intents[0].intent == 'emotion') {
reply["content"] = Conversation.toneanalyzer(message.content)
} else {
reply["content"] = data.output.text[0];
}
vm.messages.push(reply);
}
});
Я думаю, что я должен использовать эту функцию в моем rout.js, но я немного запутался, должен я или нет
app.post('/api/tone', function(req, res, next) {
toneAnalyzer.tone(req.body, function(err, data) {
if (err) {
return next(err);
}
return res.json(data);
});
})