-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response middleware #1021
Response middleware #1021
Conversation
By calling |
# Conflicts: # src/robot.coffee # test/robot_test.coffee
Okay, with #1019 landed, I picked this back up.
I adjusted this to send the list of strings to each middleware instead of each string. It's slightly more cumbersome on the middleware, but 100% backwards compatible. I also added some docs and a couple of tests. Ready for 👀 again. |
We probably also need a suite of tests for message sending pre-middleware. Not much there right now to protect the existing state. |
This is tough, because hubot-mock-adapter does not actually obey the |
😭 Okay, I guess we just leave the Response/Adapter interface as it is right now (a crazy mess) and put our hopes and dreams on #1036. |
Yeah, I think this can move forward separately. As long as this is bound to the normal response interface (all the existing function calls), we can ensure backwards compatibility with all manner of shim layers in the core. It ain't gonna be pretty, but it does allow us to segment out the decision making. |
As an author of response middleware, do you think you'd need to be able to target specific Response methods? For example, would you want to be modify topics vs send and reply differently? I suspect you would, so that would be a good thing to include in the |
Really good point! Do you think just |
I added |
How does this look after #1036 merges and we port all the existing methods over to a singular flow (similar to how Message encompasses all kinds of input)? |
Edit: (completely forgot I had already commented on this and not refreshed. lolwhoops) My first reaction is concern, but I think this will be okay when mixed in with #1036 as long as the @bhuga, can you try to rough out what this would look like when merged with the ideas in #1036? (i.e. custom prompts, #michaelneedsmoretimeforthis 😭 |
I'll noodle on this. We're running into this sort of thing too, and it's plain that a pile of We should also decide if the callback as the last argument to |
I thought on this some. I don't think we should make them more abstract. My term Different chat systems use structured data to handle messages. I don't think it's possible for a generic middleware to understand all of this structured data, or to provide an interface to make it "plaintext enough". If a script returns structured data, we pass that through to this middleware. So I would rename But I don't see #1036 coming up with something that wouldn't be able to fit that pattern. The method might become |
Any objections to merging? Would love to get starting using this. |
I was thinking about how to deal with adapter's having different maximum lengths of message they support sending, and it occurred to me that response middleware could be useful for that. Currently, if you send a large message with most adapters, they silently truncate, or the service itself truncates on their behalf. As a developer of a hubot, you wouldn't know that. I was thinking one approach to that would be to have a response middleware that checks the length of a message, and it could do something like emit an error so the developers could track down what was generating large messages. |
- `strings` | ||
- An array of strings being sent to the chat room adapter. You can edit these, or use `context.strings = ["new strings"]` to replace them. | ||
- `method` | ||
- A string representing which type of response message the listener sent, such as `send`, `reply`, `emote` or `topic`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this instead be a message type instead of the method name? I think it is better to specify if message.type == text
instead of `if message.type in ['send','reply'], but that depends on whether we want to allow differentiation between those types of messages... Maybe not worth worrying about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought, I hadn't considered that.
Types might be better in some cases, but the edges are fuzzier. Internally we're abstracting away colors in slack attachments, for example, and I would want to consider a helper for that as "text". But is an emote text? Is a topic? What type would a slack attachment, a sent file, or telegram buttons be?
My first instinct is that type
would be fuzzy for some of the more basic messages, and have a 1:1 correlation with advanced message formats in specific adapters. It's thus worse than send
in the base case and gains no value in the adapter-specific case, instead being a piece of metadata boilerplate that custom message types require without much benefit.
But I'm not really sure. Can you think of any complex messages that could safely share the same type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right here. I want there to be a way to group and abstract outgoing messages, but maybe it isn't so easy. I'm really just squeamish about seeing this everywhere: if message.type in ['send','reply']
. Can you think of another way to make that extremely common case less gross?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. message.plaintext
? Adapters could set it alongside basic send
and reply
, and it arguably applies to topic
and emote
, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this, but independently had the exact same idea. Thinking in the same style as Ruby message.plaintext?
returns a boolean. No ?
in CS though, so I like just having it as a "read-only" property. Thinking about applying the same idea to inbound messages to make robot.listen
easier to work with (instead of needing to do message instanceof TextMessage
every time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted the context.plaintext
pattern. See what you think. f0acd0f...0544029 has the diff from the last time you looked until now.
I wrote a really simple, and hacky response middleware a while back. I much prefer this PR though. I'm really glad this is being done, and hopefully it'll be merged soon 👍 |
👍 I like it. I think we can probably merge this. |
The triumvirate of middleware is complete. Half life 3 confirmed. |
Hot on the heels of #1019, response middleware gives you the chance to edit outgoing messages.
It looks like this: