JavaScript Chat SDK
Use the isomorphic chat client without React.
- Last reviewed
JavaScript Chat SDK
Use the JavaScript Chat SDK when you want the chat client without React. It
works in browsers, React Native, and server-side proxy code with fetch.
How authentication works
Chat requests always use a JWT bearer token created by your app.
Before you create the client, configure your backend or auth provider to mint a JWT for the signed-in user. That token must be intended for your getuserfeedback.com app:
aud: https://getuserfeedback.com/v1/apps/{appId}sub: the stable identity for this user in your appThe default setup uses sub as the user's stable app identity. If your
getuserfeedback.com app uses a custom JWT claim mapping, configure one primary
signed claim for chat, such as your app user id, account id, or another
customer-owned identity value.
Your app should fetch that token from your own auth flow, then pass it to the client. The SDK sends the token on each API request:
Authorization: Bearer <token>getuserfeedback.com verifies the token and uses the signed app identity to decide which conversations to return. See User authentication for issuer, JWKS, audience, and claim setup.
1. Install
npm install @getuserfeedback/chat2. Create the client
import { createChatClient } from "@getuserfeedback/chat";export const chat = createChatClient({auth: {jwt: {token: await fetchGetUserFeedbackChatToken(),},},});Refresh the token when your auth provider rotates it:
await chat.configure({auth: {jwt: {token: await fetchGetUserFeedbackChatToken(),},},});Clear auth on logout:
await chat.configure({auth: {jwt: null,},});The default API base URL is https://api.getuserfeedback.com/v1.
If you proxy requests through your backend, pass your own absolute baseUrl:
const chat = createChatClient({baseUrl: "https://app.example.com/api/chat/v1",auth: {jwt: {token: await fetchAppSessionToken(),},},});Custom baseUrl values are used exactly, including any path prefix.
Your backend should authenticate that app session token, then call
getuserfeedback.com with a JWT minted for your getuserfeedback.com app and
that user.
3. List conversations
const { conversations, nextCursor } = await chat.conversations.list({limit: 25,});Load the next page with the returned cursor:
if (nextCursor) {const nextPage = await chat.conversations.list({cursor: nextCursor,limit: 25,});}4. List messages
const { messages, nextCursor } = await chat.messages.list({conversationId: conversations[0].id,limit: 50,});5. Send a message
const { message } = await chat.messages.send({conversationId: conversations[0].id,text: "Hello from my app.",});Handle errors
Failed API responses throw ChatApiError.
import { ChatApiError } from "@getuserfeedback/chat";try {await chat.conversations.list();} catch (error) {if (error instanceof ChatApiError) {console.log(error.status, error.code, error.message);}}Next
- Chat SDK reference — full client and hook surface
- React Chat SDK — add headless React hooks