feat(bot): add delete action for medications and routines

- Added delete action to medications handler with confirmation flow
- Added delete action to routines handler with confirmation flow
- Updated AI config with delete examples for both meds and routines
- Added 'delete', 'remove', 'get rid of' to action recognition
This commit is contained in:
2026-02-16 06:04:19 -06:00
parent 7d7d6fb3a0
commit 20f995119c
3 changed files with 86 additions and 4 deletions

View File

@@ -225,8 +225,49 @@ async def handle_medication(message, session, parsed):
else:
await message.channel.send(f"Error: {resp.get('error', 'Failed to fetch adherence')}")
elif action == "delete":
med_id = parsed.get("medication_id")
name = parsed.get("name")
needs_confirmation = parsed.get("needs_confirmation", True)
med_id, name, found = await _find_medication_by_name(message, token, med_id, name)
if not found:
return
if not med_id:
await message.channel.send("Which medication should I delete?")
return
# Handle confirmation
if needs_confirmation:
if "pending_confirmations" not in session:
session["pending_confirmations"] = {}
confirmation_id = f"med_delete_{name}"
session["pending_confirmations"][confirmation_id] = {
"action": "delete",
"interaction_type": "medication",
"medication_id": med_id,
"name": name,
"needs_confirmation": False # Skip confirmation next time
}
await message.channel.send(
f"⚠️ Are you sure you want to delete **{name}**?\n\n"
f"This will also delete all logs for this medication.\n\n"
f"Reply **yes** to confirm deletion, or **no** to cancel."
)
return
# Actually delete
resp, status = api_request("delete", f"/api/medications/{med_id}", token)
if status == 200:
await message.channel.send(f"🗑️ Deleted **{name}** and all its logs.")
else:
await message.channel.send(f"Error: {resp.get('error', 'Failed to delete medication')}")
else:
await message.channel.send(f"Unknown action: {action}. Try: list, add, take, skip, today, refills, snooze, or adherence.")
await message.channel.send(f"Unknown action: {action}. Try: list, add, delete, take, skip, today, refills, snooze, or adherence.")
async def _add_medication(message, token, name, dosage, unit, frequency, times, days_of_week, interval_days):