slack-io / slacker

Slack Bot Framework
MIT License
31 stars 9 forks source link

Ability to set context in middleware & capture responses #12

Closed trajan0x closed 1 day ago

trajan0x commented 5 days ago

Ability to inherit context in middleware

Right now, command middleware is pretty limited because:

  1. It can not capture the responses in any way. Traditionally, in an http middleware I could do something like this:
    return func(handler slacker.CommandHandler) slacker.CommandHandler {
        return func(cmdCtx *slacker.CommandContext) {
                      ctx := context.WithValue(cmdCtx.Context(), "test", "value")
                     // in gin this would be c.Request.WithContext (or c.WithContext in net/http
                      cmdCtx.WithContext(ctx)
                      next()
                     // within the next method I could query this context
        }
    }

There's nothing like that at all. For an example use case, you could do thing s like otel with this. I've put together an example here w/o the context pass down

It would also be very standard to be able to capture the response after next() is called.

This could either be done by overwriting the writer, or with a hook on reply

raed-shomali commented 2 days ago

Would you be open to putting together a PR to address this?