-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
✅ Deploy Preview for dev-web-novu ready!
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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