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

Add Ability to filter Webhooks #6015

Open
Bonapara opened this issue Jun 25, 2024 · 1 comment
Open

Add Ability to filter Webhooks #6015

Bonapara opened this issue Jun 25, 2024 · 1 comment
Labels
good first issue Good for newcomers scope: back+front Issues requiring full-stack knowledge size: hours

Comments

@Bonapara
Copy link
Member

Current Behavior

Webhooks are currently set to send all data without discrimination. There is no functionality to trigger webhooks based on specific objects or actions.

Desired Behavior

We aim to introduce a "Filter" section to allow users to specify which objects and actions should trigger the webhooks. By default, if no filters are specified, the webhook will operate as it currently does, triggering for all objects and actions.

CleanShot.2024-06-25.at.14.07.00.mp4

When a user selects an object to edit, a new row should automatically appear below it to enable adding additional filters. If a selected object is clicked in the menu, it should be deselected and the corresponding filter row removed.

315505f156e52d615f28afb763f1033bc1ac6f1002ef9675d4f7adf77d5ecdc2

Figma

https://www.figma.com/design/xt8O9mFeLl46C5InWwoMrN/Twenty?node-id=34028-89194&t=zgRl269mYJtgBgxt-11

@Bonapara Bonapara added good first issue Good for newcomers scope: back+front Issues requiring full-stack knowledge size: hours labels Jun 25, 2024
Copy link

greptile-apps bot commented Jun 25, 2024

  1. Update Webhook Type: Modify types/webhook.ts to include filter criteria.
export interface Webhook {
  id: string;
  url: string;
  filters?: {
    objects: string[];
    actions: string[];
  };
}
  1. Modify Webhook Form: Update components/webhook/WebhookForm.tsx to include UI for filters.
const [filters, setFilters] = useState({ objects: [], actions: [] });

// Add UI elements for selecting objects and actions
  1. Handle Filter Logic: Update services/webhookService.ts to handle filter logic when triggering webhooks.
function shouldTriggerWebhook(webhook: Webhook, event: Event): boolean {
  if (!webhook.filters) return true;
  const { objects, actions } = webhook.filters;
  return objects.includes(event.object) && actions.includes(event.action);
}

function triggerWebhook(webhook: Webhook, event: Event) {
  if (shouldTriggerWebhook(webhook, event)) {
    // existing logic to send webhook
  }
}
  1. Backend Job Handler: Modify jobs/triggerWebhookJob.ts to respect these filters.
const webhooks = await getWebhooks();
webhooks.forEach(webhook => {
  if (shouldTriggerWebhook(webhook, event)) {
    // existing logic to send webhook
  }
});

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers scope: back+front Issues requiring full-stack knowledge size: hours
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant