google / chatbase-node

Quickly integrate your Node.js chatbot with Chatbase Analytics
Apache License 2.0
78 stars 24 forks source link

setMessage is not a function #28

Open sudiptachatterjee opened 5 years ago

sudiptachatterjee commented 5 years ago

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?

cristiancavalli commented 5 years ago

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