# iMessage Java & Kotlin SDK

> Blooio’s official JVM SDK for sending and receiving iMessages from Java, Kotlin, Spring Boot, and Android applications.

Source: https://blooio.com/integrations/api/imessage-java-sdk

## Summary

The Blooio Java SDK is a typed client for the Blooio REST API. It is published to Maven Central and supports Java 17+, Kotlin, fluent request builders, Jackson-based models, webhook verification, and automatic retries.

## Highlights

- Published to Maven Central for Gradle, Maven, or sbt
- Supports Java 17+ and Kotlin 1.9+
- Android compatible
- Fluent builders for request objects
- Jackson-based models and typed webhook payload deserialization
- Spring Boot–ready webhook verification
- Automatic retries for HTTP 429 and 5xx responses with exponential backoff
- Open source under the MIT License

## Installation

### Gradle Kotlin DSL

```kotlin
dependencies {
    implementation("com.blooio:blooio-sdk:latest.release")
}
```

### Maven

```xml
<dependency>
    <groupId>com.blooio</groupId>
    <artifactId>blooio-sdk</artifactId>
    <version>LATEST</version>
</dependency>
```

The SDK is available from Maven Central; no custom repository is required.

## Send an iMessage

Set `BLOOIO_API_KEY` in the trusted environment where the application runs, create a client, and call the chats API.

```java
import com.blooio.Blooio;
import com.blooio.model.SendMessageRequest;

public class Sender {
    public static void main(String[] args) throws Exception {
        Blooio blooio = Blooio.builder()
            .apiKey(System.getenv("BLOOIO_API_KEY"))
            .build();

        blooio.chats().sendMessage(SendMessageRequest.builder()
            .phone("+15551234567")
            .body("Hey Alex — thanks for booking a demo. Reply with any questions.")
            .build());
    }
}
```

## Verify Webhooks in Spring Boot

Use `WebhookVerifier` with the webhook secret to validate the `X-Blooio-Signature` header. Verification returns a typed `BlooioEvent`; an invalid signature throws `InvalidSignatureException`.

```java
@RestController
@RequestMapping("/webhooks")
public class BlooioWebhookController {

    private final WebhookVerifier verifier =
        new WebhookVerifier(System.getenv("BLOOIO_WEBHOOK_SECRET"));

    @PostMapping(value = "/blooio", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Void> handle(
        @RequestHeader("X-Blooio-Signature") String signature,
        @RequestBody byte[] body
    ) {
        try {
            BlooioEvent event = verifier.verify(body, signature);
            if ("message.received".equals(event.type())) {
                MessageReceived data = event.dataAs(MessageReceived.class);
                log.info("inbound iMessage: {}", data.body());
            }
        } catch (InvalidSignatureException e) {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
        }
        return ResponseEntity.ok().build();
    }
}
```

## Kotlin and Android Support

The SDK is written in Java and interoperates with Kotlin. Kotlin-specific coroutine helpers are available in the companion `blooio-sdk-kotlin` artifact.

The SDK targets Java 17 bytecode and has no Android-incompatible dependencies. It can be used from native Android applications or React Native modules that call into the JVM.

Keep API keys on trusted backends rather than distributing them in client applications.

## Requirements

| Component | Requirement |
|---|---|
| Java | Java 17 or later |
| Kotlin | Kotlin 1.9 or later |
| Package source | Maven Central |
| API key in example | `BLOOIO_API_KEY` |
| Webhook secret in example | `BLOOIO_WEBHOOK_SECRET` |

## Links

- HTML page: https://blooio.com/integrations/api/imessage-java-sdk
- Java SDK repository: https://github.com/Blooio/blooio-java-sdk
- REST API integration: https://blooio.com/integrations/api.md
- All integrations: https://blooio.com/integrations.md
- Pricing: https://blooio.com/pricing.md
- LLM site index: https://blooio.com/llms.txt
