Messages
All sends go through 1 endpoint:
The request needs content, or template_params, or both. For a template, see Templates.
3 ways to address a message
Give exactly 1 identifier. If a request has more than 1, the API reads them in the order below. It ignores the others.
conversation_id: reply in a conversation that you know
conversation_id is the conversation number that your agents see in the dashboard URL. It is the display_id of the conversation, not its internal id. The conversation gives the inbox, so you do not send inbox_id. A number that is not in your account returns 404.
contact_id: send to a contact that you have
The API uses the most recent conversation of the contact on that inbox with a status other than resolved. If there is none, it opens a new conversation. The contact must have an address that the channel can reach: a phone number for WhatsApp or SMS, an email address for email. If the contact has no such address, the API returns contact_not_messageable.
phone_number: send to a number that has no contact yet
The number must be in E.164 format: a +, the country code, then digits, with no spaces or dashes. If no contact has that number, the API creates a contact. Only then does it use the optional contact fields: name, email, and custom_attributes. This way works on WhatsApp, Twilio, and SMS inboxes only. Other inboxes return unsupported_channel.
The service window
Some channels let a business send free text only for a period after the last message of the customer. This period is the service window. After the window closes, the API accepts only a template. The API checks the window before it accepts the request. If the window has closed, the API returns this error immediately:
Send a template for the first message to a new contact on a channel with a window. A conversation with no message from the customer has no open window. The API rejects plain content to that conversation with outside_messaging_window.
The Phone inbox holds the calls from Cloud Call Center. It cannot send a message to the customer, so the API rejects every send to it with 422. A private note through the conversation endpoint is the exception. See Phone calls.
To know if the window is open before you send, read the conversation. Its can_reply field is true when the window is open. See Conversations.
Send template_params only on an inbox that has approved templates. When template_params is present, the API does not check the window, on any channel. On a channel without templates, the API sends content as free text, and only the provider enforces the window.
Conversation reuse
An API send goes into the same conversation as the replies of the customer. The API uses the most recent conversation with a status other than resolved. If all the conversations have the status resolved, the API opens a new conversation. If the inbox has the option to keep 1 conversation for each contact, the API always uses the latest conversation, resolved or not.
A second send to the same number continues the same conversation. Your agents see 1 conversation, not 2.
Response
The API answers 201 with the message:
Partial effects
The API finds or creates the contact and the conversation before it checks the window. A request that fails with outside_messaging_window can leave a new contact and a new conversation. This is safe. A second request with a template uses the same contact and conversation. It does not make duplicates.