chatbase-node
chatbase-node copied to clipboard
setMessage is not a function
I have the following code:
var chatbase = require('@google/chatbase')
.setApiKey(CHATBASE_KEY)
.setPlatform('Actions');
module.exports = {
userMessage: function (conv) {
let userID = conv._userid;
let conversationID = conv.id;
let message = conv.query;
console.log("USER MESSAGE: "+message);
return chatbase
.setAsTypeUser()
.setUserId(userID)
.setCustomSessionId(conversationID)
.setMessage(message)
.send();
},
agentMessage: function (message, conv) {
let conversationID = conv.id;
console.log("AGENT MESSAGE: "+message);
return chatbase
.setAsTypeAgent()
.setMessage(message)
.setCustomSessionId(conversationID)
.send();
}
}
However, when I call agentMessage("Hello", conv) my console.log shows the Hello message but I get an error that says:
TypeError: chatbase.setAsTypeAgent(...).setMessage is not a function at agentMessage
Am I doing something wrong?
I think you're missing the .newMessage() invocation before your setting of params. So to properly create a new message and set params it would be: chatbase.newMessage().setAsTypeAgent() etc. You can also see this pattern demonstrated on the readme: https://github.com/google/chatbase-node/blob/master/README.md