-
Notifications
You must be signed in to change notification settings - Fork 399
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
Add support for a generic event receiver #83
Conversation
FYI: When I ran |
This looks great! I'm curious if you have any additional context around how we might support this bit around using the original response to reply in a serverless setup: https://github.com/BeepBoopHQ/slapp/pull/83/files#diff-e367f1e8f0e82d72c72718c961f0b97fR16 We originally didn't have this bit, and it would always use the response url to reply to slash commands and message actions, but noticed it makes quite a big difference when you don't get that built in spinner while it waits for the response (hopefully that makes sense). By responding right away and making an api call later you lose out on that built in slack functionality. Currently it relies on the response object to have a I'd love to hear any thoughts you had around how we might support that, or challenges you've run into around that part. Other than that I think this looks great, just want to flush out what a potential path to adding that functionality might look like so we avoid having to change the public api later. |
Absolutely, this was actually an interesting thing that I had to think on. The conclusion that I came to was that I do not believe that this should be a thing supported by Slapp if you use this specific interface. The way I would end up working this functionality into a serverless context (generically) is by having two different "functions" (action handlers). The one function would receive the post events, call a handler "function" that contains Slapp, wait 2.5s and respond with a 200. Inside the second function that contains Slapp, it would always call the What you would essentially get is the default behavoir that slapp has where, the response in Slack's UI spins until you call BUT, the crappy thing is that it isn't baked into Slapp. After writing this, I think it probably makes sense to, on events that support it, let it take an optional http.ServerResponse (which is what express uses right?) so that if someone hooks this up to something that isnt express but still happens to have that response object, it can still do it. What do you think? |
Thanks for sharing your thought process, can see how you got to that conclusion for sure. Allowing an optional param that is the response object would be pretty useful I think, and if you have it to pass in, you'd get that functionality. If not, it'd fallback nicely. So express actually adds a few things to https://github.com/expressjs/express/blob/master/lib/response.js#L106 I know Google Cloud functions has a I think that could be added w/o adjusting the way you parse the data. The response can be attached in the |
Yeah definitely, sadly the framework I'm most familiar with is OpenWhisk which is easily the most obscure of all of them. I'll look a little harder into lambda and GCF's node runtime to see what they do. I think the best thing to do would be to allow the optional response, if it has a |
That sounds good. Did you want to add the optional |
I'll do it here, I want to do some digging on those request objects on various platforms |
Though, adding an optional parameter won't be a breaking change... Your call if that's the only thing your questioning in this pull. I'm not sure how you roll releases but either way is fine |
A followup PR would be fine. I'll test this out just to give it a try in a cloud function environment and then I think we can merge it. If you happen to get those other pieces done before I test it out feel free to add them to this PR. |
One thing I'm noticing is that the context lookup middleware wouldn't run for these messages. That's the piece that asynchronously hydrates the message w/ team specific info, like tokens. Were you doing that manually somewhere? I'm trying this branch out now and will dig in a little to see how we might integrate that functionality. |
Heads up, #85 has been merged, which tweaks the parse event logic slightly, so will need to be resolved in your branch. |
👍 also 🤓🌴, smh, I totally missed the context function. I don't know how to make this work cleanly with the context function, I can patch it, but it's starting to get a little weird. The reason is that the context function also expects a While that's not a big deal. It would be an annoying case for a dev to have to debug when they switched. I would think the cleanest approach would be to have the "serverless recievers" call a context with a different signature Thinking out loud here, you could make a breaking change to Slapp that this is the new ™️ signature for context functions and automatically handle the I've pushed my |
Yup, totally agree with what you said. Lemme circle with @mbrevoort in the next few days. I kinda feel like there might need to be a more generic context signature like you mentioned, one that doesn't assume http. |
If I may chime in here, a few thoughts: I've been thinking about forking slapp for serverless use too so super happy to see @barlock take a stab at it first. In regards to the context, not only does that need to be adjusted for a non-standard https://github.com/BeepBoopHQ/slapp/blob/master/src/receiver/index.js#L57
I've also been thinking about how to maybe expand slapp's own middleware to perhaps handle more complex cases (like applying middleware to specific actions, similar to how you can configure express middleware). Perhaps if there was a more slapp configured way of handling middleware instead of relying on express then it would solve both problems? In regards to the |
Totally agree that custom middleware would be useful. The reason I went the way I did in my pr was because every type of event on every platform would (probably) need to be handled differently. As in, the data sent back in the request would need to take a different format for every environment (lambda, gcf, openwhisk). So in order to make it work well, you'd need to write a handler for every environment (or auto detect it, which would be nasty I think). |
Michael Barlock seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This no longer needs to be open. Something like serverless-http can wrap the app. |
Fixes #81
The goal for this is to use Slapp in a serverless environment where there isn't a lot of control over the
req
object.