novuhq / novu

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

[NV-1725] πŸš€ Feature: Fetch all triggered events API #2828

Open iamclaytonray opened 1 year ago

iamclaytonray commented 1 year ago

πŸ”– Feature description

I've gone through the API reference and it doesn't seem like there's an API to fetch all triggered events. Because of this, I don't know how to programmatically cancel an event.

🎀 Why is this feature needed ?

My use case:

When a student books a lesson, we confirm the lesson with the pro. Then, we schedule a lesson reminder email the day before the lesson is set to take place. On occasion, due to weather or other circumstances, the lesson time has to change. However, I don't see an API to fetch all triggered events to be able to cancel that scheduled event. While the cancellation API works great, I'm sure, it's unusable to me right now.

✌️ How do you aim to achieve this?

Code sample:

const novu = new Novu(process.env.NOVU_API_KEY);

// Get all triggeredEvents - likely paginated
const events = await novu.triggeredEvents.fetch();

// Get all triggeredEvents for a given `subscriberId`
const events = await novu.triggeredEvents.fetch({
  subscriberId,
});

// more options/variations

πŸ”„οΈ Additional Information

I tried reaching out in Discord and Pablo recommended I create an issue here :slig

πŸ‘€ 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?

None

NV-1725

jainpawan21 commented 1 year ago

Hi @iamclaytonray Let me know if this works? You can list all triggered events either using https://docs.novu.co/api/get-messages/ or https://docs.novu.co/api/get-activity-feed/ Each item in response array will have transactionId, then you can cancel particular event using https://docs.novu.co/api/cancel-triggered-event/

scopsy commented 1 year ago

I think we can find a better way of doing that, maybe allow fetching all "pending" workflows for a particular subscriberId + template identifier instead of all workflows historically. @iamclaytonray will it help you in this case?

oba2311 commented 1 year ago

@scopsy 's suggestion sounds good to me - I'm assuming that would be a parameter say "status" to filter by?

in this case - when ready would be good to add it to the UI as well (activity). Opening a sub issue.

scopsy commented 1 year ago

Would need to do a bit more investigation on this in how best to implement this, will need to think on the technical implementation side before it is ready for work.

iamclaytonray commented 1 year ago

Sorry for not responding. Yes, that would be very helpful! I did find a way to bypass this a bit with the current API and passing some extra data to the payload. But anything along these lines would be super helpful! Thanks!

oba2311 commented 1 year ago

Sounds about right will add to the small batch of April.