/** * `client.contextData` from `aaf_sdk.js` — `action`, `trigger`, get/update, etc. on slot **context** data. * * - **`action`**: e.g. `changeCustomer` on object `customer`. * - **`trigger`**: outbound call / add-customer flows (`dialPhone`, `dialCustomer`, …). */ export interface AafContextDataApi { get: (dataObject: string) => Promise; update: (dataObject: string, updateData: unknown) => Promise; action: (dataObject: string, actionType: string, actionData: unknown) => Promise; bulkAction?: (dataObject: string, actionType: string, ids: unknown, actionData: unknown) => Promise; bulkUpdate?: (dataObject: string, ids: unknown, updateData: unknown) => Promise; trigger: (operation: string, operationData: unknown) => Promise; } export interface HasContextData { contextData: AafContextDataApi; } /** `dataObject` string for customer context (per product docs). */ export const GwtContextDataObject = { customer: "customer" } as const; /** Actions documented on the `customer` object (`contextData.action`). */ export const GwtCustomerContextAction = { changeCustomer: "changeCustomer" } as const; /** `contextData.trigger` operation names (dial / customer flows). */ export const GwtContextDataTriggerOperation = { dialPhone: "dialPhone", dialCustomer: "dialCustomer", dialCustomerOnAltPhone: "dialCustomerOnAltPhone", /** Add customer via app — payload shape is product/version specific; use {@link contextDataTrigger} or extend types locally. */ addCustomer: "addCustomer" } as const; export type GwtContextDataTriggerOperationName = (typeof GwtContextDataTriggerOperation)[keyof typeof GwtContextDataTriggerOperation]; /** Payload for `contextData.trigger("dialPhone", operationData)`. */ export type DialPhoneOperationData = { phone: string; /** Integer-parseable id of the campaign the agent is assigned to. */ campaignId: string | number; userCrtObjectId?: string; /** Optional map for Node flow / routing. */ additionalParams?: Record; }; /** * Payload for `dialCustomer` / `dialCustomerOnAltPhone` (same keys in docs/examples). * `customerId` is Long-parseable on the server; examples often use strings. */ export type DialCustomerOperationData = { phone: string; campaignId: string | number; customerId: string | number; userCrtObjectId?: string; additionalParams?: Record; }; /** Payload for `contextData.action("customer", "changeCustomer", actionData)`. */ export type ChangeCustomerActionData = { /** Target customer id (Double in server docs → number in TS). */ customerId: number; }; /** Typical success payload for `changeCustomer` (per integration sample). */ export type ChangeCustomerResponse = { customerId: number; }; function assertNonEmpty(name: string, value: unknown): void { if (value == null || (typeof value === "string" && value.trim() === "")) { throw new Error(`${name} is mandatory for this contextData.trigger operation`); } } /** * Switches the context **customer** to the given id (e.g. after linking or selection in the host). * `client.contextData.action("customer", "changeCustomer", { customerId })` */ export function changeCustomerInContext( client: HasContextData, customerId: number ): Promise { const actionData: ChangeCustomerActionData = { customerId }; return client.contextData .action(GwtContextDataObject.customer, GwtCustomerContextAction.changeCustomer, actionData) .then((data) => data as ChangeCustomerResponse); } /** Escape hatch for other `contextData.action(dataObject, actionType, actionData)` combinations. */ export function contextDataAction( client: HasContextData, dataObject: string, actionType: string, actionData: unknown ): Promise { return client.contextData.action(dataObject, actionType, actionData); } /** * Raw `contextData.trigger(operation, operationData)`. * Success is often a **request id string** for dial operations. */ export function contextDataTrigger( client: HasContextData, operation: string, operationData: unknown ): Promise { return client.contextData.trigger(operation, operationData); } function asDialRequestId(data: unknown): string { return typeof data === "string" ? data : String(data); } /** Dial an arbitrary **phone** in the given campaign. Resolves to request id string. */ export function dialPhone(client: HasContextData, data: DialPhoneOperationData): Promise { assertNonEmpty("phone", data.phone); assertNonEmpty("campaignId", data.campaignId); return contextDataTrigger(client, GwtContextDataTriggerOperation.dialPhone, data).then(asDialRequestId); } /** Dial a **customer** line (`phone` = customer’s phone1, etc.). Resolves to request id string. */ export function dialCustomer(client: HasContextData, data: DialCustomerOperationData): Promise { assertNonEmpty("phone", data.phone); assertNonEmpty("campaignId", data.campaignId); assertNonEmpty("customerId", data.customerId); return contextDataTrigger(client, GwtContextDataTriggerOperation.dialCustomer, data).then(asDialRequestId); } /** Dial customer on an **alternate** phone number. Same payload shape as {@link dialCustomer} in product examples. */ export function dialCustomerOnAltPhone(client: HasContextData, data: DialCustomerOperationData): Promise { assertNonEmpty("phone", data.phone); assertNonEmpty("campaignId", data.campaignId); assertNonEmpty("customerId", data.customerId); return contextDataTrigger(client, GwtContextDataTriggerOperation.dialCustomerOnAltPhone, data).then( asDialRequestId ); } /** * `contextData.trigger("addCustomer", operationData)` — payload not fully specified in public snippets; * pass a map built to your Ameyo / flow contract. */ export function addCustomerThroughContext( client: HasContextData, operationData: Record ): Promise { return contextDataTrigger(client, GwtContextDataTriggerOperation.addCustomer, operationData); }