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

Trigger Workflows with Webhooks #5248

Draft
wants to merge 12 commits into
base: next
Choose a base branch
from
Draft

Trigger Workflows with Webhooks #5248

wants to merge 12 commits into from

Conversation

Cliftonz
Copy link
Contributor

What change does this PR introduce?

This PR adds the ability for users to define webhooks to trigger workflows in Novu.
We create a collection that allows a user to define a preset subscribers and varibles pertaining to the workflow so it can be triggered only by a unique url.

This set of endpoints deals with CRUD operations on a webhook and triggering a workflow with a webhook.

Why was this change needed?

This change is needed for automatins that can only use http calls and not the Novu SDK

This commit introduces a new WebhookTrigger repository with its corresponding entity, schema, and types. It also modifies the Notification Template repository with new types and the inclusion of a new id for notification templates. These additions and updates aim to enhance the software's functionality by including new components and updating existing ones.
This commit includes the addition of "@paralleldrive/cuid2" to API dependencies in the package.json file. The changes are reflected in the pnpm-lock.yaml file, demonstrating that the package has been successfully installed and is ready for use in the API's codebase. Additionally, the dependency 'debug' has been updated for several packages.
The 'types' file has been added to the list of exports in the notification template repository. This step maintains an organized structure and ensures availability of all necessary types to users of this repository.
The 'subscribers' field has been included in both the webhook-trigger schema and entity files. This update allows each webhook trigger to have a list of subscriber IDs associated with it, enabling more efficient handling of notifications.
Added new use-cases for creating, updating, listing, and regenerating webhooks. 'webhookIds' field was also added to the 'message-template' schema. Besides, made changes to handle these updates in Webhook-controller and updated DTOs accordingly.
Copy link

netlify bot commented Feb 29, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 41e8298
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/65e7a59117b3eb0008c79f8e
😎 Deploy Preview https://deploy-preview-5248--dev-web-novu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Refactored the regeneration process for webhooks to ensure uniqueness of the new patient ID. A loop was added to generate and check the uniqueness of the ID until it is unique. Also, modified the webhook creation method to be asynchronous and included a "subscribers" property in the webhook request DTO.
The changes involve extracting the logic for generating a new webhook ID into a separate use case, 'GenID'. This ensures that the method to generate a unique ID is abstracted from the 'RegenWebhook' use case. This makes the code cleaner, improves maintainability and also allows for reusability of the ID generation logic if needed elsewhere in the future.
CreateWebhook in webhook.usecase.ts has been expanded with token generation using a separate use case 'GenID' and subscribers. This enriches its functionality by generating a unique token for a webhook to improve security and allowing the assignment of subscribers to a created webhook. Also, comments indicating upcoming variable validation tasks were added in the webhook.controller.ts.
The createWebhook method in webhook.controller.ts file now includes '@ApiOperation' annotations. This provides a summary and description for the 'create new webhooks' endpoint in the API documentation. Additionally, comments about the planned task to introduce variable validation were added to the same method.
Added a new 'subscribers' field to the WebhookResponseDto and subsequently updated the convertToDTO function in the 'convert-response.usecase.ts' file to include this field. Additionally, updated the 'execute' method in 'get-webhook.usecase.ts' to return a Promise of 'WebhookResponseDto' type or null. Also, the method 'triggerWebhook' in 'webhook.controller.ts' has been significantly updated to handle webhook triggers more robustly.
@Cliftonz Cliftonz changed the title Trigger Webhooks Trigger Workflows with Webhooks Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant