State Service

Learn about the Nextiva SDK's state service

Overview

The StateService class provides centralized state management for the SDK. It manages user session data, authentication tokens, language and platform settings, telephony configuration, user and tenant information, translation bundles, and more. Designed to be used as a singleton, this service enables consistent access to key application state throughout the SDK lifecycle.

Public methods

clear

Clears all states except for critical fields (platform, language, baseURL, translationBundles).

clear(): void

get

Retrieves the value associated with the given key from the state map.

get(key: string): unknown

Parameters

  • key (string)
    The key to retrieve.

Returns

  • The value stored for the key, or undefined if not present.

set

Sets the value for a given key in the state map.

set(key: string, value: unknown): void

Parameters

  • key (string)
    The key to set.
  • value(unknown)
    The value to store.

delete

Removes the value associated with the given key from the state map.

delete(key: string): void

Parameters

  • key (string)
    The key to remove.

getMap

Returns the underlying state map.

getMap(): Map<string, any>

Returns

  • The internal Map<string, any> instance that stores all states.

getTelephonyConfig

Retrieves the telephony configuration from the current session or device.

getTelephonyConfig(): unknown

Returns

  • The telephony configuration object, or undefined if not set.

getLanguage / setLanguage

Gets or sets the current language for the application. Defaults to 'en' if not set.

getLanguage(): string
setLanguage(language: string): void

Parameters

  • (setLanguage):
    language (string) REQUIRED The language code to set (e.g., 'en', 'es').

Returns

  • getLanguage
    The current language code.

getPlatform/setPlatform

Gets or sets the current platform.

getPlatform(): Platform | undefined
setPlatform(platform: Platform): void

Parameters

  • (setPlatform):
    platform (Platform) The platform to set.

Returns

  • getPlatform()
    The current platform, or undefined if not set.

getToken/ setToken

Gets or sets the authentication token.

getToken(): string | undefined
setToken(token: string): void

Parameters

  • (setToken):
    token (string) The authentication token.
  • getToken()
    The current token, or undefined if not set.

getUserId

Retrieves the user ID from the current session.

getUserId(): string | undefined

Returns

The user ID string, or undefined if not available.

getTenant/setTenant

Gets or sets the current tenant.

getTenant(): Tenant | undefined
setTenant(tenant: Tenant): void

Parameters

(setTenant):
tenant (Tenant) The tenant object.

Returns

  • getTenant()
    The current tenant, or undefined if not set.

getSession/setSession

Gets or sets the current user session object.

getSession(): UserSession | undefined
setSession(session: UserSession): void

Parameters

  • (setSession):
    session (UserSession) The session object to store.

Returns

  • getSession()
    The current session, or undefined if not set.

getUser/setUser

Gets or sets the current user details.

getUser(): UserDetails | undefined
setUser(user: UserDetails): void

Parameters

  • (setUser):
    user (UserDetails): The user details object.

Returns

  • getUser()
    The current user details, or undefined if not set.

getUserProfile/setUserProfile

Gets or sets the current user profile.

getUserProfile(): UserProfile | undefined
setUserProfile(userProfile: UserProfile): void

Parameters

  • (setUserProfile):
    userProfile (UserProfile) The user profile object.

Returns

  • getUserProfile()
    The current user profile, or undefined if not set.

getDevice/setDevice

Gets or sets the current multilogin device.

getDevice(): MultiloginDevice | undefined
setDevice(device: MultiloginDevice): void

Parameters

  • (setDevice):
    device (MultiloginDevice) The device object.

Returns

  • getDevice()
    The current device, or undefined if not set.

getTranslations/setTranslations

Gets or sets translation bundles for a specific language.

getTranslations(language: string): Translations | undefined
setTranslations(language: string, translations: Translations): void

Parameters

  • (setTranslations):
    language string The language code.

    translations (Translations)
    The translation bundle.

Returns

  • getTranslations()
    The translation bundle for the specified language, or undefined if not set.

getACDLoginAt/setACDLoggedInAt

Gets or sets the ACD login timestamp in the session.

getACDLoginAt(): number
setACDLoggedInAt(acdLoginAt: number): void

Parameters

  • (setACDLoggedInAt):
    acdLoginAt (number) ACD login timestamp or 0 if logged out.

Returns

  • getACDLoginAt():
    The ACD login timestamp, or 0 if not logged in.

isLoggedInToACD

Checks if the user is logged in to ACD (Automatic Call Distributor).

isLoggedInToACD(): boolean

Returns

  • true if logged in to ACD, otherwise false.
Campaigns and inboxes

getCampaigns/setCampaigns

Gets or sets the list of campaigns in the state.

getCampaigns(): Campaign[] | undefined
setCampaigns(campaigns: Campaign[]): void

Parameters

  • (setCampaigns):
    campaigns Campaign[] Array of campaign objects.

Returns

  • getCampaigns()
    Array of campaigns or undefined if not set.

getSharedInboxes

Retrieves shared inbox campaigns, optionally filtered by type.

getSharedInboxes(types?: CampaignType[]): Campaign[]

Parameters

  • types CampaignType[]
    Types to filter the shared inboxes by.

Returns

  • An array of shared inbox campaigns.

getPersonalInboxes

Retrieves campaigns of type PERSONAL.

getPersonalInboxes(): Campaign[]

Returns

  • An array of personal inbox campaigns.

getPersonalInbox

Retrieves the first personal inbox campaign matching the user's personal inbox ID.

getPersonalInbox(): Campaign | undefined

Returns

  • The personal inbox campaign, or undefined if not found.

getCampaign

Retrieves a campaign by its ID.

getCampaign(id: string): Campaign | undefined

Parameters

  • id string
    The campaign ID.

Returns

  • The campaign object, or undefined if not found.

getCampaignScripts/setCampaignScripts

Gets or sets campaign scripts in the state.

getCampaignScripts(): CampaignScript[] | undefined
setCampaignScripts(campaignScripts: CampaignScript[]): void

Parameters

  • (setCampaignScripts)
    campaignScripts CampaignScript[] An array of campaign scripts.

Returns

  • (getCampaignScripts)
    An array of campaign scripts or undefined if not set.

getSurveys/setSurveys

Gets or sets surveys in the state.

getSurveys(): Survey[] | undefined
setSurveys(surveys: Survey[]): void

Parameters

  • (setSurveys)
    surveys Survey[] Array of survey objects.

Returns

  • (getSurveys)
    An array of surveys or undefined if not set.
Additional methods

getUserSettings

Retrieves user client settings from the state.

getUserSettings(): UserClientSettings | null

Returns

  • A user client settings object or null if not found.
export interface Settings {
 acd?: {
   channels?: string[];
   queues?: string[];
 };
 dial?: {
   closeOnDial: boolean;
 };
 directory?: {
   agentMessageNotification: boolean;
   agentSoundNotification?: string;
   closeOnDial: boolean;
   closeOnTransfer: boolean;
   queueMessageNotification: unknown[];
   topicMessageNotification: boolean;
 };
 general?: {
   defaultCampaignId: string;
   defaultEmailCampaignId?: string;
   defaultFaxCampaignId?: string;
   defaultSMSCampaignId: string;
 };
 workitem?: {
   alwaysDigitalMessagesWebNotification: boolean;
   alwaysDigitalWebNotification: boolean;
   alwaysVoiceWebNotification: boolean;
   digitalMessageRingtone?: string;
   digitalRingtone?: string;
   enableDigitalMessagesWebNotification: boolean;
   enableDigitalWebNotification: boolean;
   enableVoiceWebNotification: boolean;
   highPrioritySoundNotification?: string;
   repeatDigitalMessagesRingtone: boolean;
   repeatDigitalRingtone: boolean;
   repeatVoiceRingtone: boolean;
   voiceRingtone?: string;
 };
}

hasClientTracing/setClientTracing

Checks or sets whether client tracing is allowed for the user.

hasClientTracing(): boolean
setClientTracing(allowClientTracing: boolean): void

Parameters

  • (setClientTracing)
    allowClientTracing boolean Whether client tracing is allowed.

Returns

  • hasClientTracing() boolean
    True if allowed, false otherwise.

setOffers/getOffers

Sets or retrieves offers in the state.

Parameters

  • (setOffers)
    offers Offer[] Array of offers.

Returns

  • getOffers()
    An array of offers or undefined if not set.

getTopics/setTopics

Gets or sets topics in the state.

getTopics(): RealTimeTopic[] | undefined
setTopics(topics: RealTimeTopic[]): void

Parameters

  • (setTopics)
    topics RealTimeTopic[] An array of topics.

Returns

  • getTopics()
    An array of topics or undefined if not set.

getInboxes/setInboxes

Gets or sets inboxes in the state.

getInboxes(): RealTimeInbox[] | undefined
setInboxes(inboxes: RealTimeInbox[]): void

Parameters

  • (setInboxes)
    inboxes RealTimeInbox[] An array of inboxes.

Returns

  • getInboxes()
    An array of inboxes or undefined if not set.

getUsers/setUsers

Gets or sets users in the state.

getUsers(): RealTimeUser[] | undefined
setUsers(users: RealTimeUser[]): void

Parameters

  • (setUsers)
    users RealTimeUser[] An array of users.

Returns

  • getUsers()
    An array of users or undefined if not set.

getBaseURL/setBaseURL

Gets or sets the base URL for the service.

getBaseURL(): string | undefined
setBaseURL(baseURL: string): void

Parameters

  • (setBaseURL)
    baseURL string The base URL to set.

Returns

  • getBaseURL()
    The base URL string or undefined if not set.

getDeviceToken/setDeviceToken

Gets or sets the device token.

getDeviceToken(): string | undefined
setDeviceToken(token: string): void

Parameters

  • (setDeviceToken)
    token (string) The device token.

Returns

  • getDeviceToken()
    The device token string or undefined if not set.

getClientLocation/setClientLocation

Gets or sets the client location.

getClientLocation(): string | undefined
setClientLocation(clientLocation: string): void

Parameters

  • (setClientLocation)
    clientLocation (string) The client location.

Returns

  • getClientLocation()
    The client location string or undefined if not set.

getUserFromId

Retrieves a user object from the company directory by user ID.

getUserFromId(userId: string): UserDetails | undefined

Parameters

  • userId string
    The user ID.

Returns

  • The user object or undefined if not found.
 [key: string]: unknown;
 _id: string;
 acdAutoAccept: boolean;
 acdAutoLogin: boolean;
 allowAcdChanges: boolean;
 allowClientTracing: boolean;
 allowServerTracing: boolean;
 alwaysDurationWebNotification: boolean;
 alwaysHoldWebNotification: boolean;
 avatar?: string;
 callFailedNotification: boolean;
 chatDurationNotification: boolean;
 confirmDisposition: string;
 createdAt: number;
 createdBy: string;
 credentialsNonExpired: boolean;
 defaultAcdLoginStatus: string;
 deletedAt: number;
 deletedBy?: string;
 dialConfirmation: boolean;
 dialpadMode: string;
 directory: {
   queues: unknown[];
   topics: string[];
   users: string[];
 };
 disableDisposition: 'on' | 'off' | 'userProfile' | boolean | null | undefined;
 disableEmailNotification: boolean;
 disableStartRecording: boolean;
 disableStopRecording: boolean;
 dispositionNotification: boolean;
 edgeId?: string;
 enableDurationWebNotification: boolean;
 enableHoldWebNotification: boolean;
 enableRealtimeTranscription: string;
 enabled: boolean;
 expansions?: {
   languageId?: UserLanguageSettings;
   networkregionId?: UserNetworkRegionSettings;
   personalInboxCampaignId?: UserPersonalInboxCampaignSettings;
   voiceSettingsId?: UserVoiceSettings;
 };
 files: Record<
   string,
   {
 	contentType: string;
 	fileType?: string;
 	label: string;
 	name: string;
   }
 >;
 firstName: string;
 hideInCompanyDirectory: boolean;
 hideInDirectory: boolean;
 hometabs: HomeTabs;
 inboundCallDurationNotification: boolean;
 inboundCallHoldNotification: boolean;
 inboundEmailDurationNotification: boolean;
 inboundExtensionCallDurationNotification: boolean;
 inboundSMSDurationNotification: boolean;
 languageId: string;
 lastName: string;
 mSTeamsEnabled?: boolean;
 modifiedAt: number;
 modifiedBy: string;
 name: string;
 oAuthProfileAssignmentFromExternalRole: boolean;
 outboundCallDurationNotification: boolean;
 outboundCallHoldNotification: boolean;
 outboundEmailDurationNotification: boolean;
 outboundExtensionCallDurationNotification: boolean;
 outboundSMSDurationNotification: boolean;
 passwordModifiedAt: number;
 personalInboxCampaignId?: string;
 predictiveCallDurationNotification: boolean;
 predictiveSMSDurationNotification: boolean;
 progressiveCallDurationNotification: boolean;
 pseudonym: string;
 queues: Queues;
 recordingAnalysisPercentage: number;
 ringOnLogout: boolean;
 ringPhoneOnOffer: boolean;
 scrubOnDial: boolean;
 sendToVoicemailOnBusy?: boolean;
 settings: Settings;
 showWebrtcNotification: boolean;
 socialDurationNotification: boolean;
 status?: number;
 statusId?: string;
 telephony: TelephonyConfig;
 tenantId: string;
 timezone: string;
 useReactWorkitemLayout: string;
 useSideBarHeader: string;
 userClientSettingsId: string;
 userId: string;
 userProfileId: string;
 username: string;
 verifyConsentOnDial: boolean;
 verifyConsentOnSMS: boolean;
}

getInboxFromId

Retrieves an inbox (queue) from the company directory by inbox ID.

getInboxFromId(inboxId: string): RealTimeInbox | undefined

Parameters

  • inboxId string
    The inbox ID.

Returns

  • The inbox object or undefined if not found.

getTopicFromId

Retrieves a topic from the company directory by topic ID.

getTopicFromId(topicId: string): RealTimeTopic | undefined

Parameters

  • topicId string
    The topic ID.

Returns

  • The topic object or undefined if not found.
export interface RealTimeTopic {
 _id: string;
 createdAt: number;
 createdBy: string;
 deletedAt: number;
 description: string;
 modifiedAt: number;
 modifiedBy: string;
 name: string;
 objectType: string;
 tenantId: string;
 topicId: string;
 users: string;
}

getUserStatusRecord/setUserStatusRecord

Gets or sets the user status record.

getUserStatusRecord(): UserStatusRecord | undefined
setUserStatusRecord(record: UserStatusRecord): void

Parameters

  • (setUserStatusRecord)
    record UserStatusRecord The user status record to set.

Returns

  • getUserStatusRecord()
    The user status record or undefined if not set.

getAuthorities/setAuthorities

Gets or sets authorities in the state.

getAuthorities(): Authority[] | undefined
setAuthorities(authorities: Authority[]): void

Parameters

  • (setAuthorities)
    authorities Authority[] An array of authorities.

Returns

  • getAuthorities()
    An array of authorities or undefined if not set.

hasPermission/canCreate/canDelete/canListenMine/canSearch/canShow/canUpdate/ canUpdateMine/canView/canViewMine

Permission and access control checks for various operations.

hasPermission(domain: string, type: string, permission: Permission): boolean
canCreate(type: string): boolean
canDelete(type: string): boolean
canListenMine(type: string): boolean
canSearch(type: string): boolean
canShow(type: string): boolean
canUpdate(type: string): boolean
canUpdateMine(type: string): boolean
canView(type: string): boolean
canViewMine(type: string): boolean

Parameters

  • Varies by method; typically
    type string or domain string or permission Permission

Returns

A boolean indicating if the user has the permission.

getLanguages/setLanguages

Gets or sets available languages in the state.

getLanguages(): Language[] | undefined
setLanguages(languages: Language[]): void

Parameters

  • (setLanguages)
    languages Language[] An array of language objects.

Returns

  • getLanguages()
    An array of languages or undefined if not set.

getName/getUsername/isSysAdmin/isSysTenant/isAgent/getEdgeId/hasAutoLoginToACD

User and session utility methods.

getName(): string
getUsername(): string | undefined
isSysAdmin(): boolean
isSysTenant(): boolean
isAgent(): boolean
getEdgeId(): string | null
hasAutoLoginToACD(): boolean

Returns

  • Varies by method (string, boolean, or null).

getStatuses/setStatuses/getStatusName

Gets/sets statuses or retrieves the name of a status by ID.

getStatuses(): Status[] | undefined
setStatuses(statuses: Status[]): void
getStatusName(statusId: string): string

Parameters

  • (setStatuses)
    statuses (Status[]) Array of status objects.

    statusId string
    The status ID.

Returns

  • Array of statuses, or status name as string.

setSchemaTypeMap/getSchemaTypeMap/getSchemaTypes/getSchemaType/getSchemaTypeLinks /getSchemaTypeLinkURI/getSchemaTypeModel/getSchemaTypeModelByName

Schema type and model management utilities.

setSchemaTypeMap(map: Map<string, SchemaType>): void
getSchemaTypeMap(): Map<string, SchemaType> | undefined
getSchemaTypes(): SchemaType[] | undefined
getSchemaType(schemaTypeName: string): SchemaType | undefined
getSchemaTypeLinks(schemaTypeName: SchemaTypeName): unknown
getSchemaTypeLinkURI(options: GetSchemaTypeLinkURIOptions): string
getSchemaTypeModel(schemaTypeId: string): unknown
getSchemaTypeModelByName(schemaTypeName: string): unknown

Paramters

  • Varies by method (see source for details).

Returns

  • Schema type, model, map, or URI as appropriate.

getDispositions/setDispositions/getComplianceDispositions/setComplianceDispositions

Gets/sets dispositions and compliance dispositions.

getDispositions(): Disposition[] | undefined
setDispositions(dispositions: Disposition[]): void
getComplianceDispositions(): unknown[] | undefined
setComplianceDispositions(complianceDispositions: unknown[]): void

Parameters

  • Varies by method.

Returns

  • Array of dispositions or compliance dispositions.

getSpeedDials/setSpeedDials

Gets/sets speed dials in the state.

getSpeedDials(): unknown[] | undefined
setSpeedDials(speedDials: unknown[]): void

Parameters

  • (setSpeedDials)
    speedDials unknown[] An array of speed dials.

Returns

  • (getSpeedDials)
    An array of speed dials or undefined if not set.

getTemplates/setTemplates

Gets/sets templates in the state.

getTemplates(): Template[] | undefined
setTemplates(templates: Template[]): void

Parameters

  • (setTemplates)
    templates Template[] An array of templates.

Returns

  • (getTemplates)
    An array of templates or undefined if not set.

getClassifications/setClassifications

Gets/sets classifications in the state.

getClassifications(): unknown[] | undefined
setClassifications(classifications: unknown[]): void

Parameters

  • (setClassifications)
    classifications unknown[] An array of classifications.
  • (getClassifications)
    An array of classifications or undefined if not set.

getScoreCards/setScoreCards

Gets/sets score cards in the state.

getScoreCards(): unknown[] | undefined
setScoreCards(scoreCards: unknown[]): void

Parameters

  • (setScoreCards)
    scoreCards (unknown[]) An array of score cards.

Returns

  • (getScoreCards)
    An array of score cards or undefined if not set.

getSchemaLayouts/setSchemaLayouts/getSchemaLayout

Gets/sets schema layouts or retrieves a schema layout by ID.

getSchemaLayouts(): SchemaLayout[] | undefined
setSchemaLayouts(schemaLayouts: SchemaLayout[]): void
getSchemaLayout(id: string): SchemaLayout | undefined

Parameters

Varies by method.

Returns

An array of schema layouts or a single schema layout.

getSkills/setSkills

Gets/sets skills in the state.

getSkills(): Skill[] | undefined
setSkills(skills: Skill[]): void

Parameters

  • (setSkills)
    skills Skill[] Array of skills.

Returns

  • (getSkills)
    An array of skills or undefined if not set.

getRegexes/setRegexes

Gets/sets regexes in the state.

getRegexes(): unknown[] | undefined
setRegexes(regexes: unknown[]): void

Parameters

  • (setRegexes)
    regexes unknown[] An array of regexes.

Returns

  • (getRegexes)
    An array of regexes or undefined if not set.

setOutboundMode

Sets the outbound mode for the session.

setOutboundMode(outboundMode: OutboundMode): void

Parameters

  • outboundMode OutboundMode
    The outbound mode identifier.

getDevices

Gets all devices from the session.

getDevices(): MultiloginDevice[] | undefined

Returns

Array of devices or undefined if not set.

isLoggedIntoProgressive/isLoggedIntoPredictive/isLoggedIntoQuarterback

Checks if the user is logged into a specific outbound mode.

isLoggedIntoProgressive(): boolean
isLoggedIntoPredictive(): boolean
isLoggedIntoQuarterback(): boolean

Returns

  • A boolean indicating login status for each mode.

isWebRTCAllowed/setWebRTCAllowed

Checks or sets whether WebRTC is allowed.

isWebRTCAllowed(): boolean
setWebRTCAllowed(isWebRTCAllowed: boolean): void

Parameters

  • (setWebRTCAllowed)
    isWebRTCAllowed boolean Whether WebRTC is allowed.

Returns

  • (isWebRTCAllowed)
    A boolean indicating if WebRTC is allowed.

isInConference/setInConference

Checks or sets whether the user is in a conference.

isInConference(): boolean
setInConference(isInConference: boolean): void

Parameters

  • (setInConference)
    isInConference boolean Whether the user is in a conference.

Returns

  • (isInConference)
    A boolean indicating conference status.

Example Usage

typescript
import { StateService } from '../services/state';

const state = new StateService();

// Set and get a token
state.setToken('abc123');
const token = state.getToken();

// Set and get language
state.setLanguage('es');
const lang = state.getLanguage();

// Set and retrieve user session
state.setSession({ userId: 'user1', ... });
const session = state.getSession();

// Clear all state except for critical fields
state.clear();