# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
