From Bright Pattern Documentation
Jump to: navigation, search
• 5.19


Sample Code

API Initialization

In order to use this API, you must first create an API 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

}

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 Agent Desktop  Communicator Widget, that is, if it exists before the API is initialized.
  • mountRoot: HTMLElement - The HTML node where the API will insert an iframe with the Agent Desktop 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 API to work without the Agent Desktop application’s user interface.


Request Returns and Result Errors

Every request to the Agent Desktop application will return an answer in the following format:

type OperationResult<ReturnType> = {

    status: ResultStatus

    data?: ReturnType

    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

    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.

< Previous | Next >