rubyhipchatlita

How to forward message responses with ruby Lita?


I am working with a chatbot operating on the lita ruby gem using lita-hipchat. After a response is made to lita using hipchat, lita will be able to return messages to the user who created the response through the reply method. I would like to change this pattern and be able to send a hipchat to a secondary user, essentially being able to cc or forward that same response to more than one user. Is this possible using only the Lita gem?

I am aware that sending messages through http or the hipchat gem is another option for sending messages to secondary users, but I would prefer to do this through lita.


Solution

  • You can do this using Robot#send_messages. For example:

    def my_handler_route(response)
      user2 = Lita::User.find_by_id("user2")
      target = Lita::Source(user: user2)
      robot.send_message(target, "This message will go to User2!")
    end
    

    This is essentially what Response#reply is doing—but with the convenience of automatically targeting the original source.