0

I have a chatbot I am trying to make for Google Chat platform. My boss wants it so that if someone says in a room "Im Bored" or "its slow" and so on that it responds with a canned response. Something like "have you made your calls today?" or similar. I have attempted to do this but can only get it to work if the chat bot is mentioned.

function onMessage(event) {
  var name = "";

  if (event.message.text == "Im Bored") {
    name = "You";
  } else {
    name = event.user.displayName;
  }
  var message = name + ": You could scrub accounts or make some calls.  Have you logged into statflo today? ";

  return { "text": message };
}

what we would like is it to see the messages and find any that say bored or slow and respond automatically. The above does not work for our use. Any ideas on this?

I have read the event formats page at https://developers.google.com/hangouts/chat/reference/message-formats/events but couldnt get anywhere with that.

ellucidone
  • 21
  • 6

1 Answers1

0

You can make a condition to search for an specific string in each message sent. For example:

    function onMessage(event) {
      var name = "";

      if (event.type == "MESSAGE") {
        if (event.message.text.indexOf("I'm bored") > -1) {
        var message = name + ": You could scrub accounts or make some calls.  Have you logged into statflo today? ";

      return { "text": message };
        }
      }
    }

EDIT:

This is not possible for Rooms. As the documentation says:

Just like people, bots can participate in chat rooms, and they can respond to direct messages. But unlike people, bots only see messages directed to them when a person @mentions them in a chat room, or when a person sends them a direct message.

Jescanellas
  • 2,555
  • 2
  • 9
  • 20
  • Thank you for your response. I tested your answer but this still requires the chatbot to be mentioned using @botname I'm bored. I was trying to find a way to use this without mentioning the bot. – ellucidone Nov 29 '19 at 15:03
  • Sorry for misunderstanding the question. It is not possible for chat Rooms. I updated my question. – Jescanellas Dec 03 '19 at 14:32