Skip to content

Comments

feat: support for synchronous custom step handling#2408

Merged
WilliamBergamin merged 22 commits intomainfrom
dynamic-options-support
May 14, 2025
Merged

feat: support for synchronous custom step handling#2408
WilliamBergamin merged 22 commits intomainfrom
dynamic-options-support

Conversation

@WilliamBergamin
Copy link
Contributor

@WilliamBergamin WilliamBergamin commented Jan 27, 2025

Summary

This PR changes the way function_executed events handle auto acknowledgement. These changes lift the auto ack logic into a middleware that is then registered to the function listener.

The function listener exposes an autoAcknowledge flag, when enabled (default) the auto ack middleware is added, when disabled the auto ack middleware is not added. This allows the function listener to support dynamic options use cases, functions used as dynamic inputs must complete or fail before acknowledging the request (this provides a crisp user experience).

Example

app.function('get-options', { autoAcknowledge: false }, async ({ inputs, ack, fail, complete, logger }) => {
  try {
    const category: string[] = inputs.category as string[];
    if (category.includes('dogs')) {
      await complete({
        outputs: {
          options: [
            { key: 'Poodle', value: 'value-0' },
            { key: 'Bulldog', value: 'value-1' },
            { key: 'Beagle', value: 'value-2' },
          ],
        },
      });
    } else if (category.includes('cars')) {
      await complete({
        outputs: {
          options: [
            { key: 'Toyota', value: 'value-0' },
            { key: 'Ford', value: 'value-1' },
            { key: 'Jeep', value: 'value-2' },
          ],
        },
      });
    } else {
      await fail({ error: `Invalid category: ${category} (valid: 'dogs', 'cars')` });
    }
  } catch (error) {
    logger.error(`Failed to handle a function request (error: ${error})` });
  } finally {
    await ack();
  }
});

Manual tests

These changes were manually tested against

Testing

  1. Pull this branch
  2. npm install & npm pack
  3. Use npm install path/to/the/bolt-js/slack-bolt-4*.tgz to install the built package in a project with a custom step like bolt-js-custom-step-template
  4. Set the options field of the function handler to { autoAcknowledge: false }
  5. You are now required to use ack input parameter in your handler
  6. AutoAck behavior is now disabled you must now manually call await ack(); for this specfic handler

Requirements (place an x in each [ ])

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

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@a1cb83c). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2408   +/-   ##
=======================================
  Coverage        ?   93.35%           
=======================================
  Files           ?       37           
  Lines           ?     7575           
  Branches        ?      664           
=======================================
  Hits            ?     7072           
  Misses          ?      498           
  Partials        ?        5           

☔ 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 removed the request for review from mwbrooks February 12, 2025 19:10
@WilliamBergamin WilliamBergamin marked this pull request as ready for review February 13, 2025 17:29
@misscoded misscoded requested a review from seratch February 13, 2025 20:28
@WilliamBergamin
Copy link
Contributor Author

I think I will break this up into 2 separate PRs, one to refactor and add more unit tests the other to introduce the auto acknowledge toggle

@WilliamBergamin
Copy link
Contributor Author

Please review and merge #2424 first 🙇 🙏

@WilliamBergamin WilliamBergamin added this to the 4.3.1 milestone May 7, 2025
@WilliamBergamin WilliamBergamin modified the milestones: 4.3.1, 4.4.0 May 7, 2025
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 LGTM! 👾 ✨

I had some trouble with outputs of the included example but found the example matching slack-samples/bolt-python-custom-step-template to work as expected!

A few comments ask quick questions about implementation, some on testing, and others around documentation. The testing changes might be nice to include in this PR, but I understand if larger efforts on documentation are better for a follow up 🫡

Huge GG on the lift to set this PR up for a quick review as well 🚢 💨

@WilliamBergamin WilliamBergamin merged commit 0959f94 into main May 14, 2025
18 checks passed
@WilliamBergamin WilliamBergamin deleted the dynamic-options-support branch May 14, 2025 18:26
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.

2 participants