An open API service indexing awesome lists of open source software.

https://github.com/daniel-sc/rocketchat-modern-client

Client SDK for https://rocket.chat employing reactive style.
https://github.com/daniel-sc/rocketchat-modern-client

reactive rocketchat rocketchat-modern-client

Last synced: over 1 year ago
JSON representation

Client SDK for https://rocket.chat employing reactive style.

Awesome Lists containing this project

README

          

[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)

# Deprecated / Unmaintained
This project does not work with version 7.x of Rocket Chat (https://github.com/daniel-sc/rocketchat-modern-client/issues/32).

The author of this package has no time to maintain this package - so if you are interested, please fork or provide PRs :)

# Rocketchat modern client

![CI](https://github.com/daniel-sc/rocketchat-modern-client/actions/workflows/build-and-test.yaml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/daniel-sc/rocketchat-modern-client/badge.svg?branch=master)](https://coveralls.io/github/daniel-sc/rocketchat-modern-client?branch=master)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.daniel-sc/rocketchat-modern-client?color=green)](https://mvnrepository.com/artifact/com.github.daniel-sc/rocketchat-modern-client)

This project aims to provide a simple java client for the [Rocket.Chat](https://rocket.chat) live chat api.
The current focus is on ease of usability and solid core functionality over complete method coverage (PRs always welcome!).

## Read first
Make sure you have at least some rough understanding of [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html)
and [RxJava](https://github.com/ReactiveX/RxJava) as these are used heavily for the client api.

## Setup
Just include the client as Maven dependency in your `pom.xml` via:

```xml

com.github.daniel-sc
rocketchat-modern-client
1.3.1

```

## Usage

Get subscriptions/rooms:
```java
try(RocketChatClient client = new RocketChatClient("wss://open.rocket.chat:443/websocket", new LoginParam(USERNAME, PASSWORD))) {
List subscriptions = client.getSubscriptions().join();
}
```

Send message:
```java
try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
ChatMessage msg = client.sendMessage("Your message", roomId).join();
}
```

Send message with alias and avatar:
```java
try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
ChatMessage msg = client.sendMessageExtendedParams("Your message", roomId, "Alias", "https://goo.gl/8afu6d", null, null, null).join();
}
```

Send message with alias and emoji:
```java
try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
ChatMessage msg = client.sendMessageExtendedParams("Your message", roomId, "Alias", null, ":e-mail:", null, null).join();
}
```

_If you send both avatar and emoji, rocket chat client show only avatar._
```
ChatMessage msg = client.sendMessageExtendedParams("Your message", roomId, "Alias", "https://goo.gl/8afu6d", ":e-mail:", null, null).join();
```

Update message:
```java
try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
ChatMessage chatMessage = client.sendMessage("Your message", roomId).join();
String edited = "~" + chatMessage.msg + "~"; // strikethrough original message
new Scanner(System.in).nextLine(); // Wait ...
ChatMessage editedMessage = client.updateMessage(edited, chatMessage._id).join();
}
```

Stream/read messages:
```java
try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
Observable msgStream = client.streamRoomMessages(roomId).join();
msgStream.forEach(msg -> System.out.println("received msg: " + msg));
// block thread until you got enough messages.. (or don't use try-with and close client explicitly)
msgStream.dispose();
}
```

Send message with _Attachments_ and _Attachment Fields_:
```java
try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
List attachments = new ArrayList();

Attachment a1 = new Attachment();
a1.color = "#0000ff";
a1.iso8601Date = "2001-02-03T04:05:06.789Z";
a1.text = "Test attachment message\nand next **line** ~~with~~ **mark-down** formatting\n:-) ...";
a1.authorName = "author";
a1.authorIcon = "https://avatars2.githubusercontent.com/u/0?s=400&v=4";
a1.authorLink = "https://github.com/";
a1.title = "Attachment test A1";
a1.titleLink = "https://www.google.com/?q=Attachment%20test%20A1";
attachments.add(a1);

Attachment a2 = new Attachment();
a2.imageUrl = "https://cdn3.iconfinder.com/data/icons/iconshock_developer/linux.png";
attachments.add(a2);

Attachment a3 = new Attachment();
a3.color = "#00FF00";
a3.title = "Project status";
List attachmentFields = new ArrayList<>();
attachmentFields.add(new AttachmentField(true, "Status", "New"));
attachmentFields.add(new AttachmentField(true, "Priority", "High"));
attachmentFields.add(new AttachmentField(true, "Tags", "Test, Chat"));
a3.fields = attachmentFields;
attachments.add(a3);
ChatMessage msg = client.sendMessageExtendedParams(message, roomId, rcAlias, rcAvatar, rcEmoji, null, attachments).join();
}
```
![Message with Attachments and Attachment Fields](img/message_attachments.png)

## Websocket API
This client ships with [Tyrus](https://github.com/tyrus-project/tyrus)
websocket reference implementation.

If you like, you can replace the websocket library with any
other JSR-356 compliant implementation of [WebSocket Server API](https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api).
Just update your `pom.xml` as follows:
```xml

com.github.daniel-sc
rocketchat-modern-client
0.1.0


org.glassfish.tyrus.bundles
tyrus-standalone-client-jdk

some.websocket-api.impl
some.websocket-api.impl
VERSION

```

## Run integration tests
```bash
mvn clean install -Pintegration-test
```