Unblu Agent Embedded JS API
    Preparing search index...

    Class UnbluPersonsApi

    This class provides functionality around persons

    Index

    Constructors

    Methods

    Constructors

    • Parameters

      • personsModule: PersonsModule
      • apiStateProvider: ApiStateProvider

      Returns UnbluPersonsApi

    Methods

    • Search for visitors based on the provided query.

      The query allows filtering by name, email, phone, username, source ID, team, authorization role and person labels, combined with AND/OR via compound filters. Results can be sorted using the orderBy parameter and paginated using offset and limit.

      The person IDs returned can be passed to UnbluAgentEmbeddedApi.startConversation as the contextPersonId.

      Parameters

      • query: PersonQuery

        The search query containing filters, ordering, and pagination options

      Returns Promise<PersonResult>

      The search result containing matching visitors

      UnbluApiError with type UnbluErrorType.ILLEGAL_STATE when the API instance is deinitialized.

      UnbluApiError with type UnbluErrorType.INVALID_FUNCTION_ARGUMENTS if a filter, an order criterion, the offset or the limit is invalid. The offset may not be negative and the limit must be between 1 and 5000.

      // Look a customer up by the identifier the host application propagates over SSO
      const result = await api.persons.searchVisitors({
      searchFilters: [
      {
      field: PersonSearchFilterField.SOURCE_ID,
      operator: {
      type: IdOperatorType.EQUALS,
      value: 'customer-4711'
      }
      }
      ],
      limit: 1
      });

      const personId = result.items?.[0]?.id;
      // Match what the agent typed against first and last name
      const result = await api.persons.searchVisitors({
      searchFilters: [
      {
      field: PersonSearchFilterField.COMPOUND,
      operator: { type: CompoundOperatorType.OR },
      searchFilters: [
      {
      field: PersonSearchFilterField.FIRST_NAME,
      operator: { type: StringOperatorType.CONTAINS, value: searchText }
      },
      {
      field: PersonSearchFilterField.LAST_NAME,
      operator: { type: StringOperatorType.CONTAINS, value: searchText }
      }
      ]
      }
      ],
      orderBy: [
      {
      field: PersonOrderByField.LAST_NAME,
      order: Order.ASCENDING
      }
      ],
      limit: 50
      });

      console.log(`Found ${result.items?.length} visitors`);
      if (result.hasMoreItems) {
      console.log(`More items available at offset ${result.nextOffset}`);
      }