Skip to main content

Sending messages

Make your application send messages to specific conversations.

The conversation identifier is required. You can get it from:

val conversationId = QualifiedId(
id = UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
domain = "example.com"
)

Text message

val textMessage = WireMessage.Text.create(
conversationId = conversationId,
text = "Hello world!"
)
val applicationManager = wireAppSdk.getApplicationManager()

applicationManager.sendMessageSuspending(textMessage)

Asset message

Upload and send an asset (file) to a conversation.

note

When sending an asset message, you need to provide the file, name and mime type, while we take care of the encryption and metadata based on mime type.

// Get local file from resources
val filename = "my-file.png"
val resourcePath = javaClass.classLoader.getResource(filename)?.path
?: throw IllegalStateException("Resource '$filename' not found")
val asset = File(resourcePath)

// Read File data in ByteArray
val originalData = asset.readBytes()

// Send File with necessary parameters
applicationManager.sendAssetSuspending(
conversationId = conversationId,
asset = AssetResource(originalData),
name = asset.name,
mimeType = "image/png",
retention = AssetRetention.ETERNAL
)

Composite message

Composite messages are a combination of text and buttons in a single message.

note

Only Apps can create Composite messages. End clients can receive and display them, but cannot send them.

A WireMessage.Composite object has Base properties and includes a list of Item objects.

Each Item can be one of the following:

  • WireMessage.Text — A text element. See how to create one.
  • WireMessage.Button — An interactive element that lets users perform an action. Each button includes:
    • text — the label shown on the button.
    • id — a unique identifier for the button, automatically generated unless specified.

Composite message on desktop

composite on desktop

val compositeMessage = WireMessage.Composite.create(
conversationId = conversationId,
text = "What's the best JVM language?",
buttonList = listOf(
WireMessage.Button(text = "Java"),
WireMessage.Button(text = "Kotlin")
)
)

applicationManager.sendMessageSuspending(compositeMessage)