gocodebox / lifterlms-rest

LifterLMS REST API Feature Plugin
6 stars 7 forks source link

Add webhook failure email (and admin?) notice(s) #303

Open thomasplevy opened 1 year ago

thomasplevy commented 1 year ago

If a webhook is disabled due to the maximum number of consecutive failures having been reached:

https://github.com/gocodebox/lifterlms-rest/blob/9215df26a9a589d5a5488f019339dd83c1b3c15d/includes/abstracts/class-llms-rest-webhook-data.php#L289-L321

There is currently no way for the admin to be aware of this other than proactively manually reviewing the webhooks list on the admin dashboard.

We should add an email notification that alerts users whenever a webhook fails. I think that creating this as a configurable email notification is probably best so that users can easily customize the behavior without code. Although the easiest solution might be to just make a simple email that can be customized with filters.

The notification should be sent to the webhook owner (and possibly to the site's main admin email address). Configuring this as an email notification makes it easy to add additional subscribers beyond the webhook owner too.

We could also pop an admin notice too?

This hook can be used to trigger:

https://github.com/gocodebox/lifterlms-rest/blob/9215df26a9a589d5a5488f019339dd83c1b3c15d/includes/abstracts/class-llms-rest-webhook-data.php#L315

But it would probably be better to actually create a new hook that triggers on every failure (not just on disabled).

Ideally, I think, a notification should be triggered after 2 failures: first failure might be a momentary interruption, second and beyond failures probably mean there's a problem...