Looking to modify replies via middleware after the handler generates the reply

8 views
Skip to first unread message

Daniel Pritchett

unread,
Feb 18, 2018, 8:55:23 PM2/18/18
to Lita
Hi folks.  I've been trying to figure out the easiest way to modify messages after a handler returns the message but before the user sees the message.

It seems I'll need to monkeypatch either Robot#send_message or maybe Message#reply or somehow invent a new class of hook.

Thoughts?  I'd love to figure out a solution that I can submit as a PR rather than just my own hacks because I'm writing a book for PragPub on Lita and I'd like the code to be clean.

Thanks!
Daniel Pritchett

Jimmy Cuadra

unread,
Feb 24, 2018, 4:20:48 AM2/24/18
to Daniel Pritchett, Lita
Hi Daniel,

You're right that there's not currently a mechanism in Lita to do this. I think the best way to do it would be to add a new extension hook for it. That said, Lita development hasn't been very active in a while, so I wouldn't want to promise that such a thing would get released in a timely manner. I'm the primary author of Lita and have largely moved on from working with Ruby. Lita has also been in a stable enough state that there hasn't been a pressing need to make changes and release a new version. That said, I did plan to get back to it some day. I've also hoped to put out a formal call for new maintainers to keep the project healthy even when I'm not involved myself.

As a more immediate workaround, you could of course use monkey patches, as that's what Ruby allows you to do, but of course there's no guarantee a future version of Lita wouldn't break such an approach. Another possibility—though this is a totally harebrained so take it with a giant grain of salt—would be to create a Lita adapter that wraps another adapter, injecting its own logic before/after delegating the adapter it wraps.

It's very cool to hear that you're writing about Lita! Please share your work with us, either by mailing the list again, or by tweeting at @litachatbot when it's available. I'm sure many people would be interested.

Jimmy

--
You received this message because you are subscribed to the Google Groups "Lita" group.
To unsubscribe from this group and stop receiving emails from it, send an email to litaio+un...@googlegroups.com.
To post to this group, send email to lit...@googlegroups.com.
Visit this group at https://groups.google.com/group/litaio.
To view this discussion on the web visit https://groups.google.com/d/msgid/litaio/97cd6bca-d663-4dec-8a0c-d33bc4cc5fe9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages