When AgroPulse detects a sensor anomaly, it automatically notifies the people responsible for that greenhouse. Notifications travel over two channels in parallel: email via SendGrid and WhatsApp via CallMeBot. Both channels are protected by circuit breakers that prevent a failing external service from slowing down or blocking the detection loop.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/diarpicu2022-commits/backend-AgroPulse/llms.txt
Use this file to discover all available pages before exploring further.
Notification flow
When the anomaly detection sweep finishes evaluating sensors, it collects all unnotified anomalies and dispatches them in sequence:- The anomaly is looked up alongside its sensor and greenhouse name.
- An
Alertrecord is inserted so the anomaly appears in the dashboard feed. NotificationService.notifyAnomaly()is called with the anomaly details.- For each active recipient of that greenhouse, an email and/or WhatsApp message is sent depending on which contact details are present.
- The anomaly’s
notifiedflag is set totrueso it is not dispatched again.
Setting up notifications
Configure the SendGrid API key
Set the following environment variables in your deployment. The Without
SENDGRID_FROM_EMAIL variable controls the sender address shown in the email.SENDGRID_API_KEY, the email step is skipped entirely. SendGrid account and a verified sender identity are required on the SendGrid side.Add alert recipients
Recipients are configured per greenhouse via the To receive WhatsApp messages, the recipient must first message the CallMeBot service to obtain their personal
/api/alert-recipients endpoint. Each recipient can have an email address, a WhatsApp phone number, or both.callmebotApikey. See the CallMeBot documentation for setup instructions.Recipients with no callmebotApikey receive only email. Recipients with no email receive only WhatsApp. A recipient with neither will not receive any notification until contact details are added.Configure sensor thresholds
Notifications only fire when an anomaly is detected, and anomalies are only detected for sensors that have an active
SensorThreshold record. Create thresholds via /api/sensor-thresholds with minValue, maxValue, noDataMinutes, stuckMinutes, and spikePercent values appropriate for each sensor type.See Automated sensor anomaly detection for a full explanation of how thresholds map to anomaly conditions.Email notifications
Emails are sent via the SendGrid Java SDK. Each email includes the greenhouse name, sensor name, anomaly type, the value at detection time, and the detection timestamp. Messages are sent as HTML. The subject line follows the pattern:[AgroPulse] Anomalía: {TYPE} — Sensor "{name}"
WhatsApp notifications
WhatsApp messages are delivered via the CallMeBot free API. The message is a compact single-line text containing the anomaly type, sensor name, greenhouse name, detected value, and timestamp. Each recipient stores their owncallmebotApikey in the alert_recipients table. The API key is per-phone-number and is obtained directly from CallMeBot by the recipient.
Circuit breakers
Both delivery channels are wrapped in Resilience4j circuit breakers to prevent a degraded external API from causing cascading failures in the detection loop.| Parameter | SendGrid | CallMeBot |
|---|---|---|
| Sliding window size | 5 calls | 5 calls |
| Failure rate threshold | 60% | 60% |
| Pause duration when open | 30 seconds | 60 seconds |
notified. The delivery failure is logged but the anomaly cycle continues.