Reechdesk

HelpdeskProvider

Context provider that initializes the SDK, manages chat sessions, and connects to Pusher for real-time events.

Installation

bash
npm install @reechdesk/sdk@latest

Basic Usage

app/layout.tsxtsx
import { HelpdeskProvider } from '@reechdesk/sdk';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <HelpdeskProvider
          entityId="cashmatrix"
          user={{
            id: "user-123",
            name: "John Doe",
            email: "john@example.com",
          }}
        >
          {children}
        </HelpdeskProvider>
      </body>
    </html>
  );
}

Props

PropTypeDescription
entityId*stringThe slug of your entity (subsidiary). Found in Settings → Entities.
apiUrlstringBase URL of your Reechdesk instance. Auto-detected if omitted.
userHelpdeskUserAuthenticated user info. Enables personalized greeting and session tracking.
user.id*stringUnique user identifier.
user.name*stringDisplay name shown in agent dashboard.
user.email*stringUser email for notifications and session linking.
pusherKeystringPusher app key for real-time events. Required for chat.
children*ReactNodeChild components that consume the helpdesk context.

Using the Hook

Access the helpdesk context from any child component using useHelpdesk().

MyComponent.tsxtsx
import { useHelpdesk } from '@reechdesk/sdk';

function MyComponent() {
  const { entityId, apiUrl, user, sessionId, branding } = useHelpdesk();

  return (
    <div>
      <p>Entity: {branding.entityName}</p>
      <p>Session: {sessionId || 'No active session'}</p>
      {user && <p>Logged in as {user.name}</p>}
    </div>
  );
}

Context Value

FieldTypeDescription
entityIdstringThe resolved entity slug
apiUrlstringResolved API base URL
userHelpdeskUser | undefinedAuthenticated user info
sessionIdstring | nullActive chat session ID
setSessionId(id: string | null) => voidUpdate the active session
pusherPusherJS | nullConnected Pusher instance
brandingEntityBrandingEntity name, logo, and primary color

Resume from URL

The provider automatically detects ?chat=resume&id=xxx in the URL and restores the existing chat session.