Skip to main content

Quickstart

In this guide you will create a basic App that can echo to received messages.


1. Creating an App

First, create an app in Team Management if you don’t have one yet.
Create app

2. Include the SDK into your project

dependencies {
implementation("com.wire:wire-apps-jvm-sdk:0.0.1")
}

3. Initiate the SDK

Handling Events

The SDK uses the WireEventsHandler to notify your application about events and messages. Override the methods that you need in this class to handle them however you want. The http connection, deserialization, authentication and decrypting are performed by the Application, so you will receive the event as a WireMessage

Here's a complete example showing how to initialize the SDK and handle received events:

fun main() {
val wireAppSdk = WireAppSdk(
applicationId = UUID.fromString("YOUR_APPLICATION_ID"),
apiToken = "YOUR_API_TOKEN",
apiHost = "YOUR_API_HOST",
cryptographyStoragePassword = "YOUR_32_CHAR_STORAGE_PASSWORD",
object : WireEventsHandlerSuspending() {
override suspend fun onTextMessageReceived(wireMessage: WireMessage.Text) {
println("Text message received: $wireMessage")

// Add your message handling logic here, like storing the message,
// sending back another message, or triggering some workflow
}
}
)

// Start the SDK
wireAppSdk.startListening()
}

For simplicity the subclassing of WireEventsHandler is done inline as an anonymous class, but you can create a separate class for it, especially if you handle events in a complex way:

class MyWireEventsHandler : WireEventsHandlerSuspending() {
private val logger = LoggerFactory.getLogger(MyWireEventsHandler::class.java)

override suspend fun onTextMessageReceived(wireMessage: WireMessage.Text) {
logger.info("Text message received: $wireMessage")
}
}

4. Echoing a received message

In your onTextMessageReceived implementation from MyWireEventsHandler you can echo a message as:

override suspend fun onTextMessageReceived(wireMessage: WireMessage.Text) {
val message = WireMessage.Text.createReply(
conversationId = wireMessage.conversationId,
text = "${wireMessage.text} -- Sent from the SDK",
mentions = wireMessage.mentions,
originalMessage = wireMessage
)

// The manager is accessible through the inherited WireEventsHandler class.
// It is used to manage the Wire application's lifecycle and communication with the backend.
manager.sendMessageSuspending(message = message)
}

5. Conclusion

With this basic setup you now have a running Echo App.

You can check other events in Wire Events