Add server-only webhook plugin with deduplication#8427
Add server-only webhook plugin with deduplication#8427MtlPhil wants to merge 3 commits intonightscout:devfrom
Conversation
|
Thanks for the PR. The general idea seems useful, but I don’t think it’s ready to merge yet. A few issues need to be addressed first:
If you want to update the PR to address those points, we can take another look. |
- Fix at-least-once delivery: lastSentMills now updated only after a successful (2xx) response; failed requests are retried next cycle - Add pendingMills guard to prevent duplicate concurrent requests - Suppress startup webhook: first checkNotifications call records the current SGV as already seen without firing, so only newly ingested readings trigger webhooks - Add WEBHOOK_PROTOCOL env var (default: http) so HTTPS endpoints are actually reachable; URL is now built from the chosen protocol - Accept any 2xx status code as success (202, 204, etc.) - Add tests/webhook.test.js with 10 tests covering deduplication, retry-on-failure, startup skip, payload shape, and edge cases Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for the detailed review. Here's what was addressed in the latest commit: 1. At-least-once delivery 2. Startup behaviour 3. HTTPS support 4. 2xx success codes 5. Tests
|
TL;DR
This change adds an opt-in, server-only webhook plugin that emits a push-based notification when Nightscout processes a new blood glucose entry. It provides a low-latency mechanism for external services to react to new data without relying on polling, while keeping all follow-up actions outside of Nightscout’s scope. The plugin is disabled by default, runs exclusively on the server, and does not affect existing behavior or the client bundle.
Problem
Some downstream consumers require a push-based signal when new blood glucose data is ingested by Nightscout. Nightscout does not currently expose a simple, low-latency mechanism to notify custom local services immediately when a new glucose entry is recorded.
Polling for new entries is inefficient and introduces unnecessary delay for integrations that need to react in near real time.
Motivation
This change supports architectures where Nightscout acts as a data source and an external service reacts to new glucose data as it becomes available. A common pattern is to run such a service locally (for example, on a Raspberry Pi) and perform follow-up actions outside of Nightscout’s scope.
Providing a webhook at the point where new glucose entries are processed allows these integrations to be implemented cleanly without modifying core Nightscout behavior or relying on polling.
Solution
Introduce a server-only webhook plugin that is invoked when Nightscout processes a new blood glucose entry. The plugin sends an HTTP request to a configurable endpoint, enabling external systems to react immediately.
The implementation:
Backward compatibility
Testing
lib/plugins/index.js,lib/plugins/webhook.js) with no findingsmy.test.env