
Integration
Your agent handles threads like this. The next section covers the exact setup steps.- Customer reaches out → Plain creates a thread via your email, slack, chat or any other channel integration.
- Listen to webhooks to trigger your agent
-
thread.thread_created- Fired when a thread is created, if you you can listen to this webhook if you need logic to decide if to assign your agent -
thread.thread_assignment_transitioned- This is fired when a thread’s assignment changes, this can be useful for when you want to use assignment to filter threads with your own logic, or via a Workflow rule. -
Channel events (
thread.email_received,thread.slack_message_received, etc.)
- Example automation flow:
-
thread.thread_createdwebhook is received- Here you have the opportunity to handle all threads via your agent, or filter threads the Agent will handle based on some conditions (for example: you could check the thread’s tier, and skip handling Enterprise Tier threads)
-
Update thread agent status to In progress (see below for more info) -
updateThreadAgentStatus(IN_PROGRESS)
- Call your agent, with the context from the newly created thread
-
If agent can reply:
-
replyToThread -
updateThreadAgentStatus(HANDLED) -
markAsDone
-
-
If the agent can’t reply
-
replyToThreadwith a message you will hand off -
updateThreadAgentStatus(HANDED_OFF)
-
-
Error handling:
- A typical flow:
-
createNotewith what happened -
updateThreadAgentStatus(HANDED_OFF) -
unassignThread -
markThreadAsTodothis will mean the thread will go back into the Todo queues for a human to pickup
Setup
Create a machine user
First, create a machine user to represent your AI agent. You can do this from Settings > Machine users & API keys. You can also set a custom avatar to distinguish your agent.Subscribe to webhooks
Listen for the events that should make your agent act. At a minimum, subscribe to the following, depending on which channels you have enabled:-
thread.thread_created -
thread.thread_status_transitioned -
Channel events (for message bodies):
thread.email_received,thread.slack_message_received,thread.chat_received, etc. Complete details can be found in the webhook events documentation.
Responding to threads
Your agent can respond to threads using standard reply mutations for the required channel. For channel agnostic thread replies, you can use thereplyToThread mutation:
Managing agent status
An important step is managing the Agent Status of a thread. This should be done as part of your integration, so that in Plain, we can display threads in the correct views. Agent status has 3 states, defined below.
Only threads that have an agent status of
HANDED_OFF will appear in your First Response, Next Response and Investigating queues.
This is intentional so that work your agent is handling is kept out of view, and only threads that need human interaction are visible.
To update Agent status you can use the API like so:
Caveats
Automatic handoff behavior
When a human agent replies to a thread that your AI marked asHANDLED or IN_PROGRESS, Plain automatically moves it to HANDED_OFF status. This signals collaboration between your AI and human agents.
Why this matters: If your AI responds to a thread but the customer replies again, and then a human agent jumps in, the thread will now appear in your Todo queues.
