> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aide.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Control Aide Chat with JavaScript

> Once the snippet is on the page, the global Aide function controls the widget.

Once the snippet is on the page, the global `Aide` function controls the widget. Calls made before the script has loaded are queued and run when it's ready.

```js theme={null}
Aide('open')
Aide('navigate', '/articles')
Aide('on', 'message:received', (event) => console.log(event))
```

## Opening and closing

| Command | What it does |
| - | - |
| `Aide('open')` | Opens the panel |
| `Aide('close')` | Closes the panel |
| `Aide('toggle')` | Opens or closes it |
| `Aide('show')` / `Aide('hide')` | Shows or hides the whole widget |
| `Aide('chat')` | Opens straight into a chat |
| `Aide('handoff')` | Opens the widget and asks for a person, so the conversation goes straight to your team |
| `Aide('article', id)` | Opens a help article |
| `Aide('navigate', route)` | Goes to `/`, `/chat`, `/articles`, `/articles/{id}`, `/history` or `/history/{id}` |

To open the chat from your own button, call `Aide('open')` from it. Use `Aide('handoff')` for your own "Contact us" buttons: the AI doesn't answer first.

## Visitors and session data

* `Aide('identify', user)` tells Aide who the visitor is (see [Identify logged-in customers securely](/aide-chat/identify-visitors)).
* `Aide('setSessionData', attributes)` attaches extra facts to the visit, such as cart value. Proactive messages can target them.
* `Aide('logout')` forgets the visitor when they sign out of your site.
* `Aide('reset')` clears the widget's state.

## Configuration at runtime

`Aide('config', options)` changes options such as `color`, `position`, `theme`, `launcherLabel` or `hideLauncher` from code, and `Aide('setLocale', 'fr')` switches the widget's language.

## Events

Listen with `Aide('on', name, handler)`, stop with `Aide('off', name, handler)`, or listen once with `Aide('once', name, handler)`. The events are:

| Event | When |
| - | - |
| `ready` | The widget has loaded |
| `opened` / `closed` | The panel opens or closes |
| `unread:changed` | The unread count changes |
| `message:received` / `message:sent` | A message arrives or is sent |
| `conversation:started` / `conversation:ended` | A conversation starts or ends |
| `article:viewed` | A help article is opened |
| `search` | The visitor searches help articles |
| `rating:submitted` | The visitor rates a conversation |
| `campaign:shown` / `campaign:clicked` / `campaign:dismissed` | A proactive message is shown, clicked or dismissed |

For example, listen for `message:received` to update your own page when a new chat message comes in, or for `unread:changed` to show an unread badge.

`Aide('ready')` and `Aide('info')` return promises, for example to wait until the widget has loaded.

## Single-page apps

Send `Aide('event', { type: 'page-viewed', url: location.href })` when your router changes page, so proactive messages see the right URL.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.