React SDK Guide
Learn how to use Nextiva's React SDK
Overview
This guide shows how to integrate the NCX React SDK into your application and make full use of its hooks for voice, messaging, and supervisory features.
Installation
Install the React SDK package and its peer dependencies. For full instructions, refer to the SDK Installation Guide.
Wrap your app in the provider
The NcxSdkProvider uses React’s Context API to expose the SDK instance throughout your app. First, create a new instance of the SDK, then pass it to the provider at the root of your application.
import { Nextiva, NcxSdkProvider } from '@nextiva/ncx-react-sdk';
const sdk = new Nextiva();
<NcxSdkProvider ncxSdk={ sdk }>
<App />
<NcxSdkProvider>Access the SDK
Use the useNcxSdk() hook to access the SDK instance in any component.
const sdk = useNcxSdk();
const makeACall =() => {
sdk.getUserService().dial({ number: '1234567890' });
};Hooks overview
The SDK provides event hooks and state hooks to integrate seamlessly with your React component lifecycle.
What are hooks?
Hooks allow your React components to subscribe to SDK data, react to real-time events, or access local session state. Event hooks use RxJS under the hood to emit updates. State hooks expose local values managed within the SDK.
Event hooks
Event hooks respond to real-time events emitted by the SDK, like incoming calls, ticket updates, and workitem changes.
All event hooks are built on top of the base useSubscription{(...)} hook. These hooks do not store nor return local state. Instead, they execute callbacks when events occur.
Events
List of events
| Event name | Value |
|---|---|
| ACDSessionChangeNotification | ACDSessionChangeNotification |
| AISummaryNotification | AISummaryNotification |
| AuthenticationSuccess | AuthenticationSuccess |
| CallRecordingNotification | CallRecordingNotification |
| CampaignTotalsNotification | CampaignTotalsNotification |
| CampaignsChangedNotification | CampaignsChangedNotification |
| ChangeStatusNotification | ChangeStatusNotification |
| CompanyDirectoryNotification | CompanyDirectoryNotification |
| ConferenceStateNotification | ConferenceStateNotification |
| ContactImportFailureNotificationEvent | ContactImportFailureNotificationEvent |
| ContactImportNotificationEvent | ContactImportNotificationEvent |
| ConversationStatusEvent | ConversationStatusEvent |
| DynamicChangeNotification | DynamicChangeNotification |
| EngagementDataStatusUpdateNotification | EngagementDataStatusUpdateNotification |
| ExpiredTokenNotification | ExpiredTokenNotification |
| ExtensionWorkitemNotification | ExtensionWorkitemNotification |
| InitAutoLoginToAcd | InitAutoLoginToAcd |
| InitAutoLoginToAcdEnabled | InitAutoLoginToAcdEnabled |
| InitAutoLoginToAcdError | InitAutoLoginToAcdError |
| InitChangeTelephonyImplementation | InitChangeTelephonyImplementation |
| InitChangeTelephonyImplementationError | InitChangeTelephonyImplementationError |
| InitChangeTelephonyImplementationFreeswitch | InitChangeTelephonyImplementationFreeswitch |
| InitChangeTelephonyImplementationPSTN | InitChangeTelephonyImplementationPSTN |
| InitChangeTelephonyImplementationTwilio | InitChangeTelephonyImplementationTwilio |
| InitConnectStatisticsSocket | InitConnectStatisticsSocket |
| InitConnectStatisticsSocketError | InitConnectStatisticsSocketError |
| InitConnectStatisticsSocketSuccess | InitConnectStatisticsSocketSuccess |
| InitConnectUserSocket | InitConnectUserSocket |
| InitConnectUserSocketError | InitConnectUserSocketError |
| InitConnectUserSocketSuccess | InitConnectUserSocketSuccess |
| InitDataDogServiceLoadMandatoryData | InitDataDogServiceLoadMandatoryData |
| InitDataDogServiceSetUser | InitDataDogServiceSetUser |
| InitError | init_error |
| InitFetchWidgets | InitFetchWidgets |
| InitFetchWidgetsError | InitFetchWidgetsError |
| InitFetchWidgetsSuccess | InitFetchWidgetsSuccess |
| InitRefreshToken | InitRefreshToken |
| InitRefreshTokenCycleStarted | InitRefreshTokenCycleStarted |
| InitRefreshTokenSuccess | InitRefreshTokenInitRefreshTokenSuccess |
| InitResolveSession | InitResolveSession |
| InitRetrieveLocalStorageDevices | InitRetrieveLocalStorageDevices |
| InitRetrieveLocalStorageDevicesError | InitRetrieveLocalStorageDevicesError |
| InitRetrieveLocalStorageDevicesSuccess | InitRetrieveLocalStorageDevicesSuccess |
| InitSuccess | init_success |
| LanguageLoaded | LanguageLoaded |
| LiveTranscriptionCompletedNotification | LiveTranscriptionCompletedNotification |
| LiveTranscriptionNotification | LiveTranscriptionNotification |
| LoginSuccess | LoginSuccess |
| LogoutNotification | LogoutNotification |
| MessageNotification | MessageNotification |
| MonitorWorkitemNotification | MonitorWorkitemNotification |
| OffersChangedNotification | OffersChangedNotification |
| PhoneStateNotification | PhoneStateNotification |
| QualityWarningsChangedNotification | QualityWarningsChangedNotification |
| Ready | ready |
| StatusChangedNotification | StatusChangedNotification |
| SupervisorStatsNotification | SupervisorStatsNotification |
| UnreadCountNotification | UnreadCountNotification |
| UpdateTicketNotification | UpdateTicketNotification |
| UsersChangedNotification | UsersChangedNotification |
| WallboardNotification | WallboardNotification |
| WorkitemConversationMessageNotification | WorkitemConversationMessageNotification |
| WorkitemFailedNotification | WorkitemFailedNotification |
| WorkitemPredictiveNotification | WorkitemPredictiveNotification |
| WorkitemProgressiveNotification | WorkitemProgressiveNotification |
| WorkitemRemovedNotification | WorkitemRemovedNotification |
| WorkitemStateChangeNotification | WorkitemStateChangeNotification |
| WorkitemSummaryNotification | WorkitemSummaryNotification |
| WorkitemTransferNotification | WorkitemTransferNotification |
Base hook: useSubscription
Subscribes to any SDK event
import { useSubscription } from '@nextiva/ncx-react-sdk';
useSubscription({
event: 'WorkitemSummaryNotification',
subscriptionFn: (summaryNotification) => {
Logger.log(summaryNotification);
if (
summaryNotification.state === 'started' &&
activeWorkItem?.workitemId === summaryNotification.workitemId
) {
setSummaryInProgress(true);
// you could display a notification that BE is working on the summary.
// block disposition.
} else if (summaryNotification.state === 'ended') {
// you could display a notification that BE is done working on the summary.
// unblock disposition.
setSummaryInProgress(false);
} else if (summaryNotification.state === 'failed') {
setSummaryInProgress(false);
}
},
});Prebuilt event hook
| Hook | Trigger |
|---|---|
| useExtensionWorkitemSubscription() | When you receive an agent-to-agent call |
| useMonitorWorkitemSubscription() | When a supervised agent gets a workitem |
| useUpdateTicketNotificationSubscription() | When a ticket receives an update |
| useWorkitemPredictiveSubscription() | When a predictive dialer assigns a workitem |
| useWorkitemRemovedSubscription()* | When a workitem is fully terminated |
| useWorkitemStateChangeSubscription()* | When a workitem is updated |
| useWorkitemTransferSubscription() | When a workitem is transferred to the current user |
| useWorkitemConversationMessageSubscription() | When a new message is received in a conversation |
State hooks
State hooks provide access to local SDK-managed session values. These values are reactive. If a value changes (e.g. available devices, user status) the hook will trigger a re-render.
| Hook | Description |
|---|---|
| useAvailableAudioDeviceList() | List of input/output devices |
| useSelectedAudioInputDeviceId() | ID of selected input device |
| useSelectedAudioOutputDevice() | ID of selected output device |
| useSelectedAudioInputDeviced() | Info about selected input device |
| useSelectedAudioOutputDevice() | Info about selected output device |
Session and ACD state
| Hook | Description | Return |
|---|---|---|
| useIsInConference() | Whether the user is currently in a conference | Boolean true/fase |
| useIsLoggedInToAcd() | Whether the user is logged into the ACD | Boolean true/false |
| usePhoneState() | Value of the PhoneState object | OnHook, OffHook, or Ringing |
| useMuteState() | Whether the user is muted | |
| useOffers() | List of workitems offered to the agent |
User and status
| Hook | Description |
|---|---|
| useStatusState() | Current user status |
| useUsers() | List of agents in the tenant |
Supervisor and wallboard hooks
| Hook | Description |
|---|---|
| useSupervisorCampaignStatistics() | Stats on campaigns |
| useSupervisorOutboundListStatistics() | Stats on outbound lists |
| useSupervisorQueueStatistics() | Stats on queues |
| useSupervisorUserStatistics() | Stats on users |
| useSupervisorWorkItemStatistics() | Stats on workitems |
| useWallboard() | Active wallboard messages |
Summary
| Hook type | Purpose |
|---|---|
| Event hooks | Handle to backend events in real time |
| State hooks | Access and react to local session state |
| Utility | Logging, device selection, diagnostics |
Use these hooks to create responsive UI components that react to calls, workitems, and system statuses without writing your own WebSocket handles or managing complex state.
React-specific UserServices
file: File
The attachment in the email, if there’s an attachment in the email.
force: boolean
When a user has some compliance flag and he tries to send an email
somewhere that is outside of the...that says you are calling outside of the allowed hours. They then can decide to send the email anyway (force) or cancel.
message: string
The text of the email.
name: string REQUIRED
The name of the receiver of the email.
option: string
to: string
The email address of the receiver.
workitemId: string
The unique identifier of the email workitem.
this.userService.sms(payload: SendMessagePayload)Email
file: File
The attachment in the email, if there’s an attachment in the email.
force: boolean
When a user has some compliance flag and he tries to send an email
somewhere that is outside of the...that says you are calling outside of the allowed hours. They then can decide to send the email anyway (force) or cancel.
message: string
The text of the email.
name: string REQUIRED
The name of the receiver of the email.
option: string
to: string
The email address of the receiver.
workitemId: string
The unique identifier of the email workitem.
this.userService.email(payload: SendMessagePayload)Fax
file: File
The attachment in the email, if there’s an attachment in the email.
force: boolean
When a user has some compliance flag and he tries to send an email
somewhere that is outside of the...that says you are calling outside of the allowed hours. They then can decide to send the email anyway (force) or cancel.
message: string
The text of the email.
name: string REQUIRED
The name of the receiver of the email.
option: string
to: string
The email address of the receiver.
workitemId: string
The unique identifier of the email workitem.
this.userService.fax(payload: SendMessagePayload)Updated 5 months ago