I'm writing a component for Oracle Chatbot, but I can't and don't know to debug my code.
My component imports with success to Oracle Digital Assistant (ODA), but I have a lot of work to test.
My component:
"use strict"
module.exports = {
metadata: () => ({
"name": "DocumentNumber",
"properties": {
"numberDocument": { "type": "string", "required": true }
},
"supportedActions": [
"allow",
"block"
]
}),
invoke: (conversation, done) => {
// Parse a number out of the incoming message
const text = conversation.text();
var document = "";
if (text) {
const textSize = text.length;
if (textSize < 10) {
conversation.invalidUserInput("xxxxxx");
done();
return;
} else {
document = text;
}
} else {
var errText = "xxxx";
conversation.logger().error(errText);
done(new Error(errText));
return;
}
conversation.logger().info('DocumentNumber: using numberDocumento=' + document);
var express = require('express');
var linkReturn = "";
axios.put('http://xxxxx', {
numeroDocumento: document,
filial: 0001
})
.then(function (response) {
linkReturn = response;
console.log(response);
})
.catch(function (error) {
linkReturn = "";
console.log(error);
});
// Set action based on age check
//conversation.invalidUserInput(linkReturn);
if (linkReturn !== ""){
conversation.invalidUserInput(linkReturn);
conversation.transition('allow');
} else {
conversation.invalidUserInput(response.data);
conversation.transition('block');
}
done();
}
};
I would like to know how to debug my component setting a value for properties numberDocument.
Have you looked at this documentation of how to create a custom component?
There is a chapter on how to import it into ODA and how to test it.
If you to your components in the Oracle Cloud you in the top right you can select:
This will show the things you put in your conversation.logger().info() hence you have to replace your console.log()
with conversation.logger().info("Stuff to log.")