HelpdeskProvider
Context provider that initializes the SDK, manages chat sessions, and connects to Pusher for real-time events.
Installation
bash
npm install @reechdesk/sdk@latestBasic 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
| Prop | Type | Description |
|---|---|---|
| entityId* | string | The slug of your entity (subsidiary). Found in Settings → Entities. |
| apiUrl | string | Base URL of your Reechdesk instance. Auto-detected if omitted. |
| user | HelpdeskUser | Authenticated user info. Enables personalized greeting and session tracking. |
| user.id* | string | Unique user identifier. |
| user.name* | string | Display name shown in agent dashboard. |
| user.email* | string | User email for notifications and session linking. |
| pusherKey | string | Pusher app key for real-time events. Required for chat. |
| children* | ReactNode | Child 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
| Field | Type | Description |
|---|---|---|
| entityId | string | The resolved entity slug |
| apiUrl | string | Resolved API base URL |
| user | HelpdeskUser | undefined | Authenticated user info |
| sessionId | string | null | Active chat session ID |
| setSessionId | (id: string | null) => void | Update the active session |
| pusher | PusherJS | null | Connected Pusher instance |
| branding | EntityBranding | Entity 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.