简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM