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(): voidget
Retrieves the value associated with the given key from the state map.
get(key: string): unknownParameters
key(string)
The key to retrieve.
Returns
- The value stored for the key, or
undefinedif not present.
set
Sets the value for a given key in the state map.
set(key: string, value: unknown): voidParameters
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): voidParameters
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(): unknownReturns
- The telephony configuration object, or
undefinedif not set.
getLanguage / setLanguage
Gets or sets the current language for the application. Defaults to 'en' if not set.
getLanguage(): string
setLanguage(language: string): voidParameters
- (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): voidParameters
- (setPlatform):
platform(Platform) The platform to set.
Returns
getPlatform()
The current platform, orundefinedif not set.
getToken/ setToken
Gets or sets the authentication token.
getToken(): string | undefined
setToken(token: string): voidParameters
- (setToken):
token(string) The authentication token. - getToken()
The current token, orundefinedif not set.
getUserId
Retrieves the user ID from the current session.
getUserId(): string | undefinedReturns
The user ID string, or undefined if not available.
getTenant/setTenant
Gets or sets the current tenant.
getTenant(): Tenant | undefined
setTenant(tenant: Tenant): voidParameters
(setTenant):
tenant (Tenant)
The tenant object.
Returns
getTenant()
The current tenant, orundefinedif not set.
getSession/setSession
Gets or sets the current user session object.
getSession(): UserSession | undefined
setSession(session: UserSession): voidParameters
- (setSession):
session(UserSession) The session object to store.
Returns
getSession()
The current session, orundefinedif not set.
getUser/setUser
Gets or sets the current user details.
getUser(): UserDetails | undefined
setUser(user: UserDetails): voidParameters
- (setUser):
user(UserDetails): The user details object.
Returns
getUser()
The current user details, orundefinedif not set.
getUserProfile/setUserProfile
Gets or sets the current user profile.
getUserProfile(): UserProfile | undefined
setUserProfile(userProfile: UserProfile): voidParameters
- (setUserProfile):
userProfile(UserProfile) The user profile object.
Returns
getUserProfile()
The current user profile, orundefinedif not set.
getDevice/setDevice
Gets or sets the current multilogin device.
getDevice(): MultiloginDevice | undefined
setDevice(device: MultiloginDevice): voidParameters
- (setDevice):
device(MultiloginDevice) The device object.
Returns
getDevice()
The current device, orundefinedif not set.
getTranslations/setTranslations
Gets or sets translation bundles for a specific language.
getTranslations(language: string): Translations | undefined
setTranslations(language: string, translations: Translations): voidParameters
-
(setTranslations):
languagestring The language code.translations(Translations)
The translation bundle.
Returns
getTranslations()
The translation bundle for the specified language, orundefinedif not set.
getACDLoginAt/setACDLoggedInAt
Gets or sets the ACD login timestamp in the session.
getACDLoginAt(): number
setACDLoggedInAt(acdLoginAt: number): voidParameters
- (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(): booleanReturns
trueif logged in to ACD, otherwisefalse.
Campaigns and inboxes
getCampaigns/setCampaigns
Gets or sets the list of campaigns in the state.
getCampaigns(): Campaign[] | undefined
setCampaigns(campaigns: Campaign[]): voidParameters
- (setCampaigns):
campaignsCampaign[] Array of campaign objects.
Returns
getCampaigns()
Array of campaigns orundefinedif not set.
getSharedInboxes
Retrieves shared inbox campaigns, optionally filtered by type.
getSharedInboxes(types?: CampaignType[]): Campaign[]Parameters
typesCampaignType[]
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 | undefinedReturns
- The personal inbox campaign, or
undefinedif not found.
getCampaign
Retrieves a campaign by its ID.
getCampaign(id: string): Campaign | undefinedParameters
idstring
The campaign ID.
Returns
- The campaign object, or
undefinedif not found.
getCampaignScripts/setCampaignScripts
Gets or sets campaign scripts in the state.
getCampaignScripts(): CampaignScript[] | undefined
setCampaignScripts(campaignScripts: CampaignScript[]): voidParameters
- (setCampaignScripts)
campaignScriptsCampaignScript[] An array of campaign scripts.
Returns
- (getCampaignScripts)
An array of campaign scripts orundefinedif not set.
getSurveys/setSurveys
Gets or sets surveys in the state.
getSurveys(): Survey[] | undefined
setSurveys(surveys: Survey[]): voidParameters
- (setSurveys)
surveysSurvey[] Array of survey objects.
Returns
- (getSurveys)
An array of surveys orundefinedif not set.
Additional methods
getUserSettings
Retrieves user client settings from the state.
getUserSettings(): UserClientSettings | nullReturns
- 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): voidParameters
- (setClientTracing)
allowClientTracingboolean Whether client tracing is allowed.
Returns
hasClientTracing()boolean
True if allowed, false otherwise.
setOffers/getOffers
Sets or retrieves offers in the state.
Parameters
- (setOffers)
offersOffer[] Array of offers.
Returns
- getOffers()
An array of offers orundefinedif not set.
getTopics/setTopics
Gets or sets topics in the state.
getTopics(): RealTimeTopic[] | undefined
setTopics(topics: RealTimeTopic[]): voidParameters
- (setTopics)
topicsRealTimeTopic[] An array of topics.
Returns
- getTopics()
An array of topics orundefinedif not set.
getInboxes/setInboxes
Gets or sets inboxes in the state.
getInboxes(): RealTimeInbox[] | undefined
setInboxes(inboxes: RealTimeInbox[]): voidParameters
- (setInboxes)
inboxesRealTimeInbox[] An array of inboxes.
Returns
- getInboxes()
An array of inboxes orundefinedif not set.
getUsers/setUsers
Gets or sets users in the state.
getUsers(): RealTimeUser[] | undefined
setUsers(users: RealTimeUser[]): voidParameters
- (setUsers)
usersRealTimeUser[] An array of users.
Returns
- getUsers()
An array of users orundefinedif not set.
getBaseURL/setBaseURL
Gets or sets the base URL for the service.
getBaseURL(): string | undefined
setBaseURL(baseURL: string): voidParameters
- (setBaseURL)
baseURLstring The base URL to set.
Returns
- getBaseURL()
The base URL string orundefinedif not set.
getDeviceToken/setDeviceToken
Gets or sets the device token.
getDeviceToken(): string | undefined
setDeviceToken(token: string): voidParameters
- (setDeviceToken)
token(string) The device token.
Returns
- getDeviceToken()
The device token string orundefinedif not set.
getClientLocation/setClientLocation
Gets or sets the client location.
getClientLocation(): string | undefined
setClientLocation(clientLocation: string): voidParameters
- (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 | undefinedParameters
userIdstring
The user ID.
Returns
- The user object or
undefinedif 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 | undefinedParameters
inboxIdstring
The inbox ID.
Returns
- The inbox object or
undefinedif not found.
getTopicFromId
Retrieves a topic from the company directory by topic ID.
getTopicFromId(topicId: string): RealTimeTopic | undefinedParameters
topicIdstring
The topic ID.
Returns
- The topic object or
undefinedif 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): voidParameters
- (setUserStatusRecord)
recordUserStatusRecord 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[]): voidParameters
- (setAuthorities)
authoritiesAuthority[] 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): booleanParameters
- Varies by method; typically
typestring ordomainstring orpermissionPermission
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[]): voidParameters
- (setLanguages)
languagesLanguage[] 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(): booleanReturns
- Varies by method (
string,boolean, ornull).
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): stringParameters
-
(setStatuses)
statuses(Status[]) Array of status objects.statusIdstring
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): unknownParamters
- 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[]): voidParameters
- 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[]): voidParameters
- (setSpeedDials)
speedDialsunknown[] 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[]): voidParameters
- (setTemplates)
templatesTemplate[] 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[]): voidParameters
- (setClassifications)
classificationsunknown[] 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[]): voidParameters
- (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 | undefinedParameters
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[]): voidParameters
- (setSkills)
skillsSkill[] 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[]): voidParameters
- (setRegexes)
regexesunknown[] 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): voidParameters
outboundModeOutboundMode
The outbound mode identifier.
getDevices
Gets all devices from the session.
getDevices(): MultiloginDevice[] | undefinedReturns
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(): booleanReturns
- A boolean indicating login status for each mode.
isWebRTCAllowed/setWebRTCAllowed
Checks or sets whether WebRTC is allowed.
isWebRTCAllowed(): boolean
setWebRTCAllowed(isWebRTCAllowed: boolean): voidParameters
- (setWebRTCAllowed)
isWebRTCAllowedboolean 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): voidParameters
- (setInConference)
isInConferenceboolean 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();Updated 5 months ago