Skip to main content

Starting and Continuing Conversations

1

Send a message

Send a message with no conversationId to start a new conversation. The server creates one.
2

Keep the conversation ID

You can also read it afterwards as client.currentConversationId.
3

Continue the conversation

Pass the ID to the next call:
Passing conversationId: nil always starts a new conversation. It does not fall back to currentConversationId. Pass the ID yourself, or use ConversationState, which keeps it for you.

newConversation

Clears currentConversationId. Use it if you track the current conversation through the client rather than your own state.
ConversationState has its own clear(), which also empties the message list. Use that in UI code.

listConversations

Lists the current user’s (or device’s) conversations, newest first.
String?
A cursor from an earlier page. Leave it out to start at the beginning. Prefer loadMore() over passing cursors yourself.
Int?
How many per page, from 1 to 100. The server uses 20 if you leave it out.
Only conversations created through the mobile SDKs are listed. Widget, API, and integration conversations are left out. Which ones you get depends on identity: the signed-in user’s conversations if there is one, otherwise the device’s. See User Identity.
See Conversation for the full type.

listMessages

Loads the messages in a conversation.
String
required
The conversation to load messages from.
String?
A cursor from an earlier page. Leave it out to start with the newest messages.
Int?
How many per page, from 1 to 100. The server uses 20 if you leave it out.
Pages go backwards in time. The first page holds the newest messages, and each loadMore() gets older ones. Inside a page, messages run oldest to newest, so you can add a page to a chat view as it is. When you load an older page, add it to the top.
Each Message has both a plain text value (all the text joined together) and a parts list, so you can show tool activity inline with the conversation:
Messages with no parts are skipped, so a page can hold fewer items than limit even when hasMore is true. Base your “load more” button on hasMore, never on data.count.
See Message for the full type.

PaginatedResponse

[T]
required
The items on this page.
Bool
required
Whether there are more pages.
Int
required
How many items there are in total.

loadMore

Gets the next page, or nil when hasMore is false. The page keeps its own cursor, so you have nothing to pass along.
loadMore() returns only the next page’s items. It does not build up a full list. Add next.data to your own array yourself, at the top or bottom depending on the list.
The limit you passed the first time is reused for every later page, so page sizes stay the same.
ConversationListState and ConversationState build up the list for you, and skip messages you already have. Use them unless you need something custom.

Infinite scroll in SwiftUI

Conversation Status

A conversation that has ended, or that a person has taken over, cannot take new messages. Sending to one fails with 403 CHAT_CONVERSATION_NOT_ONGOING. Check before showing a text field:

Conversation & Pagination

The full type reference

SwiftUI

Ready-made state for lists and history

Streaming

Send messages and stream replies

User Identity

Tie conversations to users