/** * Facade over Ameyo AAF iframe SDK (`aaf_sdk.js`): `AmeyoClient.init()`, `globalData`, `globalEvent`, * `lifeCycle`, typed `interface` helpers, `httpRequest`, and `contextData` (e.g. change customer). * * Global events: `gwtGlobalEvents.ts`. Lifecycle: `gwtLifeCycle.ts`. Interface: `gwtInterface.ts`. HTTP: `gwtHttpRequest.ts`. Context: `gwtContextData.ts`. * * Reference: ECC 4.x `war/build/sdk/1.0.0/aaf_sdk.js`, `GlobalEventService`, `GlobalDataService`. */ import { GWT_ALL_GLOBAL_EVENT_NAMES, GwtGlobalEventNames, registerGlobalEvent, unregisterGlobalEvent, type HasGlobalEvent } from "./gwtGlobalEvents"; import { GwtLifeCycleEventNames, registerLifeCycleEvent, unregisterLifeCycleEvent, type HasLifeCycle } from "./gwtLifeCycle"; import type { HasInterface } from "./gwtInterface"; import type { HasHttpRequest } from "./gwtHttpRequest"; import type { HasContextData } from "./gwtContextData"; import type { HasInstance } from "./gwtInstance"; import type { HasAppConf } from "./gwtAppConf"; import type { HasAugmentModel } from "./gwtAugmentModel"; import type { HasRequest } from "./gwtRequest"; import type { HasStore } from "./gwtStore"; export { GWT_ALL_GLOBAL_EVENT_NAMES, GwtGlobalEventNames, registerGlobalEvent, unregisterGlobalEvent } from "./gwtGlobalEvents"; export type { GwtGlobalEventName, HasGlobalEvent } from "./gwtGlobalEvents"; export { GwtLifeCycleEventNames, registerLifeCycleEvent, unregisterLifeCycleEvent } from "./gwtLifeCycle"; export type { GwtLifeCycleEventName } from "./gwtLifeCycle"; export { GwtInterfaceOpenContext, GwtInterfaceTriggerOperation, interfaceOpen, interfaceTrigger, openCustomerDetail, openNewCustomerForm, openNewTicketForm, triggerDesktopNotification, triggerModalCloseConfirmation, triggerToastNotification } from "./gwtInterface"; export type { DesktopNotificationClickAction, DesktopNotificationData, DesktopNotificationIcon, GwtInterfaceOpenContextName, GwtInterfaceTriggerOperationName, ModalCloseConfirmationData, NewCustomerFormContextData, NewCustomerFormCustomerInfo, NewTicketFormContextData, NewTicketMessageInfo, NewTicketMessageType, NewTicketTicketInfo, ToastNotificationData, ToastNotificationType } from "./gwtInterface"; export { invokeAmeyoHttp, invokeAmeyoMultiPartHttp, invokeThirdPartyHttp } from "./gwtHttpRequest"; export type { AafHttpMethod, AafHttpRequestObject, AafHttpResponse, HasHttpRequest } from "./gwtHttpRequest"; export { addCustomerThroughContext, changeCustomerInContext, contextDataAction, contextDataTrigger, dialCustomer, dialCustomerOnAltPhone, dialPhone, GwtContextDataObject, GwtContextDataTriggerOperation, GwtCustomerContextAction } from "./gwtContextData"; export type { ChangeCustomerActionData, ChangeCustomerResponse, DialCustomerOperationData, DialPhoneOperationData, GwtContextDataTriggerOperationName, HasContextData } from "./gwtContextData"; export { instanceClose, instanceCreate, instanceGetAllInfo, instanceGetContext, instanceGetInfo, instanceReceiveData, instanceSendData } from "./gwtInstance"; export type { AafInstanceApi, GwtInstanceSlotType, HasInstance, InstanceCreationData } from "./gwtInstance"; export { createAppConf, deleteAppConf, getAppConf, updateAppConf } from "./gwtAppConf"; export type { AafAppConfApi, AppConfParameter, HasAppConf } from "./gwtAppConf"; export { addUserAttributes, GwtAugmentModelDataObject } from "./gwtAugmentModel"; export type { AafAugmentModelApi, AugmentData, GwtAugmentModelDataObjectName, HasAugmentModel } from "./gwtAugmentModel"; export { callRequestApi, GwtRequestApi } from "./gwtRequest"; export type { AafRequestApi, GwtRequestApiName, HasRequest } from "./gwtRequest"; export { storeDelete, storeGet, storeSet } from "./gwtStore"; export type { AafStoreApi, HasStore } from "./gwtStore"; /** * Documented data objects supported by `client.globalData.get(dataObject, [requestParams])` * (per Ameyo App SDK > globalData service docs). */ export const GWT_GLOBAL_DATA_OBJECT = { loggedInUser: "loggedInUser", selectedCampaigns: "selectedCampaigns", ticketStates: "ticketStates", customFields: "customFields", closureReasonOption: "closureReasonOption", currentManagingOrMonitoringCampaign: "currentManagingOrMonitoringCampaign", getSelectedCampaignConfiguration: "getSelectedCampaignConfiguration", getICConfigurations: "getICConfigurations", /** Requires `{ campaignId }` as the second argument. */ getAgentInteractionResourceAvailibility: "getAgentInteractionResourceAvailibility" } as const; export type GwtGlobalDataObject = (typeof GWT_GLOBAL_DATA_OBJECT)[keyof typeof GWT_GLOBAL_DATA_OBJECT]; /** * @deprecated Not a documented `globalData.get` data object — use {@link GWT_GLOBAL_DATA_OBJECT.loggedInUser}. * Kept only so older sample code does not fail to import; **do not call** with this value. */ export const GWT_DATA_OBJECT_AGENT_SESSION = GWT_GLOBAL_DATA_OBJECT.loggedInUser; /** * @deprecated `ongingCallTicket` is not a documented `globalData.get` data object. * Use the workbench `globalEvent` payloads (`callConnected`, `customerCallMemberCreated`, …) instead. */ export const GWT_DATA_OBJECT_ONGOING_CALL_TICKET = "ongingCallTicket"; export type AafGlobalDataGetArg = { dataObject: string; }; export interface AafGlobalDataApi { /** * First argument is the **data object enum string** (e.g. `"loggedInUser"`). * Optional second argument is passed as `requestParams` (e.g. `{ campaignId }` for * `getAgentInteractionResourceAvailibility`). */ get: (dataObject: string | AafGlobalDataGetArg, requestParams?: unknown) => Promise; /** `update(dataObject, updateData)` — e.g. `update("ticket", { ticketId, priority, … })`. */ update?: (dataObject: string, updateData: unknown) => Promise; /** `getTickets("getAllTickets", filter)`. */ getTickets?: (dataObject: string, filter: unknown) => Promise; /** `addNote("ticket", { ticketId, subject, description, isPrivate })`. */ addNote?: (dataObject: string, addNoteData: unknown) => Promise; /** `bulkUpdate("ticket", ids, updateData)`. */ bulkUpdate?: (dataObject: string, ids: unknown, updateData: unknown) => Promise; /** `bulkAction("ticket", actionName, ids, actionData)`. */ bulkAction?: ( dataObject: string, actionName: string, ids: unknown, actionData: unknown ) => Promise; /** `transfer("transferToAgentInQueue" | "transferToAgentQueue", actionData)`. */ transfer?: (dataObject: string, actionData: unknown) => Promise; /** `invoke("setAnswered" | "generateCRMURLTicket" | "changeStatusTicket", invokeData)`. */ invoke?: (dataObject: string, invokeData: unknown) => Promise; } export interface AafGlobalEventApi { register: (eventName: string, eventCallback: (data: unknown) => void) => Promise; unRegister: (eventName: string, eventCallback: (data: unknown) => void) => void; } export interface AafClient extends HasGlobalEvent, HasLifeCycle, HasInterface, HasHttpRequest, HasContextData, HasInstance, HasAppConf, HasAugmentModel, HasRequest, HasStore { globalData: AafGlobalDataApi; globalEvent: AafGlobalEventApi; } export interface AmeyoClientGlobal { init: () => AafClient; } declare global { interface Window { AmeyoClient?: AmeyoClientGlobal; } } export function initAafClient(): AafClient { const ac = window.AmeyoClient; if (!ac || typeof ac.init !== "function") { throw new Error("window.AmeyoClient.init is not available — load inside Ameyo GWT iframe with aaf_sdk.js"); } const client = ac.init(); if ( !client?.globalData?.get || !client?.globalEvent?.register || !client?.lifeCycle?.register || !client?.interface?.trigger || typeof client.httpRequest?.invokeAmeyo !== "function" || typeof client.httpRequest?.invoke !== "function" || typeof client.contextData?.action !== "function" || typeof client.contextData?.trigger !== "function" ) { throw new Error( "AmeyoClient.init() returned an object without globalData, globalEvent, lifeCycle, interface.trigger, httpRequest (invokeAmeyo/invoke), or contextData (action/trigger)" ); } return client; } /** Logged-in user (per Ameyo docs `globalData.get("loggedInUser")`). */ export function getLoggedInUser(client: AafClient): Promise { return client.globalData.get(GWT_GLOBAL_DATA_OBJECT.loggedInUser); } /** Selected campaigns array. */ export function getSelectedCampaigns(client: AafClient): Promise { return client.globalData.get(GWT_GLOBAL_DATA_OBJECT.selectedCampaigns); } /** * @deprecated `getAgentSession` is not a documented `globalData.get` data object — * call {@link getLoggedInUser} for the user object and {@link getSelectedCampaigns} * for assigned campaigns. */ export function getAgentSession(client: AafClient): Promise { return getLoggedInUser(client); } /** * @deprecated `ongingCallTicket` is not a documented `globalData.get` data object — * use `globalEvent` payloads (`callConnected`, `customerCallMemberCreated`, …) for the * live voice ticket. */ export function getOngoingCallTicket(client: AafClient): Promise { return client.globalData.get(GWT_DATA_OBJECT_ONGOING_CALL_TICKET); } export function onCallConnected( client: AafClient, callback: (data: unknown) => void ): Promise { return registerGlobalEvent(client, GwtGlobalEventNames.callConnected, callback); } /** Voice call cleared / hung up (ECC `GlobalEventEnum.CALL_HUNGUP`). */ export function onCallHungup(client: AafClient, callback: (data: unknown) => void): Promise { return registerGlobalEvent(client, GwtGlobalEventNames.callHungup, callback); } /** * @deprecated Prefer {@link onCallHungup}. Some older samples register `callEnded` instead of `callHungup`. */ export function onCallEnded(client: AafClient, callback: (data: unknown) => void): Promise { return registerGlobalEvent(client, GwtGlobalEventNames.callEnded, callback); } export function offCallConnected(client: AafClient, callback: (data: unknown) => void): void { unregisterGlobalEvent(client, GwtGlobalEventNames.callConnected, callback); } export function offCallHungup(client: AafClient, callback: (data: unknown) => void): void { unregisterGlobalEvent(client, GwtGlobalEventNames.callHungup, callback); } export function offCallEnded(client: AafClient, callback: (data: unknown) => void): void { unregisterGlobalEvent(client, GwtGlobalEventNames.callEnded, callback); } export function onAppModalClose( client: AafClient, callback: (data: unknown) => void ): Promise { return registerLifeCycleEvent(client, GwtLifeCycleEventNames.appModalClose, callback); } export function offAppModalClose(client: AafClient, callback: (data: unknown) => void): void { unregisterLifeCycleEvent(client, GwtLifeCycleEventNames.appModalClose, callback); } export function onAppUnload(client: AafClient, callback: (data: unknown) => void): Promise { return registerLifeCycleEvent(client, GwtLifeCycleEventNames.appUnload, callback); } export function offAppUnload(client: AafClient, callback: (data: unknown) => void): void { unregisterLifeCycleEvent(client, GwtLifeCycleEventNames.appUnload, callback); }