---
title: "Websocket"
site: api
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/api/1.11/scripting/websocket/
type: reference
application: platform
last_updated: 2026-10-19
commit: f1879fd7e955
---


`Websocket` sends a message from a server script to the browsers of signed-in users. The browser delivers it on a topic of its message bus, where a component such as the progress dialog listens. `Websocket` is a global object in server scripts, such as script libraries, jobs and system controllers.

## Get an instance

Call the methods on the global object.

```javascript
Websocket.sendMessage("example.topic", { text: "Done" });
```

## Methods

A message reaches every browser session of the user. A user who is not signed in receives nothing, and nothing is queued.

| Method | Returns | Description | Since |
| --- | --- | --- | --- |
| `sendMessage(topic: string, message: any)` | nothing | Sends the message on the topic to the user the script runs as. | 1.11 |
| `sendMessage(topic: string, message: any, responseTo: string)` | nothing | As above, marked as the response to the request ID in `responseTo`. | 1.11 |
| `sendUserMessage(userID: string, topic: string, message: any)` | nothing | Sends the message on the topic to the user with this ID. | 1.11 |
| `sendUserMessage(userID: string, topic: string, message: any, responseTo: string)` | nothing | As above, with a request ID. | 1.11 |
| `sendGlobalBroadcast(topic: string, message: any)` | nothing | Sends the message on the topic to every signed-in user. | 1.11 |

The `sendApi` variants address a named browser API instead of the message bus: `sendApiMessage(api, topic, message)`, `sendApiUserMessage(userID, api, topic, message)` and `sendApiGlobalBroadcast(api, topic, message)`. The first two also take a `responseTo` argument. Since 1.11.

## Progress dialog messages

The progress dialog listens on the topic it was opened with. A message for it can carry these keys.

| Key | Type | Description |
| --- | --- | --- |
| `percentage` | number | Progress from 0 to 100. |
| `message.text` | string | The status line under the bar. |
| `message.type` | string | The style of the status line, for example `success`. |
| `title` | string | The dialog title. |
| `complete` | boolean | `true` marks the job as finished. A `percentage` of 100 or more does the same. |

A client script opens the dialog with `Navigate.progressDialog`, giving a `title`, the `topic`, `autoClose` and a `closeCallback`.

## Examples

### Report progress to the current user

This server script reports progress while it summarises a record, for example while an [AI prompt](page:admin/sofi/ai-prompts) runs. The topic name is an example.

<CodeTabs>
  Servicely Script

  ```javascript
  const topic = "incident.ai_summarisation.progress.update";

  function sendProgressUpdate(text, percentage) {
      Websocket.sendMessage(topic, {
          message: { text: text, type: "success" },
          percentage: percentage
      });
  }

  sendProgressUpdate("Summarising incident...", 25);
  ```
</CodeTabs>

<CodeTabs>
  Response

  ```text
  The progress dialog open on this topic
  shows 25% and "Summarising incident...".
  ```
</CodeTabs>

### Open the dialog from a client script

The shipped table operations open the dialog this way. The topic comes back from the controller that starts the job.

```javascript
Navigate.progressDialog({
    title: "Summarising incident",
    topic: response.data.topic,
    autoClose: false,
    closeCallback: function () {
        Navigate.reload();
    }
});
```

## Related

- [Custom endpoints](page:rest/custom-endpoints)
- [Scripting recipes](page:scripting/recipes)
- [UI events](page:admin/automation/ui-events)
