Add complete snitch feature with contact management, consent system, and notification delivery
This commit is contained in:
@@ -12,6 +12,7 @@ from datetime import datetime, timezone, timedelta
|
||||
import core.postgres as postgres
|
||||
import core.notifications as notifications
|
||||
import core.adaptive_meds as adaptive_meds
|
||||
import core.snitch as snitch
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -358,6 +359,37 @@ def check_nagging():
|
||||
f"Sent nag {nag_count}/{max_nags} for {med['name']} to user {user_uuid}"
|
||||
)
|
||||
|
||||
# Check if we should snitch (max nags reached)
|
||||
should_snitch, trigger_reason, snitch_settings = (
|
||||
snitch.should_snitch(
|
||||
user_uuid, med_id, nag_count, missed_doses=1
|
||||
)
|
||||
)
|
||||
|
||||
if should_snitch:
|
||||
logger.info(
|
||||
f"Triggering snitch for {med['name']} - {trigger_reason}"
|
||||
)
|
||||
results = snitch.send_snitch(
|
||||
user_uuid=user_uuid,
|
||||
med_id=med_id,
|
||||
med_name=med["name"],
|
||||
nag_count=nag_count,
|
||||
missed_doses=1,
|
||||
trigger_reason=trigger_reason,
|
||||
)
|
||||
|
||||
# Log results
|
||||
for result in results:
|
||||
if result.get("delivered"):
|
||||
logger.info(
|
||||
f"Snitch sent to {result['contact_name']} via {result['contact_type']}"
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
f"Failed to snitch to {result['contact_name']}: {result.get('error')}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking nags: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user