@or-sdk/hitl
v0.45.7
Published
OneReach SDK client for Hitl
Readme
Installation:
$ npm i @or-sdk/hitlUsage
To start using HitL API methods through this SDK it has to be Initialized first. To do that a OneReach JWT authorization token and a HitL or Discovery service URL have to be passed to the constructor. After initializing the HitL SDK, its methods can be used to make requests to HitL APIs.
Available HitL APIs are:
agents- Manage HitL agents (retrieve, search, manage permissions, status and meta information) (see AgentsApi class for the documentation)cannedMessages- Manage predefined message templates for quick responses (see CannedMessagesApi class for the documentation)commands- Send and manage commands within HitL sessions (see CommandsApi class for the documentation)conferences- Manage voice conference participants and member states (see ConferencesApi class for the documentation)contactRuleGroups- Manage contact rule groups (search, create, update, delete) (see ContactRuleGroupsApi class for the documentation)contacts- Search contacts with filtering based on agent's contact rule groups (see ContactsApi class for the documentation)contactsMeta- Retrieve metadata information about contacts (timestamps, etc.) (see ContactsMetaApi class for the documentation)eventTemplates- Manage event templates (retrieve, create, update, delete) (see EventTemplatesApi class for the documentation)filters- Manage conversation view filters with bulk operations support (see FiltersApi class for the documentation)helpers- Provide helper utilities for system maintenance (like cleaning duplicates) (see HelpersApi class for the documentation)listeners- Manage HitL event listeners (WebSocket connections, callbacks, notifications) (see ListenersApi class for the documentation)migrations- Manage database migrations and default records (see MigrationsApi class for the documentation)ruleGroups- Manage rule groups (search, create, update, delete) (see RuleGroupsApi class for the documentation)sessionEvents- Manage events for HitL sessions (retrieve, track read status, bulk operations) (see SessionEventsApi class for the documentation)sessionRelations- Manage relationships between HitL sessions (see SessionRelationsApi class for the documentation)sessions- Manage HitL session lifecycle (create, update, close, transfer, search) (see SessionsApi class for the documentation)settings- Manage system settings and configuration (see SettingsApi class for the documentation)tasks- Manage asynchronous task execution (event sending, broadcasting, etc.) (see TasksApi class for the documentation)versions- Manage UI version information and compatibility (see VersionsApi class for the documentation)
Examples
In a flow
const HitlApi = require('@or-sdk/hitl').HITL;
// with direct api url
const hitlApi = new HitlApi({
token: `FLOW ${this.config.flowToken}`,
hitlUrl: this.config.env.HITL_API_URL
});
// with service discovery(slower)
const hitlApi = new HitlApi({
token: `FLOW ${this.config.flowToken}`,
discoveryUrl: this.config.env.SERVICE_DISCOVERY_API_URL,
});
const ruleGroupsList = await hitlApi.ruleGroups.searchRuleGroups();Outside a flow
const HitlApi = require('@or-sdk/hitl').HITL;
const CLIENT_DOMAIN_PREFIX = ''; // A PDE client-environment domain prefix, e.g. "staging"
// Either "discoveryUrl" or "hitlUrl" should be specified, "hitlUrl" takes precedence if both are present
const { agents, cannedMessages, ruleGroups } = new HitlApi({
token: 'AUTH TOKEN HERE', // FLOW, SERVICE or USER JWT OneReach authorization token
discoveryUrl: `https://discovery.${CLIENT_DOMAIN_PREFIX}.api.onereach.ai`, // A service discovery URL, e.g. "https://discovery.staging.api.onereach.ai"
hitlUrl: `https://hitl.${CLIENT_DOMAIN_PREFIX}.api.onereach.ai`, // A HitL API URL, e.g. "https://hitl.staging.api.onereach.ai"
});
const agentsList = await agents.getAgents();
const cannedMessages = await cannedMessages.getCannedMessages({ id: 'MESSAGE ID HERE' });
const ruleGroupsList = await hitlApi.ruleGroups.searchRuleGroups();Additional API reference
Methods below were missing from the package guide. Signatures and return types are taken directly from the exported source API.
AppError
| Method | Returns | Purpose |
|---|---|---|
| detailsToObject() | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
EKS
| Method | Returns | Purpose |
|---|---|---|
| parseError(e: AxiosError<AppErrorObject>) | AppError | See the exported TypeScript signature for behavior and constraints. |
HITL
| Method | Returns | Purpose |
|---|---|---|
| parseError(e: AxiosError<AppErrorObject>) | AppError | See the exported TypeScript signature for behavior and constraints. |
Agents
| Method | Returns | Purpose |
|---|---|---|
| getAgents(options: GetAgentsOptions = {}) | Promise<GetAgentsResponse> | Gets a list of agents with HITL (Human in the Loop) information |
| getCompleteAgents(options: GetCompleteAgentsOptions = {}) | Promise<GetAgentsResponse> | Get Agents list with full info (additional data from Users API DB) |
| getCompleteAgentById({ accountId, multiUserId, ...options }: GetCompleteAgentByIdOptions & { accountId?: string; }) | Promise<Agent> | Get Agent with full info (additional data from Users API DB) |
| searchAgents(options: SearchAgentsOptions = {}) | Promise<SearchAgentsResponse> | Search Agents by Rule Groups, status etc. |
| updateAgent({ agentId, ...options }: UpdateAgentOptions) | Promise<UpdateAgentResponse> | Updates an agent |
| updateAgentRuleGroups({ agentId, ...options }: UpdateAgentRuleGroupsOptions) | Promise<UpdateAgentRuleGroupsResponse> | Update Rule Groups for Agent |
| updateAgentContactRuleGroups({ agentId, ...options }: UpdateAgentRuleGroupsOptions) | Promise<UpdateAgentRuleGroupsResponse> | Update Contact Rule Groups for Agent |
| getAgentStatus(options: AgentStatusOptions = {}) | Promise<GetAgentStatusResponse> | Gets agent status |
| pingAgentStatus(options: AgentStatusOptions = {}) | Promise<GetAgentStatusResponse> | Sends an agent status "ping" message to keep the agent "online" |
| setAgentStatus({ agentId, ...options }: SetAgentStatusOptions) | Promise<void> | Set Agent status |
| updateAgentsStatusByQuery({ maxRetries = 3, ...options }: UpdateAgentsStatusByQueryOptions) | Promise<void> | Update Agents status by providing a raw SQL query |
CannedMessages
| Method | Returns | Purpose |
|---|---|---|
| getCannedMessages(options: GetCannedMessagesOptions = {}) | Promise<GetCannedMessagesResponse \| CannedMessage> | Gets a list of canned messages (message templates) |
| createCannedMessage({ isCommon, agentId, ...options }: CreateCannedMessageOptions) | Promise<CannedMessage> | Creates a new canned message (message template) |
| updateCannedMessage(options: UpdateCannedMessageOptions) | Promise<CannedMessage> | Updates an existing canned message (message template) |
| deleteCannedMessage({ id, ...options }: DeleteCannedMessageOptions) | Promise<void> | Deletes a canned message (message template) |
Commands
| Method | Returns | Purpose |
|---|---|---|
| applyCommandToSession({ command, sessionId, agentId, data, ...options }: ApplyCommandOptions) | Promise<void> | Sends a command to the flow currently controlling the HitL session |
Conferences
| Method | Returns | Purpose |
|---|---|---|
| getConferenceMembers({ hitlSessionId, memberId, ...options }: GetConferenceMembersOptions) | Promise<GetConferenceMembersResponse \| ConferenceMember> | Gets a list of conference members or a specific member |
| addOrUpdateConferenceMember({ hitlSessionId, memberId, identifier, type, status, state, disconnectedAt, ...options }: AddOrUpdateConferenceMemberOptions) | Promise<ConferenceMember> | Adds or updates a conference member |
| cleanUpConference({ hitlSessionId, memberId, ...options }: CleanUpConferenceOptions) | Promise<void> | Removes conference members from a session |
ContactRuleGroups
| Method | Returns | Purpose |
|---|---|---|
| searchContactRuleGroups({ groupIdList, ...options }: SearchRuleGroupsOptions = {}) | Promise<SearchRuleGroupsResponse \| RuleGroup> | Searches for contact rule groups or retrieves specific groups |
| createContactRuleGroup({ groupId, name, rules, ...options }: CreateRuleGroupOptions) | Promise<RuleGroup> | Creates a new contact rule group |
| updateContactRuleGroup({ groupId, name, rules, ...options }: UpdateRuleGroupOptions) | Promise<RuleGroup> | Updates an existing contact rule group |
| deleteContactRuleGroup({ groupId, ...options }: DeleteRuleGroupOptions) | Promise<void> | Deletes a contact rule group |
Contacts
| Method | Returns | Purpose |
|---|---|---|
| searchContacts(options: SearchContactsOptions) | Promise<SearchContactsResponse> | Searches for contacts limited by the agent's contact rule groups |
ContactsMeta
| Method | Returns | Purpose |
|---|---|---|
| searchContactsMeta(options: SearchContactsMetaOptions) | Promise<SearchContactsMetaResponse> | Retrieves HitL-specific contact parameters (metadata) |
DraftMessages
| Method | Returns | Purpose |
|---|---|---|
| getDraftMessages(options: GetDraftMessagesOptions = {}) | Promise<GetDraftMessagesResponse \| DraftMessage> | Gets a list of draft messages |
| getDraftMessagesCount({ status, sessionId, contactIds, agentId, ...options }: GetDraftMessagesCountOptions) | Promise<GetDraftMessagesCountResponse> | Gets the count of draft messages based on specified criteria |
| createDraftMessage(options: CreateDraftMessageOptions) | Promise<DraftMessage> | Creates a new draft message |
| updateDraftMessage(options: UpdateDraftMessageOptions) | Promise<DraftMessage> | Updates an existing draft message |
| deleteDraftMessage({ id, agentId, ...options }: DeleteDraftMessageOptions) | Promise<void> | Deletes a draft message |
EventTemplates
| Method | Returns | Purpose |
|---|---|---|
| getEventTemplates({ templateId, ...options }: GetEventTemplatesOptions = {}) | Promise<GetEventTemplatesResponse \| EventTemplate> | Retrieves event templates or a specific template |
| createEventTemplate(options: CreateEventTemplateOptions) | Promise<EventTemplate> | Creates a new event template |
| updateEventTemplate(options: UpdateEventTemplateOptions) | Promise<EventTemplate> | Updates an existing event template |
| deleteEventTemplate({ templateId, ...options }: DeleteEventTemplateOptions) | Promise<void> | Deletes an event template |
Filters
| Method | Returns | Purpose |
|---|---|---|
| getFilters(options: GetFiltersOptionsV1) | Promise<GetFiltersResponseV1> | Retrieves a list of conversation view filters |
| getFilters(options: GetFiltersOptions) | Promise<GetFiltersResponse> | See the exported TypeScript signature for behavior and constraints. |
| getFilters({ id, agentId, ignoreRuleTags, ...options }: GetFiltersOptions = {}) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
| bulkGetFilters(options: BulkGetFiltersOptionsV1) | Promise<GetFiltersResponseV1> | Bulk retrieves conversation view filters, ignoring userId for personal filters |
| bulkGetFilters(options: BulkGetFiltersOptions) | Promise<GetFiltersResponse> | See the exported TypeScript signature for behavior and constraints. |
| bulkGetFilters({ ignoreRuleTags, ...options }: BulkGetFiltersOptions = {}) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
| createFilter(options: CreateFilterOptionsV1) | Promise<FilterV1> | Creates a new conversation view filter |
| createFilter(options: CreateFilterOptions) | Promise<Filter> | See the exported TypeScript signature for behavior and constraints. |
| createFilter({ isCommon, agentId, ...options }: CreateFilterOptions) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
| updateFilter(options: UpdateFilterOptionsV1) | Promise<FilterV1> | Updates an existing conversation view filter |
| updateFilter(options: UpdateFilterOptions) | Promise<Filter> | See the exported TypeScript signature for behavior and constraints. |
| updateFilter(options: UpdateFilterOptions) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
| bulkUpdateFilters(options: BulkUpdateFiltersOptionsV1) | Promise<BulkUpdateFiltersResponseV1> | Bulk updates conversation view filters |
| bulkUpdateFilters(options: BulkUpdateFiltersOptions) | Promise<BulkUpdateFiltersResponse> | See the exported TypeScript signature for behavior and constraints. |
| bulkUpdateFilters(options: BulkUpdateFiltersOptionsV1 & { filterVersion?: string; }) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
| deleteFilter(options: DeleteFilterOptionsV1) | Promise<GetFiltersResponseV1 \| FilterV1> | Deletes a conversation view filter |
| deleteFilter(options: DeleteFilterOptions) | Promise<GetFiltersResponse \| Filter> | See the exported TypeScript signature for behavior and constraints. |
| deleteFilter({ id, ...options }: DeleteFilterOptions) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
HITLBase
| Method | Returns | Purpose |
|---|---|---|
| configure(request: Request) | T | See the exported TypeScript signature for behavior and constraints. |
| format(template: string, values: Record<string, string>) | string | Function similar to "format" from Python |
Helpers
| Method | Returns | Purpose |
|---|---|---|
| deleteContactDuplicates(options: ApiVersionOptions) | Promise<CleanUpDuplicatesResponse> | Deletes duplicate contacts from Tables-based contacts (v1) |
Listeners
| Method | Returns | Purpose |
|---|---|---|
| getListeners(options: GetListenersOptions = {}) | Promise<GetListenersResponse> | Retrieves a list of HitL event listeners |
| getListenerById({ agentId, callbackId, ...options }: GetListenerByIdOptions) | Promise<GetListenersResponse> | Retrieves a specific HitL event listener by ID |
| createListener(options: CreateListenersOptions) | Promise<Listener> | Creates a new HitL event listener |
| updateListener({ callbackId, ...options }: UpdateListenersOptions) | Promise<Listener> | Updates an existing HitL event listener |
| deleteListener({ callbackId, ...options }: DeleteListenersOptions) | Promise<void> | Deletes a HitL event listener |
Migrations
| Method | Returns | Purpose |
|---|---|---|
| getListOfMigrations({ appVersion, ...options }: GetMigrationsOptions = {}) | Promise<GetMigrationsResponse> | Retrieves a list of pending migrations |
| runAllMigrations({ meta, ...options }: RunMigrationsOptions = {}) | Promise<RunMigrationsResponse> | Executes pending migrations |
| getRunMigrationsStatus(options: ApiVersionOptions = {}) | Promise<GetRunMigrationsStatusResponse> | Retrieves the current status of running migrations |
| deleteMigrationsTableLock(options: ApiVersionOptions = {}) | Promise<void> | Removes the migrations table lock that is set during migration runs |
| getMigrationsInfo(options: ApiVersionOptions = {}) | Promise<GetMigrationsInfoResponse> | Retrieves migration compatibility information with UI versions |
| getTableDefaultRecords(options: GetDefaultRecordsOptions) | Promise<GetDefaultRecordsResponse> | Retrieves default records for specific tables |
| createTableDefaultRecords(options: ApiVersionOptions = {}) | Promise<CreateDefaultRecordsResponse> | Creates default records for specific tables |
| syncTableDefaultRecords(options: SyncDefaultRecordsOptions) | Promise<SyncDefaultRecordsResponse> | Synchronizes default records for specific tables |
RuleGroups
| Method | Returns | Purpose |
|---|---|---|
| searchRuleGroups({ groupIdList, ...options }: SearchRuleGroupsOptions = {}) | Promise<SearchRuleGroupsResponse \| RuleGroup> | Searches for rule groups or retrieves specific groups |
| createRuleGroup({ groupId, name, rules, ...options }: CreateRuleGroupOptions) | Promise<RuleGroup> | Creates a new rule group |
| updateRuleGroup({ groupId, name, rules, ...options }: UpdateRuleGroupOptions) | Promise<RuleGroup> | Updates an existing rule group |
| deleteRuleGroup({ groupId, ...options }: DeleteRuleGroupOptions) | Promise<void> | Deletes a rule group |
SessionEvents
| Method | Returns | Purpose |
|---|---|---|
| getSessionEventsList(options: GetSessionEventsOptions) | Promise<GetSessionEventsResponse> | Retrieves events for a specific HitL session |
| getBulkSessionEventsList(options: GetBulkSessionEventsOptions) | Promise<GetBulkSessionsEventsResponse> | Retrieves events for multiple HitL sessions in bulk |
| addEvents({ sessionId, events, ...options }: AddEventsOptions) | Promise<AddEventsResponse> | Adds new events to a HITL session |
| getNewEventsCount({ agentId, ...options }: GetNewEventsCountOptions) | Promise<GetNewEventsCountResponse> | Retrieves count of unread events for specified sessions |
| saveReadEventByUserId({ agentId, ...options }: SaveLastReadEventOptions) | Promise<void> | Records the last read event for a specific session |
SessionRelations
| Method | Returns | Purpose |
|---|---|---|
| getSessionRelations(options: GetSessionRelationsOptions) | Promise<GetSessionRelationsResponse> | Retrieves a list of HitL session relations based on specified criteria |
| createSessionRelations(options: CreateSessionRelationsOptions) | Promise<CreateSessionRelationsResponse> | Creates new relations between HitL sessions |
| deleteSessionRelations(options: DeleteSessionRelationsOptions) | Promise<void> | Deletes specified HitL session relationships |
Sessions
| Method | Returns | Purpose |
|---|---|---|
| getSessions(options: GetSessionsOptions = {}) | Promise<GetSessionsResponse> | Retrieves a list of HITL sessions |
| getSessionById({ agentId, projection, ...options }: GetSessionByIdOptions) | Promise<Session> | Retrieves a specific HitL session by ID |
| searchSessions({ agentId, ...options }: SearchSessionsOptions = {}) | Promise<SearchSessionsResponse> | Searches for HitL sessions based on provided criteria |
| searchSessionsGroupedByContacts({ agentId, ...options }: SearchSessionsGroupedByContactsOptions) | Promise<SearchSessionsGroupedByContactsResponse> | Searches for HitL sessions based on provided criteria grouped by unique contact Ids |
| searchSessionsWithContacts({ agentId, ...options }: SearchSessionsWithContactsOptions = {}) | Promise<SearchSessionsWithContactsResponse> | Searches for HitL sessions and includes associated contact information |
| getQueueSession({ agentId, ruleTags, ...options }: GetQueueSessionOptions) | Promise<GetQueueSessionResponse> | Retrieves the next session in NEEDS_ACTION state from the queue |
| getSessionInitTriggers(options: GetInitTriggersOptions = {}) | Promise<GetInitTriggersResponse> | Retrieves available initialization triggers for starting new HitL sessions |
| claimSessionByAgent({ claimBy, params, ...options }: ClaimSessionByAgentOptions) | Promise<Session> | Claims a session for a specific agent |
| transferToBot({ agentId, params, ...options }: TransferToBotOptions) | Promise<Session> | Transfers session control back to the bot |
| startConversation({ contactId, triggerId, params, ...options }: StartConversationOptions) | Promise<Session> | Initiates a new conversation session |
| updateSession({ sessionId, tags, contactId, meta, ...options }: UpdateSessionOptions) | Promise<Session> | Updates an existing session with new information |
| createSessions({ sessions, ...options }: CreateSessionsOptions) | Promise<CreateSessionsResponse> | Creates multiple sessions in bulk |
| closeSession(options: CloseSessionOptions) | Promise<Session> | Closes an active session |
| bulkCloseSession({ sessionIds, agentId, ...options }: BulkCloseSessionOptions) | Promise<BulkCloseSessionResponse> | Closes multiple active sessions in bulk |
| reopenSession({ startedSessionId, ...options }: ReopenSessionOptions) | Promise<Session> | Reopens a previously closed session |
| deleteClosedSession(options: DeleteClosedSessionOptions) | Promise<void> | Deletes a closed session |
| buldDeleteSessions({ sessionIds, ...options }: BulkDeleteSessionsOptions) | Promise<void> | See the exported TypeScript signature for behavior and constraints. |
| bulkDeleteSessions({ sessionIds, ...options }: BulkDeleteSessionsOptions) | Promise<void> | Deletes multiple sessions in bulk |
Settings
| Method | Returns | Purpose |
|---|---|---|
| getSettings({ ignoreRuleTags = false, ...options }: GetSettingsOptions = {}) | Promise<GetSettingsResponse> | Retrieves system settings |
| getContactBookInfoSetting(options: GetContactBookInfoSettingOptions = {}) | Promise<SettingsType> | Retrieves contact book information settings using agent rule groups for triggers |
| updateSettings({ isCommon, data, settings, ...options }: UpdateSettingsOptions) | Promise<UpdateSettingsResponse> | Updates system settings |
| deleteSetting(options: DeleteSettingOptions) | Promise<GetSettingsResponse> | Deletes a specific setting |
Tasks
| Method | Returns | Purpose |
|---|---|---|
| runTask({ task, data, ...options }: RunTaskOptions) | Promise<void> | Executes a specified task with provided data |
Versions
| Method | Returns | Purpose |
|---|---|---|
| getVersionsList(options: ApiVersionOptions) | Promise<GetVersionsListResponse> | Retrieves a list of available UI versions |
| getVersionInfo(options: ApiVersionOptions) | Promise<GetVersionInfoResponse> | Retrieves detailed information about the last available version of HitL UI |
| getStepsToUIVersionsMap({ stepName, ...options }: GetStepsToUIVersionsMapOptions) | Promise<object> | Retrieves information about the compatibility of steps to UI versions |
