Olá,
Dando sequência sequência no curso, deparei com um problema quando respondo a mensagem de boas-vindas do bot.
Após a mensagem inicial, respondo, e o retorno é o abaixo:
[iMac-Midia-0575:app-conversa thiago.lemos$ node app-conversa.js
WARNING: This method of instantiating the Watson services has been deprecated beginning with Version 3.0.0 of the Node SDK. Please refer to the Node SDK documentation for information on how to instantiate Watson services. This form of service instantiaion will be removed in a future release of the SDK.
Olá. Como posso te ajudar?
>> voces fazem site?
undefined
/Applications/XAMPP/xamppfiles/htdocs/app-conversa/app-conversa.js:43
if(response.output.text != 0){
^
TypeError: Cannot read property 'output' of undefined
at processarResposta (/Applications/XAMPP/xamppfiles/htdocs/app-conversa/app-conversa.js:43:14)
at ConversationV1.message (/Applications/XAMPP/xamppfiles/htdocs/app-conversa/node_modules/watson-developer-cloud/conversation/v1-generated.js:318:20)
at processarResposta (/Applications/XAMPP/xamppfiles/htdocs/app-conversa/app-conversa.js:48:12)
at Request._callback (/Applications/XAMPP/xamppfiles/htdocs/app-conversa/node_modules/watson-developer-cloud/lib/requestwrapper.js:124:9)
at Request.self.callback (/Applications/XAMPP/xamppfiles/htdocs/app-conversa/node_modules/request/request.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/Applications/XAMPP/xamppfiles/htdocs/app-conversa/node_modules/request/request.js:1163:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
Meu código JS completo é:
//faz a requisicao da API
var watson = require('watson-developer-cloud');
var prompt = require('prompt-sync')();
//conecta na API
var assistant = new watson.conversation({
username: 'username',
password: 'password',
version: 'v1',
version_date:'2018-02-16'
});
//mandar uma mensagem vazia para receber a mensgem de boas vindas
assistant.message({
workspace_id: 'workspace_id',
//input: {'text' : 'valor do site'}
}, processarResposta);
function processarResposta (err, response) {
if(err){
console.log('error: ' . err)
}
if(response.output.text != 0){
console.log(response.output.text[0])
}
var novaMensagemUsuario = prompt('>> ');
assistant.message({input:{'text': novaMensagemUsuario}
}, processarResposta);
}
Obrigado! Thiago