I am making a food expiry date chatbot using watson conversation service. So the main function would be alert when the specific food due date is near, which means I have to save both food and the expected days the food would last. (Milk - 14 days, or egg- 7 days, for instance)
And this is the code someone answered for me with the previous questions I asked.
function updateMessage(input, data, req, res) {
if (data.context.verifiedDate){
searchRequest(data, req, res);
} else if (data.output && data.output.text) {
return res.json(data);
}
return data;
}
function searchRequest(data, req, res){
// something to do and return value
var sendRequest = "Thanks for wait, the request is" + valueRequest;
data.output.text[0] = sendRequest;
return data;
}
*Date.prototype.addDays = function(days) {
var dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
}
var dat = new Date();
alert(dat.addDays(7))*
Like I've said I have to deal with foods individually. But according to this code I think it only allows one food to alert. 1. How do you write codes to alert food individually? 2. And does "addDay" coding works with the code above ('updateMessage'). Because reading between the lines it doesn't seem to have connections (like having same variables/functions or so) to implement it.
*Note that I started from scratch, so I might have some trouble understanding terms or functions in JS.
I think you can combine the days with the product...
You will need to create one context variable and save the name of your product... Or create one entity with all products and save within one context variable, like:
"context": {
"product": "<? @product ?>"
},
Like:
function searchRequest(data, req, res){
if(data.context.verifiedDate && data.context.product === 'milk'){
var sendRequest = "Thanks for wait, , the validate for the product is 14 days, product: " + data.context.product;
return data;
} else if(data.context.verifiedDate && data.context.product === 'egg'){
var sendRequest = "Thanks for wait, the validate for the product is 7 days, product::" + data.context.product;
data.output.text[0] = sendRequest;
return data;
}
}