Java chat
Chat for Java apps
TalkJS handles message storage and delivery for your Java app. For a Spring Boot or Jakarta EE web app, embed the chat UI in the browser and manage conversations from Java over REST. For an Android or desktop client, use the Java SDK to connect as the signed-in user.
// A new admin token for every REST call
private String adminToken() {
return JWT.create()
.withClaim("tokenType", "admin")
.withIssuer(appId)
.withExpiresAt(new Date(
System.currentTimeMillis() + 30_000))
.sign(hs256);
}


Which TalkJS piece goes in which Java process
Ask what the process is. If it’s one person in the chat, it gets the JVM package. If it manages everyone’s chat, it gets the REST API.
The TalkJS piece for each kind of Java process
| Java process | TalkJS piece | What it does there |
|---|---|---|
| Spring Boot or Jakarta EE backend | TalkJS pieceThe REST API, with a token signed by java-jwt or the JDK | What it does thereCreates users and conversations, sends messages, and reads history for every user. Signs the user token for the chat UI in your web pages. |
| Android app | TalkJS pieceThe Kotlin Data API, com.talkjs:core | What it does thereConnects as the signed-in user: their conversations, messages, and live updates. You build the screens. |
| Desktop client, or a service that acts as one person | TalkJS piececom.talkjs:core on the JVM, with Java 11+ and Kotlin 2.0+ | What it does thereThe same single-user view as on Android. You write this part in Kotlin. |
com.talkjs:core is on Maven Central (version 0.2.1 in November 2026). The Kotlin Data API docs cover setup.Whichever row you’re in, TalkJS stores the messages and delivers them in real time. It also sends email, SMS, and mobile push notifications to people who are offline (SMS is charged separately). Word filters and contact masking come on every plan. You don’t build any of that. Development mode is free, and after launch you pay per monthly active user.
The secret key trap in JJWT and Spring
TalkJS uses your secret key as plain text to check HS256 tokens. If your JJWT setup decodes the secret as Base64 first, a TalkJS key fails before any token is made:
Key size JJWT gets from one TalkJS secret key, in bits
WeakKeyExceptionDecodingException on _How each way of reading the key worked with a TalkJS secret key
| How the key is read | Result |
|---|---|
JJWT: Keys.hmacShaKeyFor(Decoders.BASE64.decode(secretKey)) | ResultDecodingException: Illegal base64 character: '_' |
JJWT: Keys.hmacShaKeyFor(Decoders.BASE64URL.decode(secretKey)) | ResultWeakKeyException: the key comes out as 240 bits, and JJWT needs at least 256 for HMAC-SHA |
JJWT: Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8)) | ResultToken accepted by the TalkJS REST API |
java-jwt: Algorithm.HMAC256(secretKey) | ResultToken accepted. It takes the string as it is. |
401 Unauthorized.The fix is one line. Read the key from the environment, never from frontend code, and pass its UTF-8 bytes:
String secretKey = System.getenv("TALKJS_SECRET_KEY");
SecretKey key = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8));
String token = Jwts.builder()
.claim("tokenType", "admin")
.issuer(appId)
.expiration(new Date(System.currentTimeMillis() + 30_000))
.signWith(key, Jwts.SIG.HS256)
.compact();A token per request, then plain HttpClient
Sign a new admin token for each REST request and let it expire in seconds. This class uses java-jwt, the library in the TalkJS REST API docs, and Java’s own HttpClient. Its main creates two users, a conversation between them, and a message:
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Date;
public class TalkJsClient {
private final String appId = System.getenv("TALKJS_APP_ID");
private final Algorithm hs256 = Algorithm.HMAC256(System.getenv("TALKJS_SECRET_KEY"));
private final HttpClient http = HttpClient.newHttpClient();
// A new admin token for every REST call, valid for 30 seconds
private String adminToken() {
return JWT.create()
.withClaim("tokenType", "admin")
.withIssuer(appId)
.withExpiresAt(new Date(System.currentTimeMillis() + 30_000))
.sign(hs256);
}
// The token your web page passes to the chat for one signed-in user
public String userToken(String userId) {
return JWT.create()
.withClaim("tokenType", "user")
.withIssuer(appId)
.withSubject(userId)
.withExpiresAt(new Date(System.currentTimeMillis() + 24 * 3600 * 1000))
.sign(hs256);
}
public int call(String method, String path, String json) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.talkjs.com/v1/" + appId + path))
.header("Authorization", "Bearer " + adminToken())
.header("Content-Type", "application/json")
.method(method, HttpRequest.BodyPublishers.ofString(json))
.build();
return http.send(request, HttpResponse.BodyHandlers.ofString()).statusCode();
}
public static void main(String[] args) throws Exception {
TalkJsClient talkjs = new TalkJsClient();
talkjs.call("PUT", "/users/alice", "{"name": "Alice"}");
talkjs.call("PUT", "/users/bob", "{"name": "Bob"}");
talkjs.call("PUT", "/conversations/order-1042",
"{"participants": ["alice", "bob"], "subject": "Order #1042"}");
int status = talkjs.call("POST", "/conversations/order-1042/messages",
"[{"text": "Your order has shipped.", "sender": "bob", "type": "UserMessage"}]");
System.out.println(status); // 200
}
}Add com.auth0:java-jwt to your Maven or Gradle build. That’s the only dependency: HttpClient is part of the JDK from Java 11. Want no dependency at all? javax.crypto.Mac with HmacSHA256 makes the same token, and TalkJS accepted ours.

main, in Alice’s chat. The page opened it with the token from userToken("alice"), November 2026.userToken signs the token for your web pages: the page passes it to the chat with session.setToken(token). Then turn on authentication in your dashboard, so the chat only connects users your server signed. Each app gets 9 REST calls a second, with bursts of 500.
We were able to offload all messaging to TalkJS — hugely simplifying our development of an otherwise complex stack.
Ready-made chat UI you can customize
The chat UI comes with three different layouts—that are highly customizable—which you can mix and match to suit your needs. You have complete control over the styling, the layout, and document structure of the chat messages and the possibility to show metadata.
The TalkJS Inbox shows the chat history on the left, selected conversation on the right. It's designed to act as the messaging center of your app, usually living on its own page.
The TalkJS Chatbox is the right half of the Inbox UI mode. It takes up less space and is designed to be embedded in your app near an order confirmation, a booking, or user profile.
You can also show a conversation in a popup that only shows up when the user clicks a button somewhere. When shown, the popup is positioned on the bottom right of your page.