Conversation models in the iOS SDK
Reference for the Conversation, Message, Source and Page types in the Askocto iOS SDK, with every field and enum case.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
These Swift types describe conversations and messages. They are plain structs that conform to Codable, Sendable and Hashable, and they match the objects of the REST API, so a field you see here has the same meaning in the conversation endpoints.
Conversation
public struct Conversation: Identifiable, Codable, Hashable, Sendable {
public let id: String
public let agentId: String
public let userId: String?
public let channel: String
public let status: ConversationStatus
public let messageCount: Int
public let createdAt: Date
public let updatedAt: Date
}
| Field | Description |
|---|---|
id |
Conversation id, starting conv_. |
agentId |
The agent that handled it, starting agt_. |
userId |
The customer id, starting usr_. nil for anonymous visitors. |
channel |
Where it happened. Conversations started by the SDK use the app channel. |
status |
A ConversationStatus value. |
messageCount |
Number of messages so far. |
createdAt, updatedAt |
Dates parsed from ISO 8601 UTC strings. |
ConversationStatus has three cases: .open, .resolved and .handoff. They correspond to open, resolved and handoff in the API.
Message
public struct Message: Identifiable, Codable, Hashable, Sendable {
public let id: String
public let role: Role
public let content: String
public let sources: [Source]
public let createdAt: Date
public enum Role: String, Codable, Sendable { case user, assistant }
}
| Field | Description |
|---|---|
id |
Message id, starting msg_. |
role |
.user for the customer, .assistant for the agent. |
content |
The message text. |
sources |
The sources the agent used. Empty for user messages. |
createdAt |
When the message was created. |
Because both types are Identifiable, you can pass them straight to a SwiftUI List or ForEach. When a human teammate replies after a handoff, that message arrives with the .assistant role, so your UI does not need a separate case for it.
Source and Page
public struct Source: Identifiable, Codable, Hashable, Sendable {
public let id: String
public let title: String
}
public struct Page<Element: Codable & Sendable>: Codable, Sendable {
public let data: [Element]
public let nextCursor: String?
}
Page wraps every list the SDK returns. data holds the items and nextCursor is nil on the last page. It is generic, so conversations returns a page of Conversation and messages returns a page of Message.
Note: Models are immutable. To show a message that is still arriving, build your own view state from
StreamEventvalues instead of editing aMessage. See Streaming events.
Related pages
- Conversations shows how to load these types.
- Chat response shows where a
Messageappears in a reply.