im.chats creates and manages iMessage conversations. A chat can be a direct conversation or a group conversation.
Most chat methods identify the conversation by chat.guid. The exceptions are create(...), which takes email addresses or phone numbers and returns chat.guid, and count(...), which does not take a chat argument.
For group names, participants, group icons, and leaving a group, use groups.
What You Can Do
Chat GUIDs
A chat GUID is the server identifier for a conversation:
In normal code, do not hand-write GUIDs. Use the
chat.guid returned by im.chats.create(...), im.chats.get(...), message results, or event payloads.
Create a Chat
One address creates a direct chat. Two or more addresses create a group chat:CreateChatResult:
The server normalizes addresses and rejects short codes, service numbers, invalid email addresses, and duplicate recipients.
effect only applies when options.message is present. It is not a chat property. For more complex sends, such as formatting or replies, create the chat first and then use the messages API.
clientMessageId is only needed when your job system might retry the same write after a crash or timeout. Most direct calls can omit it. See error handling for details.Get a Chat
Chat:
get(...) throws NotFoundError when the chat does not exist or cannot be resolved.
Count Chats
By default, archived chats are excluded:includeArchived: true:
number.
Read and Typing State
Mark Read
void. Calling it again when the chat has no unread messages is safe.
Typing Indicator
Show typing:void. Typing is temporary UI state. It is not written to the durable event log and cannot be caught up after a disconnect.
Contact Card
void. The contact card comes from the Mac running the service. The SDK cannot choose which fields are included.
Chat Backgrounds
Chat backgrounds use raw image bytes. They are not attachment GUIDs, and you do not upload them throughim.attachments first.
Set a Background
void. data must not be empty. The server detects the image type from the bytes. JPEG, PNG, HEIC, and HEIF are supported.
After setBackground(...) succeeds, the background usually syncs to other participants’ devices within 30s. The image is uploaded to iCloud and then distributed to the conversation. This is not a hard SLA: network state, iCloud state, and the Messages client state all affect when the background appears.
Common reasons the background UI may not appear:
The last case is a Messages display rule, not an SDK option. If one group member never sees the background, it is usually more effective for that member to send a message, mark the sender as known, or reopen Messages than to call
setBackground(...) repeatedly.Check Background State
boolean.
Remove a Background
void. Removing a background is safe to repeat, even when no custom background is set.
Chat Events
subscribeEvents(...) returns TypedEventStream<ChatEvent>. Use the stream to observe changes made by other people, other devices, or another part of your system. Immediately after your code calls a write method, use that method’s return value or completion status.
Scope
Only one chat:Event Shape
Every chat event has the same outer fields:Event Types
Handle Events
event.chatGuid to identify the chat:
Next Steps
- Messages — send, read, edit, and unsend messages with
chat.guid - Groups — manage group names, participants, group icons, and leaving
- Events — catch up on durable events after a disconnect
- Error Handling — handle
NotFoundError,ValidationError, and idempotent retries