Sample Code
SDK Initialization
In order to use this SDK, you must first create an SDK instance as follows:
| const adApi = window.brightpattern.AdApi(options) |
Where initialization options are as follows:
| export type InitOptions = {
integrationKey?: string adcFrame?: HTMLIFrameElement mountRoot?: HTMLElement standalone?: boolean disableNewInteractionPopup?: boolean adaptiveWidth?: boolean } |
Optional Options
- integrationKey: string - The unique ID of your CRM integration. Note that the value should remain constant. There is no need to specify anything here for custom integrations.
- adcFrame: HTMLIframeElement - The existing iframe with the Communicator Widget, that is, if it exists before the SDK is initialized.
- mountRoot: HTMLElement - The HTML node where the SDK will insert an iframe with the Communicator Widget. If the parameters were not provided, the widget’s iframe will be added to the end of the body tag.
- standalone: boolean - Set the Boolean value to true if you want the SDK to work without the Agent Desktop application’s user interface.
- disableNewInteractionPopup: boolean - Allows you to disable native popups when the agent receives incoming interactions.
- adaptiveWidth: boolean - When enabled, the widget will fit in all available space. Without this option, widget width is fixed to 500px.
Request Returns and Result Errors
Every request to the Agent Desktop application will return an answer in the following format:
| type OperationResult<ReturnType> =
{status: "success"; data: ReturnType} | {status: "error"; error: ResultError} |
Where:
| type ResultStatus = "success" | "error"
type ResultError = { code: ResultErrorCodes[keyof ResultErrorCodes] name: keyof ResultErrorCodes message?: string } type ResultErrorCodes = { not_enough_privileges: 1 not_logged_in: 2 invalid_args: 3 logged_without_phone: 4 banned: 5 api_not_answer: 6 invalid_request: 7 timeout: 8 no_chat_in_service: 9 empty_number: 10 no_service: 11 self_call: 12 no_interaction: 13 api_method_not_implemented: 14 not_suitable_state: 15 no_disposition: 16 object_not_found: 17 no_permissions_did_sms: 18 no_permissions_did_call: 19 no_channel_in_service: 20 unknown_error: 99 } |
If the requested operation is completed successfully on the Agent Desktop side, the status field of the response object will be “success” and the data will contain return value, if it should be there.
If the requested operation is completed with an error, the status field will be set to ”error”, the data will be equal to null, and the error field will contain information about the problem that occurred.