> For the complete documentation index, see [llms.txt](https://sending-network.gitbook.io/sending.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sending-network.gitbook.io/sending.network/sdk-documentation/java-sdk.md).

# Java SDK

The Java Bot SDK empowers developers with the capability to manage chats and send/receive messages.

## Install

### Add dependency

```groovy
repositories {
    maven {
        url 'https://s01.oss.sonatype.org/content/repositories/releases/'
    }
}

dependencies {
    implementation 'io.github.sending-network:sdn-sdk-java:0.1.0'
}
```

### Prepare a configuration file

{% hint style="info" %}
Use <https://portal0101.sending.network/> as the public endpoint.&#x20;
{% endhint %}

Provide P2P node `endpoint`, `wallet address`*,* and `private key` in *config.yam*l:

```yaml
endpoint: ""
wallet_address: ""
private_key: ""
```

### Create `Client` Instance

Once the configuration file has been read, create a `Client` instance, register the event listener, and initiate the syncing process.

```java
import org.yaml.snakeyaml.Yaml;
import com.sending.sdk.Client;

Map<String, Object> config = new Yaml().load(new BufferedReader(new FileReader(configFile)));
Client client = new Client((String)config.get("endpoint"));
client.loginDID((String)config.get("wallet_address"), (String)config.get("private_key"));

client.registerRoomEventListener(roomEvents -> {
    // process room events
    roomEvents.forEach(System.out::println);
});
client.startSync();
```

### Call API functions

```java
// create new room
String roomId = client.createRoom(roomName, "", null, System.out::println);

// invite user to the room
String userId = ""
client.inviteUser(roomId, userId, null);

// send room message
String eventId = client.sendMessage(roomId, "hello");

// logout to invalidate access token
client.logout()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sending-network.gitbook.io/sending.network/sdk-documentation/java-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
