# WIDGET API

### Access to API

After the button is uploaded, the callback feature is called`$owidgetOnLoad`. You can call the API feature using the`owidget`object.

```html
<script type="text/javascript">
  (function () {
    var scr = document.createElement('script');
    scr.type = 'text/javascript';
    scr.async = true;
    scr.charset = 'UTF-8';
    scr.src = '//app.mluvii.com/widget/OOWidget.js';
    scr.$owidgetOnLoad = function (owidget) {
      if (!owidget.isSupported) {
        return;
      }
      // owidget.init(...);
      // ...
      // owidget.connectToServer();
    };
    var ffs = document.getElementsByTagName('script')[0];
    ffs.parentNode.insertBefore(scr, ffs);
  })();
</script>
```

## Api feature

### `init`

#### Syntax

`owidget.init(companyId, [widgetPreset], [language], [scope]);`

#### Parameters

* `companyId`GUID identifying the company.
* `widgetPreset`Widget name. If the parameter is missing, the default widget is used.
* `language`Widget language. **If the parameter is missing, other parameters are used, see below:**
* `scope` Optional parameter. On initialization, the widget will try to restore possible active conversation only if it was started in a widget initialized with the same `scope` parameter.

{% hint style="success" %}
The language is determined:

1. by owidget.init - language parameter&#x20;
2. if empty, by the language of the page (header language - F12 - Elements)&#x20;
3. if not specified, then the browser language is used
   {% endhint %}

### `connectToServer`

It uploads the configuration from the server and starts tracking the status of the operator groups.

#### Syntax

`owidget.connectToServer();`<br>

### `setAppEventCallback`

Sets the callback feature to track defined events.

#### Syntax

`owidget.setAppEventCallback(callback);`

#### Parameters

* `callback`Callback function:`function (e) {}`. The feature will be called each time one of the defined events occurs. The feature parameter`E`will contain a structure describing an event with elements:
* `type`Event type.

#### Event Types

* `chatWindowOpen` Chat window open.
* `chatWindowClosed` Chat window closed.
* `chatSessionCreated` The client waits for the operator.
* `chatSessionStarted` Session with the operator began.
* `chatSessionEnded` The session is over.<br>

### `setStatusUpdateCallback`

Sets the callback feature to monitor the status of the button.

#### Syntax

`owidget.setStatusUpdateCallback(callback);`

#### Parameters

* `callback`Callback feature:`function (code) {}`. The feature will be called each time the button status changes. The parameter`code`acquires one of the three values described below.

#### Button status codes

* `0` the button is “offline”
* `1` the button is “online”
* `2` the button is “busy”

### `setCustomNumberNormalization`

Sets the custom function to normalize phone number

#### Syntaxe

`owidget.setCustomNumberNormalization(callback);`

#### Parameters

* `callback` Callback function: `function (phoneNumber) { }`. The function will replace the default phone number normalisation function

#### Expected return values

* `null` If the number is in a non-invalid format, the function should return null
* `Normalize phone number` If the entered number is in the correct format, the string with the phone number in the international format is returned, eg even +420 777 666 555 even if the entry was only 777 666 555


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mluvii.com/en/for-it-specialists/widget-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
