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
)

Text message with mentions

Mentions allow you to tag users in a message. The Mention object requires the user's QualifiedId, and the offset and length indicating where the mention appears in the text.

val mention = WireMessage.Mention(
userId = targetUserId,
offset = 0, // Position in text where mention starts
length = 5 // Length of the mention text including '@' character
)

val textMessage = WireMessage.Text.create(
conversationId = conversationId,
text = "@John check this out!",
mentions = listOf(mention)
)

applicationManager.sendMessageSuspending(textMessage)

Reply message

Reply to an existing message by referencing the original message. The original message must implement the Replyable interface (Text, Asset, or Location messages).

A Reply is a special case of Text.

val replyMessage = WireMessage.Text.createReply(
conversationId = conversationId,
text = "This is my reply!",
originalMessage = originalMessage // The message you're replying to
)

applicationManager.sendMessageSuspending(replyMessage)

Ephemeral message

Ephemeral messages automatically expire after a specified duration. The expiresAfterMillis parameter defines the lifetime in milliseconds.

Only message of type Asset, Location, Ping, and Text can be Ephemeral.

val ephemeralMessage = WireMessage.Text.create(
conversationId = conversationId,
text = "This message will self-destruct!",
expiresAfterMillis = 30_000L // Expires after 30 seconds
)

applicationManager.sendMessageSuspending(ephemeralMessage)

Reaction

Send emoji reactions to existing messages. The emojiSet contains the emojis to react with. Send an empty set to remove all reactions.

Techninally you can send any UTF-8 String as a Reaction, but other clients only use it with emojis.

val reaction = WireMessage.Reaction.create(
conversationId = conversationId,
messageId = targetMessageId.toString(),
emojiSet = setOf("👍", "❤️")
)

applicationManager.sendMessageSuspending(reaction)

Edit message

Edit a previously sent text message by referencing its ID.

note

Each time a message is edited, its ID changes. Therefore it cannot be edited sequentially referencing same ID.

val editedMessage = WireMessage.TextEdited.create(
replacingMessageId = originalMessageId,
conversationId = conversationId,
text = "This is the corrected text"
)

applicationManager.sendMessageSuspending(editedMessage)

Delete message

Delete a previously sent message by referencing its ID.

val deleteMessage = WireMessage.Deleted.create(
conversationId = conversationId,
messageId = originalMessageId
)

applicationManager.sendMessageSuspending(deleteMessage)

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)