For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.
Skip to content

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);
}
Dev A
Hey, I'm trying to lift state up from a child component, but I'm getting undefined errors. Any ideas?
8m ago
You
Are you passing the state and the setState function correctly as props?
6m ago
Dev A
I think so, yes.
5m ago
ok-hand
thinking
You
Maybe you're not binding the handler in the constructor. That might be the issue.
2m ago
Dev A
typing...
just now
Write a reply...
You
Hey, I’m having trouble accessing my account. It says my password is incorrect.
5m ago
SupportBot
Hi there! No problem — let’s get that sorted. Have you tried resetting your password using the 'Forgot password?' link?
4m ago
thinking
thumbs-up
You
Yes, but I haven’t received the reset email yet.
3m ago
SupportBot
Thanks for confirming. I’ve just sent a new reset link to your email. Please check your inbox and spam folder.
2m ago
SupportBot
Is there anything else I can help you with?
just now
Got it — checking my inbox now!

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 processTalkJS pieceWhat it does there
Spring Boot or Jakarta EE backendTalkJS pieceThe REST API, with a token signed by java-jwt or the JDKWhat 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 appTalkJS pieceThe Kotlin Data API, com.talkjs:coreWhat 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 personTalkJS 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

Read as UTF-8 bytes320 bits, against JJWT's minimum of 256320 bits: accepted
Decoded as Base64URL240 bits, against JJWT's minimum of 256240 bits: WeakKeyException
Decoded as Base64No key: decoding failedNo key: DecodingException on _
0128256384
The dashed line is JJWT’s minimum for HMAC keys, 256 bits. Our 40-character test key is 320 bits read as UTF-8 and 240 bits decoded as Base64URL.

How each way of reading the key worked with a TalkJS secret key

How the key is readResult
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.
Run on JDK 25.0.5 with JJWT 0.13.0 and java-jwt 4.6.2 against a TalkJS test project, November 16, 2026. A token signed with the wrong key gets 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.

A TalkJS chatbox titled Order #1042 with Bob, showing his message: Your order has shipped.
The message from 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.

Classtime
Decathlon
Riot Games
Hyundai
Retreat Guru logo
We were able to offload all messaging to TalkJS — hugely simplifying our development of an otherwise complex stack.
Deryk Wenaus
CTO, Retreat Guru

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.

Inbox

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.

Chatbox

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.

Popup

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.

FAQs

No. It connects as one user and sees only that user’s conversations. To create accounts or export every user’s messages, call the REST API from your server.

Your config decodes the key as Base64URL. That turned our 40-character test key into 240 bits, under JJWT’s 256-bit minimum. Pass secretKey.getBytes(StandardCharsets.UTF_8) to Keys.hmacShaKeyFor instead.

Yes, with the Kotlin Data API. It gives you the user’s conversations, messages and live updates, and you draw the chat in Swing or JavaFX.

Yes. TalkJS can send webhooks, such as a message.sent event, to an endpoint on your server, and your code can answer through the REST API.