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

[Discussion] Routing in the piece framework #4633

Open
islamaf opened this issue May 5, 2024 · 0 comments
Open

[Discussion] Routing in the piece framework #4633

islamaf opened this issue May 5, 2024 · 0 comments
Assignees
Labels
🌟 announcement this feature needs announcement 🌟 feature new major feature help wanted Extra attention is needed 🥄 scooping features that require scooping and designing

Comments

@islamaf
Copy link
Collaborator

islamaf commented May 5, 2024

Description
Adding a routing based functionality in the piece framework which would act as a branching mechanism on the piece itself. A piece action like "Wait for approval" could be a great example of why routing could be useful, as it is an action that would have possibly 2 or more outputs which would have their paths directly from the piece (without the need to add a branch after the piece to handle the run based on the outcome).
The current method:
image
What we want to do:
image

Describe the solution you'd like
A solution would be adding an outcomes array in the piece action, which would then have the branching made according to the possible outcomes array and then returning a Map after running the piece action as key:value, where the key is the name of the outcome and the value is the result of that possible outcome.
Example for "Wait for approval" piece action:

import { createAction } from '@activepieces/pieces-framework';
import { ExecutionType, PauseType, branchedPieceResponse } from '@activepieces/shared';

export const waitForApprovalLink = createAction({
  name: 'wait_for_approval',
  displayName: 'Wait for Approval',
  description: 'Pauses the flow and wait for the approval from the user',
  props: {},
  errorHandlingOptions: {
    continueOnFailure: {
      hide: true,
    },
    retryOnFailure: {
      hide: true,
    },
  },
  // Here we define the names of the outputs expected to be branched from the piece
  outputs: [
    { name: 'approved' }, 
    { name: 'denied' }
  ],
  async run(ctx) {
    if (ctx.executionType === ExecutionType.BEGIN) {
      ctx.run.pause({
        pauseMetadata: {
          type: PauseType.WEBHOOK,
          response: {},
        },
      });

      // Return an empty Map while execution is paused
      return branchedPieceResponse()
    } else {
      // Return a Map populated with the expected returned data
      return branchedPieceResponse({
        approved: ctx.resumePayload.queryParams['action'] === 'approve', // Branch state for when "approved"
        denied: ctx.resumePayload.queryParams['action'] !== 'approve', // Branch state for when "denied"
      })
    }
  },
});

We would like to know your feedback about this feature and how it would impact your experience using Activepieces.
In case you have a better solution for implementing routing in the piece framework, we are welcoming all suggestions!

@islamaf islamaf added help wanted Extra attention is needed 🌟 feature new major feature 🌟 announcement this feature needs announcement 🥄 scooping features that require scooping and designing labels May 5, 2024
@islamaf islamaf self-assigned this May 5, 2024
@islamaf islamaf changed the title Routing in the piece framework [Discussion] Routing in the piece framework May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 announcement this feature needs announcement 🌟 feature new major feature help wanted Extra attention is needed 🥄 scooping features that require scooping and designing
Projects
None yet
Development

No branches or pull requests

1 participant