Conversation leases and handoff
Several parties can write in the same conversation: the creator, people on the agency’s team, the creator’s own automations and your application, possibly running on many instances at once. EVVA coordinates them per conversation with three tools:
All three act on one conversation only. Nothing here locks a creator or an agency: hold as many leases at the same time as you have conversations to answer.
A person always wins. A team member can take a conversation over from your application at any time, and the creator’s own reply ends your lease. Your application is told, and its fencing token stops working.
How a reply under a lease works
1. Acquire the lease
Acquire, renew or release a lease
with one operation and an action. It needs write:messages, plus write:messages:automated or
write:messages:operator: the lease is held by your application’s automation or by its live CRM operator.
The SDKs hold the lease for you: they renew it automatically when a third of its lifetime is left (in PHP, call
renewIfDue() between steps) and release it when your function returns.
2. Send under the lease
Add the lease’s fencingToken to every message you send in the conversation. Add expectedLastMessageId (the id of
the newest message you read) to make the send conditional: if the fan has written since, nothing is sent.
A lease is optional for a single send: without one, your send is accepted as long as nobody else holds a live lease and automation is not paused in the conversation. Use a lease whenever your application may answer the same conversation from more than one place.
3. Renew or release it
- Renew with
{"action": "renew", "fencingToken": "42"}beforeexpiresAt. A renewal extends the same lease and keeps the same token. A token that is not the current one, or a lease that has already expired, is refused with409 STALE_FENCING_TOKEN: acquire again. - Release with
{"action": "release", "fencingToken": "42"}as soon as you are done. Releasing twice is harmless.
4. Hand the conversation to a person
When your application should not answer (for example, the fan asks for a person), call
Hand off the conversation. It needs
write:messages, plus write:messages:automated or write:messages:operator.
todefaults toHUMAN. An application can only hand a conversation to a person;to: "APPLICATION"is refused with403 HANDOFF_NOT_PERMITTED.reasonis a machine code (^[a-z0-9_.:-]{1,64}$), never free text.fencingTokenis optional; if you send it, it must be your current one.
The handoff releases your lease, and automation (your application and the creator’s own automations) stays off in
that conversation until a person on the agency’s team hands it back. Sends during that time are refused with
409 AUTOMATION_PAUSED, without Retry-After. The first person to act in the conversation completes the handoff.
A message your application declares as an operator’s may still answer until then; see
Messages from an operator.
A person on the agency’s team can also hand a conversation to your application. Until your application acquires
the lease or sends a message there, the conversation is reserved for it, and other applications are refused with
409 LEASE_HELD.
The automation pause
A reply written by a person (the creator, a member of the agency’s team, or a message your application declared as written by an operator) pauses automated sends in that conversation. The pause lasts the agency’s pause window: 5 minutes by default, and the agency can set it between 1 and 60 minutes under Integrations → Conversation rules in the Partner Hub. Every new reply from a person restarts it.
While it lasts, automated sends and lease acquisitions are refused with 409 AUTOMATION_PAUSED and Retry-After set
to the time left. Do not retry in a loop: a person is handling the conversation.
Messages from an operator
A message your application declares as written by a person in your CRM (HUMAN_AUTHORED or AI_DRAFTED_HUMAN_SENT,
see message authorship) is a person’s message, but the agency’s team still comes first:
- Only a reply from a person on the agency’s team pauses it, for the agency’s pause window. The creator’s replies and your operator’s own replies do not.
- While a handoff to a person has been taken up, it is refused with
409 AUTOMATION_PAUSEDand noRetry-After, until a person hands the conversation back. It may answer a handoff that nobody has taken up yet, without taking it up. - Everything else applies as to every send from your application: another holder’s live lease, a reservation for
another application, and the
fencingTokenrules.
Such a message counts as a person’s reply itself, so it pauses automated sends in the conversation.
Edits, withdrawals, reactions and pins
Changing what the fan already sees is coordinated like a send. This covers editing or withdrawing a message your
application sent, toggling a reaction, and pinning or unpinning a message. Send the lease’s fencingToken in the
body, or as the fencingToken query parameter for a withdrawal and an unpin.
- While a lease is live, only your application’s own lease admits the change, with its current
fencingToken. Under anyone else’s lease, or without the token, it is refused with409 LEASE_HELDandRetry-Afterset to the lease’s remaining time. - A
fencingTokenthat is not your lease’s current one is refused with409 STALE_FENCING_TOKEN. Once the lease is released or has expired, send no token. - After a person on the agency’s team replies, the change is refused with
409 AUTOMATION_PAUSEDfor the agency’s pause window, withRetry-After. While a handoff to a person has been taken up, it is refused with409 AUTOMATION_PAUSEDand noRetry-After, until a person hands the conversation back. The creator’s own replies do not pause it.
AI fan replies
Sending an AI-assisted fan reply is coordinated
exactly like a plain send: the lease and its fencingToken, the automation pause, handoffs and
expectedLastMessageId. Only the answer differs. Where a plain send is refused with 409 LEASE_HELD,
409 STALE_FENCING_TOKEN, 409 AUTOMATION_PAUSED or 409 CONVERSATION_ADVANCED, the AI fan reply answers
422 SEND_REFUSED, without Retry-After, and nothing is sent. Read the coordination state before you try again.
Read the coordination state
Get the coordination state (scope
read:messages) tells you who holds the conversation, whether automation is paused, and whether a handoff is
pending.
A holder from another agency is described only by its kind (APPLICATION or STAFF); applicationId and
expiresAt are set only when the holder belongs to your agency. automation.reason is HUMAN_REPLIED or
HANDED_TO_HUMAN; resumesAt is null while the conversation is handed to a person.
Errors
Events
Coordination changes reach your application through webhooks, realtime and the event feed:
Route lease.lost events to your SDK’s lease helper (observe in TypeScript, Python and PHP, ObserveLeaseEvent in Go)
so that a running reply is cancelled as soon as a person takes over.
