@twilio/flex-ui
Version:
Twilio Flex UI
132 lines (131 loc) • 6.84 kB
TypeScript
import { Profile } from "./flex-ui-core/src";
import { IProfileConnector } from "./internal-flex-commons/src";
import { ITask } from "./models";
/**
* The ProfileConnectorHelper class provides static methods to manage profile connectors in the Flex UI.
* It handles task support verification, context management, and operations like fetching, setting, and updating profile data.
* This class is essential for linking tasks with profile connectors across various communication channels such as SMS, email, and chat.
* @classdesc Helper class for Profile Connector.
* @category Helpers
* @class
*/
export declare class ProfileConnectorHelper {
/**
* Check if a task is supported for profile connector - call, sms, whatsapp, or email are supported
* @param {ITask} task The active task in the Flex UI
* @returns {boolean} true if the task is supported for profile connector
* @example
* import { ProfileConnectorHelper } from "@twilio/flex-ui";
* const boolAnswer = ProfileConnectorHelper.isSupportedTask(task);
*/
static isSupportedTask(task?: ITask): boolean | undefined;
/**
* Check if a task has a valid Status for linking to a profile connector - assigned or wrapping are supported
* @param {ITask} task The active task in the Flex UI
* @returns {boolean} true if the task has a valid Status for linking to a profile connector
* @example
* import { ProfileConnectorHelper } from "@twilio/flex-ui";
* const boolAnswer = ProfileConnectorHelper.isTaskValidForLinking(task);
*/
static isTaskValidForLinking(task?: ITask): boolean | undefined;
/**
* Try to find the most recent context that has profileData attributes with valid profileConnectSid and connectorName.
* If no such context is found, return the most recent context.
* @param contexts The contexts returned from the Context Service
* @private
*/
private static readonly validateAndSelectContextFromResponse;
/**
* Fetch profile connector for a task from existing Context Service, store it in the context
* @param {ITask} task The active task to which the profile connector is associated
* @returns {Promise<IProfileConnector | undefined>} The profile connector associated with the task.
* @since 2.13.0
* @example
* import { ProfileConnectorHelper } from "@twilio/flex-ui";
* const profileConnector = await ProfileConnectorHelper.fetchAndSetProfileConnectorForTask(task);
*/
static fetchAndSetProfileConnectorForTask(task: ITask): Promise<IProfileConnector | undefined>;
/**
* Set profile connector for a task in ProfileConnectorContext, and context
* @param {ITask} task The active task to which the profile connector is associated
* @param {IProfileConnector} profileConnector The profileConnector to set
* @example
* import { ProfileConnectorHelper } from "@twilio/flex-ui";
* ProfileConnectorHelper.setProfileConnectorForTask(task, profileConnector);
*/
static setProfileConnectorForTask(task: ITask, profileConnector: IProfileConnector): Promise<void>;
/**
* Fetches the profile and adds to local cache to set the display name
* @param profileConnector
* @param displayNameConfig
* @private
*/
static fetchProfileBySidAndSetDisplayName(profileSid: string, unique_name: string, taskSid: string, displayNameConfig: any): Promise<void>;
static fetchProfileByIdentifiersAndSetDisplayName(task: ITask, profileConfigSid: string, displayNameConfig: any, phoneNumberKey?: string, emailKey?: string, contextSid?: string): Promise<string | undefined>;
/**
* Grabs the display name from the profile using the traits and setting the name in ProfileConnectorContext
* @param taskSid
* @param singleProfile the profile associated with the task
* @param displayNameConfig the configuration for the display name
* @private
*/
static setProfileDisplayName(taskSid: string, displayNameConfig: any, singleProfile?: Profile): string | undefined;
/**
* Erase profileConnectSid for a task
* @param {ITask} task the task to erase profileConnectSid for
* @param {IProfileConnector} profileConnector the profileConnector to erase
* @example
* import { ProfileConnectorHelper } from "@twilio/flex-ui";
* ProfileConnectorHelper.eraseProfileConnectSidForTask(task, profileConnector);
*/
static eraseProfileConnectSidForTask(task: ITask, profileConnector?: IProfileConnector): Promise<void>;
/**
* Helper function to extract display name from profile using traits in redux
* @param {Profile} profile profile associated with Task
* @param {Object} trait trait mapping stored in redux
* @private
* @returns {string} display name of profile
*/
private static getTraitFromAdditionalAttributes;
/**
* Create and Link Context - entry point for the setup of a new Context in the case of an outbound call
* @param {ITask} task The task to create a new context for
* @param {IProfileConnector} profileConnector The profile connector to link the new context to
* @since 2.13.0
* @example
* import { ProfileConnectorHelper } from "@twilio/flex-ui";
* ProfileConnectorHelper.createAndLinkContext(task, profileConnector);
* @returns {Promise<IProfileConnector | undefined>} The profile connector with the new contextSid
* @throws {Error} if profileConnector or task is missing, or if one of the IC operations fails
*/
static createAndLinkContext(task?: ITask, profileConnector?: IProfileConnector): Promise<IProfileConnector | undefined>;
/**
* Fetch the Flex Connector Instance SID from customer-profiles /Instances mapping for the account sid
* @returns {string} profileConfigSid
* @private
*/
private static fetchProfileConfigSid;
/**
* Create new context in Context Service for a profile connector
* @param task The task to create new context for
* @param profileConnector The profile connector to create this new context for
* @private
* @throws {Error}
*/
private static createInteractionContext;
/**
* Create new context lookup sid for a task. This links a task to a context in the Context Service
* @param {string} taskSid - the active taskSid to which the new contextLookupSid is created
* @param {string} contextSid - the active Context sid that we are associating
* @private
* @throws {Error}
*/
private static createContextLookupSid;
/**
* Update profile connector sid in context
* @param profileConnector The updated profile connector with the new sid
* @private
* @throws {Error}
*/
private static updateProfileConnectorSidInContext;
}