Skip to main content

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:

NameDescription
sizeInBytesFile size in bytes.
nameOriginal file name, if available.
mimeTypeFile’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

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)
}
}