States and Timers in Conversations
States and Timers help automatically manage the lifecycle of your application's conversations. They keep your users focused on ongoing active conversations, while closing out older inactive conversations to make sure you're not exceeding the Conversations per user limit of 1,000.
A conversation's state indicates whether a conversation is active, inactive, or closed. You can use timers to automatically transition conversations across these states. Both state
and timers
are properties of the Conversation Resource.
This guide provides an overview of states and timers and how to configure them.
A Conversation can be one of four states:
active
: The conversation is currently in use. This is the default state for a newly created conversation.inactive
: The conversation is not in use, but you can reactivate it if needed.closed
: The conversation is no longer in use and you can't reactivate it.initializing
: Twilio is setting up the conversation and you can't edit it yet. This state is only used shortly when a conversation is created through the ConversationsWithParticipants resource.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateConversation() {11const conversation = await client.conversations.v112.conversations("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.update({ state: "inactive" });1415console.log(conversation.accountSid);16}1718updateConversation();
Response
1{2"sid": "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",6"friendly_name": "friendly_name",7"unique_name": "unique_name",8"attributes": "{ \"topic\": \"feedback\" }",9"date_created": "2015-12-16T22:18:37Z",10"date_updated": "2015-12-16T22:18:38Z",11"state": "inactive",12"timers": {13"date_inactive": "2015-12-16T22:19:38Z",14"date_closed": "2015-12-16T22:28:38Z"15},16"bindings": {},17"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",18"links": {19"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",20"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",21"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks",22"export": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Export"23}24}
A conversation can be transitioned between these states by updating the conversation directly, by a configured timer, and automatically by the system. The following table summarizes the possible transitions:
From State | To State | Behavior |
---|---|---|
active | inactive | Transitioned by timer or API. |
active | closed | Transitioned by timer or API. |
inactive | active | Automatically transitioned when a new message is added to the conversation, or by API. |
inactive | closed | Transitioned by timer or API. |
closed | N/A | Closed state is final. |
initializing | active | Automatically transitioned when the ConversationsWithParticipants process finishes. |
initializing | closed | Automatically transitioned the if conversation with participants process fails. |
A conversation can be set from active to inactive and vice versa at any time.
As described in the State Transition Table:
- A conversation can only be transitioned to inactive by using a configured timer or by making an API call.
- A conversation is automatically transitioned from inactive to active when a new message is added to the conversation.
Info
Active and inactive conversations both count towards the Conversations per User limit.
Once a conversation closes, it becomes read-only and you can't add new participants or messages to it.
Closing a conversation is permanent, and you can't transition it back to the active
or inactive
state.
Closed conversations don't count towards the Conversations per user limit.
Timers allow you to set a timeframe of inactivity after which a conversation automatically transitions between states. Timers are optional, but we highly recommend enabling them to manage conversations efficiently and avoid distruptions from the Conversations per user limit.
You can set up timers in two ways:
- Global Defaults: Set up default timers for all conversations created in your account. You can set up global defaults from the Conversations Defaults page in the Twilio Console.
- For Each Conversation: Set up a timer for a specific Conversation using the REST API.
There are two configurable timers to transition between conversation states:
- Inactive Timer: Transitions a conversation from active to inactive. It counts down from when the last message added was in the conversation.
- Closed Timer: Transitions a conversation to closed.
- If it's the only timer, it counts down from when the last message was added in the conversation.
- If there is also an inactive timer, it counts down from when the conversation becomes inactive.
Timers are set in ISO 8601 duration format (PT10M
for 10 minutes).
Info
Note: When configuring timers, durations must be specified in days or smaller units (hours, minutes, seconds).
Using months P6M
or years P1Y
will result in an invalid format error. For instance, to set a timer for 6 months,
use P180D
(assuming an average month has 30 days), and for 1 year, use P365D
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateConversation() {11const conversation = await client.conversations.v112.conversations("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.update({14"timers.closed": "PT60000S",15"timers.inactive": "PT5M",16});1718console.log(conversation.accountSid);19}2021updateConversation();
Once set, the timers property of the Conversation resource displays the date and time when the timer will elapse in ISO 8601 date and time in UTC.
1"timers": {2"date_inactive": "2025-04-16T22:19:38Z",3"date_closed": "2025-04-16TT22:28:38Z"4}
When the inactive timer lapses or you manually set the conversation to inactive, the date_inactive
property stops returning in the Conversation resources. However, the inactive timer configuration is still retained, and the timer resets if you set the conversation back to active
again. To disable a timer entirely, set it to PT0S
.
Some other things to be aware of when configuring timers:
- Timers have a precision of 1 second.
- The minimum time for the inactive timer is 60 seconds. For a closed timer, the minimum time is 600 seconds (10 minutes).
- If both timers are set, the closed timer will automatically update based on the inactive timer.
- When a conversation is closed, all timers are removed.
Inactive Timer | Closed Timer | Behavior |
---|---|---|
none | none | Conversations is active until you change it manually. |
Set to 1 hour | Set to 24 hours | The conversation transitions to inactive after 1 hour of inactivity. Then, after an additional 24 hours of inactivity, it transitions to closed . |
1 hour | none | The conversation transitions to inactive after 1 hour of inactivity. It stays in that state until a new message is added or you manually change the state. |
none | Set to 24 hours | The conversation transitions to closed after 24 hours of inactivity. |