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

Fix #759 #1109 #1110 by adding custom properties in ReceiverEvent and Context objets #1177

Merged
merged 3 commits into from
Oct 28, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented Oct 26, 2021

Summary

This pull request adds custom properties to ReceiverEvent and Context objects.

Fixes #759
Fixes #1109
Fixes #1110

Checking the added example app would be the quickest way to learn the benefits by the change.

Requirements (place an x in each [ ])

…ies in ReceiverEvent and Context objects
@seratch seratch added this to the 3.8.0 milestone Oct 26, 2021
@seratch seratch added the enhancement M-T: A feature request for new functionality label Oct 26, 2021
@seratch seratch self-assigned this Oct 26, 2021
Copy link
Member Author

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments for reviewers

let receiver;
receiver = new HTTPReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
customPropertiesExtractor: (req) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this name is a bit verbose. Does anyone have a great idea for the naming?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine!

@@ -43,14 +43,14 @@
"dependencies": {
"@slack/logger": "^3.0.0",
"@slack/oauth": "^2.3.0",
"@slack/socket-mode": "^1.1.0",
"@slack/socket-mode": "^1.2.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for extracting retry_num and retry_attempt value from payload

"@slack/types": "^2.2.0",
"@slack/web-api": "^6.4.0",
"@types/express": "^4.16.1",
"@types/node": ">=12",
"@types/promise.allsettled": "^1.0.3",
"@types/tsscmp": "^1.0.0",
"axios": "^0.21.2",
"axios": "^0.21.4",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm audit fix

@@ -168,6 +168,10 @@ export default class AwsLambdaReceiver implements Receiver {
storedResponse = response;
}
},
retryNum: this.getHeaderValue(awsEvent.headers, 'X-Slack-Retry-Num') as number | undefined,
retryReason: this.getHeaderValue(awsEvent.headers, 'X-Slack-Retry-Reason'),
// TODO
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@codecov
Copy link

codecov bot commented Oct 26, 2021

Codecov Report

Merging #1177 (5e4db12) into main (2c12dba) will decrease coverage by 0.50%.
The diff coverage is 53.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1177      +/-   ##
==========================================
- Coverage   71.83%   71.33%   -0.51%     
==========================================
  Files          15       17       +2     
  Lines        1360     1399      +39     
  Branches      405      415      +10     
==========================================
+ Hits          977      998      +21     
- Misses        312      331      +19     
+ Partials       71       70       -1     
Impacted Files Coverage Δ
src/receivers/http-utils.ts 11.11% <11.11%> (ø)
src/errors.ts 98.11% <66.66%> (-1.89%) ⬇️
src/receivers/SocketModeReceiver.ts 89.28% <66.66%> (+0.26%) ⬆️
src/App.ts 83.63% <75.00%> (-0.27%) ⬇️
src/receivers/AwsLambdaReceiver.ts 62.50% <100.00%> (+2.50%) ⬆️
src/receivers/ExpressReceiver.ts 60.97% <100.00%> (+0.57%) ⬆️
src/receivers/HTTPReceiver.ts 38.04% <100.00%> (+0.92%) ⬆️
src/types/middleware.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c12dba...5e4db12. Read the comment docs.

@seratch
Copy link
Member Author

seratch commented Oct 26, 2021

After having reviews from other maintainers, I can add unit tests to improve the coverage.

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Just curious, what purpose does the custom properties extractor serve? Similar to having middleware that customizes the context object?

src/App.ts Show resolved Hide resolved
let receiver;
receiver = new HTTPReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
customPropertiesExtractor: (req) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine!

...authorizeResult,
...event.customProperties,
retryNum: event.retryNum,
retryReason: event.retryReason,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of explicitly adding the retryNum and retryReason keys to the context object here? It looks like these two keys are part of the "built in" keys, so the check above should throw is these are reused by the custom properties, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two properties are built-in ones but they are supposed to be sent as part of the receiver event data, not from the authorize function. Thus, we set these this way.

It looks like these two keys are part of the "built in" keys, so the check above should throw is these are reused by the custom properties, right?

Yes, your understanding here is correct.

@seratch
Copy link
Member Author

seratch commented Oct 26, 2021

Just curious, what purpose does the custom properties extractor serve? Similar to having middleware that customizes the context object?

The most common use case would be propagating HTTP request headers for app tracing and so on. If you invoke another backend services from Bolt middleware/listeners, you may want to set the same x-request-id or something like that to those distributed backends.

The other possible scenario would be to pass the host/app instance specific data to Bolt middleware/listeners.

@seratch seratch force-pushed the issue-759-custom-props branch from 0bb00a5 to 5e4db12 Compare October 28, 2021 08:50
@seratch seratch merged commit e23b691 into slackapi:main Oct 28, 2021
@seratch seratch deleted the issue-759-custom-props branch October 28, 2021 08:56
@ClaudioRizzo
Copy link

Hi there!
I notice this PR introduces something very useful for my use case (I hav an event taking longer than 3seconds and slack keeps pinging me back). I think I can use the cutsom properties to get propagate the headers and respond with a 200 status while my handlers carries on.

I was wondering when will this changes be released?

@seratch
Copy link
Member Author

seratch commented Oct 29, 2021

@ClaudioRizzo Thanks for your interest! We cannot tell when we can release the next version but it won't take long at all! If everything goes well, we will release v3.8 next week or so.

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
3 participants