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

feat: support for synchronous custom step handling #2408

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

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 }) => {
  try {
    const category: string[] = inputs.category as string[];
    if (category.includes('dogs')) {
      complete({
        outputs: {
          options: [
            { key: 'Poodle', value: 'value-0' },
            { key: 'Bulldog', value: 'value-1' },
            { key: 'Beagle', value: 'value-2' },
          ],
        },
      });
    } else if (category.includes('cars')) {
      complete({
        outputs: {
          options: [
            { key: 'Toyota', value: 'value-0' },
            { key: 'Ford', value: 'value-1' },
            { key: 'Jeep', value: 'value-2' },
          ],
        },
      });
    } else {
      fail({ error: `Invalid category: ${category} (valid: 'dogs', 'cars')` });
    }
  } catch (error) {
    fail({ 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 run build
  3. Use npm install path/to/the/bolt-js/project 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 should now be able to use the 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
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.

1 participant