The ConversationWithParticipants resource accepts all the details for a conversation and allows up to 10 participants in one request. It is especially helpful for situations where you want to send group texts. It helps prevent issues that might occur with existing conversations when you add participants individually.
All URLs in the reference documentation use the following base URL:
https://conversations.twilio.com/v1
Using the REST API, you can create Conversation with Participants in the default Conversation Service instance via a "shortened" URL that doesn't include the Conversation Service instance SID (ISXXX...
). If you are only using one Conversation Service (the default), you don't need to include the Conversation Service SID in your URL, e.g.
POST /v1/ConversationWithParticipants
For Conversations applications that build on more than one Conversation Service instance, you will need to specify the Conversation Service SID in the REST API call:
POST /v1/Services/ISxx/ConversationWithParticipants
The unique ID of the Account responsible for this conversation.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The unique ID of the Conversation Service this conversation belongs to.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The unique ID of the Messaging Service this conversation belongs to.
^MG[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
A 34 character string that uniquely identifies this resource.
^CH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The human-readable name of this conversation, limited to 256 characters. Optional.
An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's sid
in the URL.
An optional string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set "{}" will be returned.
Current state of this conversation. Can be either initializing
, active
, inactive
or closed
and defaults to active
inactive
active
closed
Contains absolute URLs to access the participants, messages and webhooks of this conversation.
An absolute API resource URL for this conversation.
POST https://conversations.twilio.com/v1/ConversationWithParticipants
This resource behaves differently than most other Conversations API resources. Here's how it works:
Parameter validation: It validates all conversation and participant parameters and returns various possible conversations errors.
Conversations are created synchronously: If the request is valid, a conversation will be created and returned in the response. This conversation will be in the state initializing
while the participants are added. In this state, the conversation cannot be updated.
Participants are added to the conversation asynchronously: Once all participants are added, the conversation state will be set to active
and the conversation can be used. Listening to the onConversationStateUpdated
webhook event or polling the conversations GET
endpoint are both acceptable ways to check if the conversation is ready to be used.
System Errors: If any unexpected errors happen while adding the participants, the conversation state will be set to closed
. You can view the error logs in the Twilio Console, and in your webhook notifications if you subscribe to them.
The X-Twilio-Webhook-Enabled HTTP request header
true
false
application/x-www-form-urlencoded
The human-readable name of this conversation, limited to 256 characters. Optional.
An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's sid
in the URL.
The unique ID of the Messaging Service this conversation belongs to.
^MG[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
An optional string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set "{}" will be returned.
Current state of this conversation. Can be either active
, inactive
or closed
and defaults to active
inactive
active
closed
ISO8601 duration when conversation will be switched to inactive
state. Minimum value for this timer is 1 minute.
ISO8601 duration when conversation will be switched to closed
state. Minimum value for this timer is 10 minutes.
The default email address that will be used when sending outbound emails in this conversation.
The default name that will be used when sending outbound emails in this conversation.
The participant to be added to the conversation in JSON format. The JSON object attributes are as parameters in Participant Resource. The maximum number of participants that can be added in a single request is 10.
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 createConversationWithParticipants() {11const conversationWithParticipant =12await client.conversations.v1.conversationWithParticipants.create({13friendlyName: "Friendly Conversation",14participant: [15'{"messaging_binding": {"address": "<External Participant Number>", "proxy_address": "<Your Twilio Number>"}}',16'{"identity": "<Chat User Identity>"}',17],18});1920console.log(conversationWithParticipant.sid);21}2223createConversationWithParticipants();
1{2"sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"friendly_name": "Friendly Conversation",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"links": {18"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",19"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",20"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks"21},22"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"23}
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 createConversationWithParticipants() {11const conversationWithParticipant =12await client.conversations.v1.conversationWithParticipants.create({13friendlyName: "Friendly Conversation",14participant: [15'{"messaging_binding": {"address": "<External Participant Number>"}}',16'{"messaging_binding": {"address": "<External Participant Number>"}}',17'{"messaging_binding": {"projected_address": "<Your Twilio Number>"}}',18],19});2021console.log(conversationWithParticipant.sid);22}2324createConversationWithParticipants();
1{2"sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",6"friendly_name": "Friendly Conversation",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"links": {18"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",19"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",20"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks"21},22"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"23}