N
Novu•11mo ago
Nitin

Date Range filtering for In-App notifications

Is there is way to filter the incoming notification in the in-App setup by date range? For example if provided with a date range, then only fetch paginated notifications for that date range. I could not find anything in the documentation or in the code. Let me know if I need to raise this as an issue on Github!
7 Replies
Zac Clifton
Zac Clifton•11mo ago
Not at this time, however feel free to upvote analytics dashboard in the backlog https://roadmap.novu.co/roadmap
empe
empe•11mo ago
There might be a workaround for the time being, I haven't tested it, but it makes sense for it to work. You could potentially fetch all notifications and then perform client-side filtering based on the createdAt property of each notification. To fetch notifications, you can use the fetchNotifications method provided by Novu's headless API. After fetching, you can implement your own logic to filter the notifications according to the desired date range by comparing the createdAt dates of the notifications to your specified range . Here's an example in JavaScript:
import { IMessage } from "@novu/headless";

// Fetch notifications with the headless service
headlessService.fetchNotifications({
listener: ({ data }) => {
// Assuming data is an array of notifications with a createdAt property
const filteredNotifications = data.filter((notification: IMessage) => {
const createdAt = new Date(notification.createdAt);
return createdAt >= startDate && createdAt <= endDate;
});

// Now you have `filteredNotifications` within your date range
},
// ... other properties
});
import { IMessage } from "@novu/headless";

// Fetch notifications with the headless service
headlessService.fetchNotifications({
listener: ({ data }) => {
// Assuming data is an array of notifications with a createdAt property
const filteredNotifications = data.filter((notification: IMessage) => {
const createdAt = new Date(notification.createdAt);
return createdAt >= startDate && createdAt <= endDate;
});

// Now you have `filteredNotifications` within your date range
},
// ... other properties
});
Use this as reference: https://docs.novu.co/notification-center/client/headless/get-started
Nitin
NitinOP•11mo ago
@Emil I also thought the same but seems like we have a lot of data (1000+ notifications per account) and it is growing more every day. So somewhere I feel that doing either server-side or client side rendering with increasing data will increase the load gradually and is not an optimal way 😓
empe
empe•11mo ago
Yeah, I totally get it.. We will announce once this feature is available. @Nitin Do you mind share your use case with Novu maybe?
Nitin
NitinOP•11mo ago
Yes yes sure. Do I share here only or is there a separate thread / channel for it?
empe
empe•10mo ago
@Nitin You can do it here
Pawan Jain
Pawan Jain•10mo ago
@Nitin ping
Want results from more Discord servers?
Add your server