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

Provide Access to Request/Response #1109

Closed
4 of 10 tasks
adarnon opened this issue Sep 8, 2021 · 2 comments · Fixed by #1177
Closed
4 of 10 tasks

Provide Access to Request/Response #1109

adarnon opened this issue Sep 8, 2021 · 2 comments · Fixed by #1177
Assignees
Labels
enhancement M-T: A feature request for new functionality
Milestone

Comments

@adarnon
Copy link

adarnon commented Sep 8, 2021

Description

The current SDK API does not let middlewares/handlers access the server request/response that initiated the workflow.

Many frameworks, especially Express/Connect-like frameworks, rely on access to the req/res objects instead of globals. For example, attaching a DB connector or user info to the req object. Being able to access these objects will make integration with other frameworks significantly easier.

A few examples:

  • I use Pino for logging, with pino-http middleware that attaches req.log. Bolt's Logger API requires a global function that only has access to the msg argument and not the req/res context so I can't integrate my current logging solution.
  • I use Next.js and much of my code for API routes relies on being able to access req/res from the handler. Having access to req/res will allow me to reuse existing code.

The only workaround at the moment is to implement a custom receiver that wraps the Bolt app with AsyncLocalStorage, so that they can be accessed from inside the Bolt handlers.

I suggest providing access to req/res in Bolt middleware (app.use(...)), so that the user can use them to attach anything they'd like to the context object that Bolt passes around anyway.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

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

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.
@gitwave gitwave bot added the untriaged label Sep 8, 2021
@seratch seratch added enhancement M-T: A feature request for new functionality and removed untriaged labels Sep 8, 2021
@seratch seratch added this to the 3.8.0 milestone Sep 8, 2021
@seratch
Copy link
Member

seratch commented Sep 8, 2021

Hi @adarnon, thanks for sharing this feedback!

We are planning to add custom properties to the receiver events: #759 With this change, you can relay any custom data as part of context object in App middleware/listeners. We don't have a pull request for it but I did a prototyping a few days ago here (the name customRequestProperties is too long, I will change it when making a pull request 😸 ).

We cannot tell when the new feature will be available but if everything goes well, the change can be merged with a few weeks and be included in v3.8 (the version after the next).

@seratch
Copy link
Member

seratch commented Oct 25, 2021

Once we release socket-mode v1.2.0, I will come up with a pull request for this enhancement. slackapi/node-slack-sdk#1363

@seratch seratch self-assigned this Oct 26, 2021
seratch added a commit to seratch/bolt-js that referenced this issue Oct 26, 2021
…ies in ReceiverEvent and Context objects
seratch added a commit that referenced this issue Oct 28, 2021
… Context objets (#1177)

* Fix #759 #1109 #1110 by adding custom properties in ReceiverEvent and Context objects
* Add AWS receiver implementation
* Fix bugs in SocketModeReceiver and add more tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants