Cancel Pending Messages
Messages
Cancel Pending Messages
Cancel all pending, scheduled, and queued Tuco AI messages for a lead — use when a lead replies Stop or opts out to instantly halt outbound campaigns.
POST
Cancel Pending Messages
Call this endpoint when a lead replies “Stop”, “Unsubscribe”, or any opt-out keyword. It cancels all pending, scheduled, and queued messages for that lead and removes their jobs from the processing queue.
Authentication
Request body
You must provide at least one of these identifiers:Cancel all pending messages for this lead ID. Most direct — skips the lookup step.
Phone number (E.164 format). Tuco looks up the lead by phone (including altPhone1-3), then cancels all pending messages for that lead. If no lead is found, cancels messages matching this phone directly.
Email address. Tuco looks up the lead by email (including altEmail1-3), then cancels all pending messages for that lead. If no lead is found, cancels messages matching this email directly.
How it works
Identify the lead
If
leadId is provided, use it directly. Otherwise, look up the lead by recipientPhone or recipientEmail (checks primary + alt fields).Find cancellable messages
Query all messages for this lead (or address) with status
queued, pending, or scheduled.Examples
Success response (200)
Always
true on success (even when 0 messages cancelled).Number of messages set to
cancelled in the database.Number of BullMQ jobs removed. May be less than
cancelledCount if some jobs already started processing.The resolved lead ID (may be
null if no lead was found and cancellation was done by address).IDs of all cancelled messages.
Error responses
| Status | When | Body |
|---|---|---|
400 | No identifier provided | { "error": "Either leadId, recipientPhone, or recipientEmail is required" } |
400 | Invalid leadId format | { "error": "Invalid leadId" } |
401 | Missing or invalid API key | { "error": "Unauthorized" } |
500 | Server error | { "error": "Internal server error" } |