Skip to main content

ChatClient

The ChatClient provides methods for interacting with X Chat (direct messages), including sending messages, managing conversations, and handling media.

send_message

Sends an encrypted message to a specific Chat conversation.
from xdk.chat.models import SendMessageRequest

response = client.chat.send_message(
    conversation_id="123456789",
    body=SendMessageRequest(
        text="Hello, this is a test message"
    )
)
conversation_id
str
required
The Chat conversation ID.
body
SendMessageRequest
required
Request body containing the message content.
SendMessageResponse
object
Response data confirming the message was sent.

get_conversation

Retrieves messages and key change events for a specific Chat conversation with pagination support.
for page in client.chat.get_conversation(
    conversation_id="123456789",
    max_results=50,
    chat_message_event_fields=["id", "text", "created_at"]
):
    for message in page.data:
        print(message)
conversation_id
str
required
The Chat conversation ID.
max_results
int
Maximum number of message events to return.
pagination_token
str
Token for pagination to retrieve the next page of results.
chat_message_event_fields
List[str]
A comma separated list of ChatMessageEvent fields to display.
GetConversationResponse
Iterator
Iterator that yields pages of conversation messages. Automatically handles pagination.

send_typing_indicator

Sends a typing indicator to a specific Chat conversation on behalf of the authenticated user.
response = client.chat.send_typing_indicator(
    conversation_id="123456789"
)
conversation_id
str
required
The Chat conversation ID.
SendTypingIndicatorResponse
object
Response confirming the typing indicator was sent.

media_download

Downloads encrypted media bytes from an XChat conversation.
response = client.chat.media_download(
    conversation_id="123456789",
    media_hash_key="abc123def456"
)
conversation_id
str
required
The Chat conversation ID.
media_hash_key
str
required
The media hash key returned from the upload initialize step.
MediaDownloadResponse
object
Response containing raw binary bytes with content type application/octet-stream.

Build docs developers (and LLMs) love