Global function with state and timers

Hello!

I’m trying to understand how i could snooze phone notifications, specifically for scenarios like “washing machine cycle completed”, something similar to what you find in alarm or calendar apps.

What I’d like to create is a reusable notification system with snooze functionality that I can apply across different notification types (washing machine, dishwasher, security alerts, etc.) without having to implement snooze handling logic for each one separately.

Ideally, I’m looking for:

  1. A way to extend notificationBuilder to add snooze buttons automatically
  2. A centralized handler for snooze requests that can reschedule notifications
  3. Something that’s reusable across different notification scenarios

I’m comfortable with JavaScript which i guess is the only option anyway. I’m thinking along the lines of a helper module or function that could be imported into my rules.

Has anyone implemented something similar or have suggestions on the best approach? Any code examples or patterns would be greatly appreciated. I am not interested in something that specifically solves my problem but advice on how this is normally done, i am installing 4.x from scratch and i’d like to create reusable functions rather than using a “single rule file approach” i had in the past with 3.x

Thanks in advance!