Skip to content
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

Middleware for handling responses #364

Closed
1 of 4 tasks
Tenzer opened this issue Jun 4, 2021 · 2 comments
Closed
1 of 4 tasks

Middleware for handling responses #364

Tenzer opened this issue Jun 4, 2021 · 2 comments
Labels
area:adapter discussion question Further information is requested

Comments

@Tenzer
Copy link

Tenzer commented Jun 4, 2021

I would like to add tracing to my bot, so I was looking at setting up middleware to add tracing to each request. It does however look like middleware only can be triggered for incoming requests and not for the outgoing responses.

Would it be possible to let middleware's hook into the response action? That way, a trace can be started in the middleware and attached to the context of the request, and then finalised when the response is being sent after the event has been handled.

Category (place an x in each of the [ ])

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Others

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@seratch seratch added area:adapter discussion question Further information is requested labels Jun 4, 2021
@seratch
Copy link
Member

seratch commented Jun 4, 2021

Hi @Tenzer, thanks for asking this question!

As you mentioned, a global middleware is not a right solution for this. A suggested way to do this is to have your own adapter. With your own adapter, you can hook the timings of the BotRequest construction from raw HTTP requests and the BoltResponse conversion to a valid HTTP/Socket Mode response.

Here is the built-in Flask adapter: https://github.com/slackapi/bolt-python/blob/v1.6.1/slack_bolt/adapter/flask/handler.py#L40-L41 At least, you can reuse to_bolt_request and to_flask_response. If you are not using Flask, you may be able to find the one you can use here. Also, refer to the document about implementing a custom adapter.

I hope this was helpful to you! if everything is clear, would you mind closing this issue?

@Tenzer
Copy link
Author

Tenzer commented Jun 5, 2021

Thank you! That's really helpful. I'll take a look at this next week. I'll close this ticket and get back if I've got further questions. Have a nice weekend.

@Tenzer Tenzer closed this as completed Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:adapter discussion question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants