daniel-sc/rocketchat-modern-client


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

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.daniel-sc:rocketchat-modern-client:rocketchat-modern-client-1.3.2'
	}
	dependencies {
		implementation("com.github.daniel-sc:rocketchat-modern-client:rocketchat-modern-client-1.3.2")
	}
	<dependency>
	    <groupId>com.github.daniel-sc</groupId>
	    <artifactId>rocketchat-modern-client</artifactId>
	    <version>rocketchat-modern-client-1.3.2</version>
	</dependency>

                            
    libraryDependencies += "com.github.daniel-sc" % "rocketchat-modern-client" % "rocketchat-modern-client-1.3.2"
        
        

                            
    :dependencies [[com.github.daniel-sc/rocketchat-modern-client "rocketchat-modern-client-1.3.2"]]
        
        

Readme


No Maintenance Intended

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 Coverage Status Maven Central

This project aims to provide a simple java client for the 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 and RxJava as these are used heavily for the client api.

Setup

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

<dependency>
    <groupId>com.github.daniel-sc</groupId>
    <artifactId>rocketchat-modern-client</artifactId>
    <version>1.3.1</version>
</dependency>

Usage

Get subscriptions/rooms:

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

Send message:

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

Send message with alias and avatar:

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:

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:

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:

try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
    Observable<ChatMessage> 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:

try(RocketChatClient client = new RocketChatClient(URL, new LoginParam(USERNAME, PASSWORD))) {
    List<Attachment> attachments = new ArrayList<Attachment>();

    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<AttachmentField> 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

Websocket API

This client ships with Tyrus websocket reference implementation.

If you like, you can replace the websocket library with any other JSR-356 compliant implementation of WebSocket Server API. Just update your pom.xml as follows:

<dependency>
    <groupId>com.github.daniel-sc</groupId>
    <artifactId>rocketchat-modern-client</artifactId>
    <version>0.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.glassfish.tyrus.bundles</groupId>
            <artifactId>tyrus-standalone-client-jdk</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>some.websocket-api.impl</groupId>
    <artifactId>some.websocket-api.impl</artifactId>
    <version>VERSION</version>
</dependency>

Run integration tests

mvn clean install -Pintegration-test