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 identity verification works
With the default Chat API, requests 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:
protected alg: the asymmetric signing algorithm selected in Widget settingsprotected typ: gx-widget+jwtaud: copy the Audience shown in Widget settingssub: the stable identity for this user in your appexp: the token expiration time as a Unix timestampThe 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 Identity verification for issuer, JWKS, signing algorithm, token type, audience, and claim setup.
With a custom baseUrl, the token is the bearer credential your backend
expects. Your backend authenticates it, then calls getuserfeedback.com with a
JWT that follows the profile above.
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 fetchBackendBearerCredential(),},},});Custom baseUrl values are used exactly, including any path prefix.
Your backend should authenticate that bearer credential, 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