novuhq / novu

Open-Source Notification Platform. Embeddable Notification Center, E-mail, Push and Slack Integrations.
https://novu.co
Other
34.46k stars 3.51k forks source link

[NV-2374] Allow notifications feed filtering by custom payload data #3466

Closed chauandrew closed 1 year ago

chauandrew commented 1 year ago

šŸ”– Feature description

At the moment, we can query notification meessages/feeds by page, feedId, seen, read, subscriberId, channels, etc. It would be helpful to query by custom data in messages.payload

šŸŽ¤ Why is this feature needed ?

I work on a web app where we are trying to migrate our existing notification systems to Novu. One feature of our existing notification system is that we are able to filter notifications by their 'component type', or a subsection of the app. As we transition to Novu, we can store this custom data within a notification payload, but we run into compatibility issues since we are unable to filter by these features.

āœŒļø How do you aim to achieve this?

I would like to expand the GET /v1/notifications api to take custom data as input.

Specifically, I think it will involve the following:

šŸ”„ļø Additional Information

No response

šŸ‘€ Have you spent some time to check if this feature request has been raised before?

šŸ¢ Have you read the Code of Conduct?

Are you willing to submit PR?

Yes I am willing to submit a PR!

NV-2374

chauandrew commented 1 year ago

Good catch I completely missed that. Seems like this ticket makes sense as an API change, and the other as a front end change once this is finished. But I'm new to the codebase, so open to feedback / other suggestions!

chauandrew commented 1 year ago

Can I pick up this ticket?

jainpawan21 commented 1 year ago

cc:- @scopsy

scopsy commented 1 year ago

Sure thing @chauandrew!

chauandrew commented 1 year ago

Hi @scopsy - sorry about this, recently learned that I'm not supposed to be contributing to any open source projects. Don't think I can take this on. But if I'm able to get permission in the future I'll try to contribute!

Thanks!

gitstart commented 1 year ago

@scopsy I would like to pick this up

thenbe commented 1 year ago

I also have similar use case:

Say you produce an invoice at the beginning of the month.

On day 1, you create a new invoice and send a reminder to the user. On day 2, the user has not paid, so you send another reminder. On day 3, the user has not paid, so you send another reminder. ...and so on.

Then, you want to view all the reminders you have sent for this particular invoice. Is there a way to view/paginate those reminders? How can this be done?

Workaround:

Use the invoice_id as the subscriber_id. Then, use the existing search functionality to search by subscriber_id.

curl https://api.novu.co/v1/notifications?search=${INVOICE_ID}

Proposed solution:

  1. Define a custom_field of "invoice_id": 123 when sending a notification.
await novu.trigger('TAG', {
    metadata: {
        invoice_id: 123,
    },
    // ...
});
  1. Then search for notifications where "invoice_id" === "123". This fetches the desired result and allows for pagination.
curl https://api.novu.co/v1/notifications?metadata_invoice_id=123

Prior art:

This is the pattern used by the Postmark API:

  1. Define a metadata custom_field = "foo" when sending a message.
  2. Afterwards, search for messages that have the metadata custom_field = "foo".
github-actions[bot] commented 1 year ago

Hi, I'm Jarvis šŸ¤–

I'm a bot built to help you with your contribution to Novu. I will add instructions and guides on how to run the subset of the Novu platform associated to this issue and make your first contribution.

This issue was tagged as related to @novu/api and the related code is located at the apps/api folder, here is how I can help you:

First time contributing to Novu? If that's the first time you want to contribute to Novu here are a few simple steps to get you started: 1. Fork the repository and clone your fork to your local machine. 2. Install the dependencies using `npm run setup:project`. 3. Create a new branch with the number of the issue, for example: `1454-fix-something-cool` and start contributing based on the [Contributing Guide](https://docs.novu.co/community/run-locally) or the short guide in the section below. 4. Create a Pull request and follow the template of creation
Run and test `@novu/api` locally ### Run API in watch mode The easiest way to start the API is to run `npm run start:api` from the root of the repository ### Run API integration tests To validate your changes or simply to run the e2e tests run `npm run start:e2e:api`. All the e2e tests have the `.e2e.ts` suffix and usually are located near the controller files of each module.
LetItRock commented 1 year ago

hey @chauandrew šŸ‘‹ the functionality will be implemented in the PR #3939 ;)