Skip to content

Comments

fix: refactor function handler for follow up auto ack behavior#2424

Merged
WilliamBergamin merged 21 commits intomainfrom
refactor-function-listener-for-future-auto-ack-changes
Apr 30, 2025
Merged

fix: refactor function handler for follow up auto ack behavior#2424
WilliamBergamin merged 21 commits intomainfrom
refactor-function-listener-for-future-auto-ack-changes

Conversation

@WilliamBergamin
Copy link
Contributor

@WilliamBergamin WilliamBergamin commented Feb 14, 2025

Summary

This PR aims to

  • Increase unit test coverage for the custom function handler
  • Align the function handler with the middleware pattern used by actions and events
  • Set up the project to allow simple introduction of auto acknowledgment flag

Manual tests

These changes were manually tested against

bolt-js-custom-step-template -> no breaking change observed 🟢
bolt-ts-starter-template -> no breaking change observed 🟢

Requirements

@WilliamBergamin WilliamBergamin added enhancement M-T: A feature request for new functionality semver:minor labels Feb 14, 2025
@WilliamBergamin WilliamBergamin self-assigned this Feb 14, 2025
@codecov
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 96.10390% with 6 lines in your changes missing coverage. Please review.

Project coverage is 92.97%. Comparing base (657416f) to head (f7f210d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/App.ts 89.28% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2424      +/-   ##
==========================================
+ Coverage   92.59%   92.97%   +0.37%     
==========================================
  Files          36       36              
  Lines        7472     7441      -31     
  Branches      653      652       -1     
==========================================
- Hits         6919     6918       -1     
+ Misses        545      518      -27     
+ Partials        8        5       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WilliamBergamin WilliamBergamin marked this pull request as ready for review February 17, 2025 21:42
@WilliamBergamin WilliamBergamin removed the request for review from misscoded April 28, 2025 17:58
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@WilliamBergamin Lots of awesome changes are happening here! I'm also hopeful that these will make later additions and future maintenance more clear 🙏 ✨

I left handfuls of comments for now with suggestions and thoughts, but nothing seems to be so blocking. A few notes around typings might be worth considering though!

It took me a bit to familiarize myself with parts of this code, but tomorrow I plan to review the test changes. Thank you in advanced for these changes and care for the code 👾

Comment on lines -1102 to -1105
// If functionBotAccessToken exists on context, the incoming event is function-related *and* the
// user has `attachFunctionToken` enabled. In that case, subsequent calls with the client should
// use the function-related/JIT token in lieu of the botToken or userToken.
const token = context.functionBotAccessToken ? context.functionBotAccessToken : selectToken(context);
Copy link
Member

Choose a reason for hiding this comment

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

@WilliamBergamin Super nice catch here! It seems like attachFunctionToken might've been ignored before these changes 👁️‍🗨️

📝 Moving all of this logic into selectToken is also a nice change that aligns with the expected behavior noted in #2500!

Copy link
Member

Choose a reason for hiding this comment

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

📣 Following up on this with #2513 since changes to selectToken allow us to share this token in context without unexpected overrides I believe!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for creating #2513 🙇 I left one comment and I've approved it 🟢

Comment on lines 981 to 983
// Factory for say() utility
const createSay = (channelId: string): SayFn => {
const token = selectToken(context);
const token = selectToken(context, this.attachFunctionToken);
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Thinking aloud here, but I'm wondering if inlining createSay might allow us to use the same token from below and perhaps even a client from the pool:

bolt-js/src/App.ts

Lines 1117 to 1120 in d61f2cd

// Set say() utility
if (conversationId !== undefined && type !== IncomingEventType.Options) {
listenerArgs.say = createSay(conversationId);
}

AFAICT we do not use this factory function in other places. No blocker since we're overriding the token in these arguments at the moment, though perhaps that wouldn't be needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great point 💯 but I think we should dedicate a specific PR for this change, since the scope of these changes is already large

I added a TODO comment for this

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

📝 Leaving another note of a related change in mind from another PR!

I'm also wondering if this is a patch change, since at a glance no changes to behavior were noticed in testing. Though I still have not reviewed the tests 😉

Comment on lines -1102 to -1105
// If functionBotAccessToken exists on context, the incoming event is function-related *and* the
// user has `attachFunctionToken` enabled. In that case, subsequent calls with the client should
// use the function-related/JIT token in lieu of the botToken or userToken.
const token = context.functionBotAccessToken ? context.functionBotAccessToken : selectToken(context);
Copy link
Member

Choose a reason for hiding this comment

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

📣 Following up on this with #2513 since changes to selectToken allow us to share this token in context without unexpected overrides I believe!

@WilliamBergamin WilliamBergamin requested a review from zimeg April 29, 2025 21:10
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@WilliamBergamin Thanks so much for sifting through all of those comments! 🤖

Another pass at reviewing and more test runs with a sample app have me excited for these changes.

I left two more comments around documentation and test cases that would be nice to include before merging this, but once the time is right please feel free to merge 🚢 💨

The improvements to test helpers are a nice addition.

Thank you for your patience in these reviews as well 🙏 ✨

@WilliamBergamin WilliamBergamin merged commit 46744f7 into main Apr 30, 2025
18 checks passed
@WilliamBergamin WilliamBergamin deleted the refactor-function-listener-for-future-auto-ack-changes branch April 30, 2025 14:16
@WilliamBergamin WilliamBergamin added this to the 4.3.0 milestone May 7, 2025
@hello-ashleyintech hello-ashleyintech modified the milestones: 4.3.0, 4.2.2 May 7, 2025
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 semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants