chatbase-node icon indicating copy to clipboard operation
chatbase-node copied to clipboard

setMessage is not a function

Open sudiptachatterjee opened this issue 6 years ago • 1 comments

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?

sudiptachatterjee avatar May 17 '19 21:05 sudiptachatterjee

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

cristiancavalli avatar May 18 '19 01:05 cristiancavalli