onAssetMessageReceived
Triggers when a new asset (such as an image, video, or audio file) arrives in a conversation.
Use it to handle, store, or process received media.
Received properties
Apart from Base, Ephemeral, and Replyable properties,
a WireMessage.Asset object contains the following fields:
| Name | Description |
|---|---|
sizeInBytes | File size in bytes. |
name | Original file name, if available. |
mimeType | File’s MIME type. Determines supported asset category (image, audio, video). |
metadata
Each asset type includes additional metadata:
- Image – width and height in pixels.
- Video – width, height, and duration in milliseconds.
- Audio – duration and normalized loudness.
remoteData
Data needed to download and decrypt the asset.
Receiving an onAsset event does not mean you have received the file itself.
The asset must be downloaded separately using the remoteData field.
You can pass the AssetRemoteData object directly to the downloadAsset/downloadAssetSuspending method to retrieve the asset as a byte array.
Sample usage
Download received asset
- Kotlin
override suspend fun onAssetMessageReceived(wireMessage: WireMessage.Asset) {
wireMessage.remoteData?.let { remoteData ->
val asset = manager.downloadAssetSuspending(remoteData)
val fileName = wireMessage.name ?: "unknown"
val outputDir = File("build/downloaded_assets").apply { mkdirs() }
val outputFile = File(outputDir, fileName)
outputFile.writeBytes(asset.value)
}
}