MessageEvent

data class MessageEvent(val conversationId: String, val status: MessageStatus, val fromUserId: String? = null, val toUserId: String? = null, val title: String? = null, val message: Message? = null, val content: String? = null, val role: MessageRole? = null, val error: Throwable? = null, val timestamp: Instant = Instant.now())

Event published for message lifecycle changes in a conversation.

Status Flow

Conversation TypeEvents Fired
In-memoryADDED
PersistentADDEDPERSISTED or PERSISTENCE_FAILED

Usage

@EventListener
fun onMessage(event: MessageEvent) {
when (event.status) {
MessageStatus.ADDED -> {
// Message appeared in conversation - show in UI
}
MessageStatus.PERSISTED -> {
// Message saved - can update UI indicator
}
MessageStatus.PERSISTENCE_FAILED -> {
// Handle failure - event.error has details
}
}
}

// Or filter to specific status:
@EventListener(condition = "#event.status.name() == 'ADDED'")
fun onMessageAdded(event: MessageEvent) { ... }

Parameters

conversationId

the conversation the message belongs to

status

the current status of the message

fromUserId

the ID of the user who sent this message (author)

toUserId

the ID of the user who should receive this message (for routing, e.g., WebSocket)

title

the session/conversation title (for UI display)

message

the message (always present for ADDED, present for PERSISTED)

content

the message content (useful for PERSISTENCE_FAILED when message ref may be stale)

role

the message role

error

the exception if persistence failed (present for PERSISTENCE_FAILED)

timestamp

when the event occurred

Constructors

Link copied to clipboard
constructor(conversationId: String, status: MessageStatus, fromUserId: String? = null, toUserId: String? = null, title: String? = null, message: Message? = null, content: String? = null, role: MessageRole? = null, error: Throwable? = null, timestamp: Instant = Instant.now())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val content: String? = null
Link copied to clipboard
Link copied to clipboard
val error: Throwable? = null
Link copied to clipboard
val fromUserId: String? = null
Link copied to clipboard
val message: Message? = null
Link copied to clipboard
val role: MessageRole? = null
Link copied to clipboard
Link copied to clipboard
open val timestamp: Instant
Link copied to clipboard
val title: String? = null
Link copied to clipboard
val toUserId: String? = null