0

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.

Alex Cohen
  • 5,596
  • 16
  • 54
  • 104
  • how do you determine who the 2ndary user even is? – lacostenycoder Feb 28 '19 at 22:44
  • I'm not exactly sure but it looks like you should just be able to mention whoever you want in your response. So my prefix your response with the mention name `@someonelse Here is my response`. Similar to what they are doing in the source [here](https://www.rubydoc.info/gems/lita/Lita%2FRobot:send_messages_with_mention) – Antarr Byrd Mar 01 '19 at 06:10
  • @lacostenycoder the secondary user can be located using account details such as emails attached to users, the lita redis database and the Lita::User object https://www.rubydoc.info/gems/lita/Lita/User finding this will provide all the details that are needed to match those found in the response objects used to send replys – Alex Cohen Mar 02 '19 at 00:19
  • @AntarrByrd Thats a good sugestion if these messages were being sent to a room available to be viewed by multiple users. However I am looking for a method of sending a private message to two distinct users. – Alex Cohen Mar 02 '19 at 00:21

1 Answers1

1

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.

Jimmy
  • 35,686
  • 13
  • 80
  • 98
  • That worked! I prefer using Lita::User.find_by_name instead of Lita::User.find_by_id, but both work: https://www.rubydoc.info/gems/lita/Lita/User#find_by_name-class_method – Alex Cohen Apr 03 '19 at 19:47