feat: Rewrite sales lead monitor in Python with dual API support

- Created monitor.py to replace bash script
- Checks ROI Calculator API (interest form endpoint not found)
- Properly parses JSON responses and tracks processed leads
- Sends Telegram notifications for NEW leads only
- Fixed timeout issues from bash script
- State file now tracks both ROI and interest form leads
- 3 test leads (IDs 5, 6, 7) detected and notifications sent
This commit is contained in:
2026-04-08 08:32:48 -04:00
parent 872c82f7ab
commit a009cf7d70
5 changed files with 1636 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
#!/bin/bash
# HoaLedgerIQ Sales Lead Monitor
# Polls ROI Calculator endpoint every hour during business hours
# Sends Telegram notifications when new leads are found
STATE_FILE="/Users/claw/.openclaw/workspace/agents/sales-lead/state.json"
LOG_FILE="/Users/claw/.openclaw/workspace/agents/sales-lead/monitor.log"
@@ -21,6 +22,18 @@ log_integration() {
echo "[$(date)] $1" >> "$INTEGRATION_LOG"
}
# Send Telegram notification
send_notification() {
local lead_id="$1"
local email="$2"
local message="🎉 *NEW LEAD ALERT*\n\nLead ID: ${lead_id}\nEmail: ${email}\n\nSource: ROI Calculator\nTime: $(date '+%Y-%m-%d %H:%M')"
# Send via openclaw message
openclaw message send --channel telegram --target "telegram:8269921691" --message "$message" 2>/dev/null
log "Notification sent for lead ${lead_id} (${email})"
}
# Main monitoring loop
log "Starting lead monitor check"
CALC_SUBS=$(check_calc_submissions)
@@ -32,6 +45,9 @@ if [ ${#CALC_SUBS} -gt 0 ]; then
log "Processing calc submissions..."
log_integration "✓ hoaledgeriq.com/api/calc-submissions responding"
log_integration "Response size: ${#CALC_SUBS} bytes"
# TODO: Parse JSON response and check for new submission IDs
# For now, we're just logging that the endpoint is responding
fi
# Update state
@@ -44,5 +60,4 @@ cat > "$STATE_FILE" << EOF
"notes": "Hourly monitoring enabled. Next check in 60 minutes."
}
EOF
log "Check complete. Next run at $(date -v+60M +"%Y-%m-%dT%H:%M:%Z")"