> For the complete documentation index, see [llms.txt](https://docs.newbot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.newbot.io/use-newbot-framework-js/user-object.md).

# User object

This is an instance of the `User` class regarding the current user

### getMagicVariable ()

Get the value of a magic variable

| Parameter |   Type   |                Description |
| --------- | :------: | -------------------------: |
| `name`    | `String` | Name of the magic variable |

#### Example

```javascript
const converse = new NewBot()

converse.exec('hey', 'user id', {
    preUser(user) {
        user.getMagicVariable('text') // "hey"
    }
})
```

### setMagicVariable ()

Assign a value to a magic variable

| Parameter |   Type   |                 Description |
| --------- | :------: | --------------------------: |
| `name`    | `String` |  Name of the magic variable |
| `value`   |   `Any`  | Value of the magic variable |

#### Example

```javascript
const converse = new NewBot()

converse.exec('hey', 'user id', {
    preUser(user) {
        user.setMagicVariable('custom', 'foo')
    }
})
```

In ConverseScript

```typescript
@Intent(/hey/i)
hey() {
    > { :custom } // => "foo"
}
```

### getVariable ()

Get the value of a global variable

| Parameter |   Type   |                 Description |
| --------- | :------: | --------------------------: |
| `name`    | `String` | Name of the global variable |

### setVariable ()

Assign a value to a global variable

| Parameter |   Type   |                  Description |
| --------- | :------: | ---------------------------: |
| `name`    | `String` |  Name of the global variable |
| `value`   |   `Any`  | Value of the global variable |

### saveSession ()

Save a session

| Parameter |   Type   |                   Description |
| --------- | :------: | ----------------------------: |
| `session` | `Object` | The properties of the session |

### retrieveSession ()

Return the saved session

### setLang ()

Assign the language of the user

| Parameter |   Type   |                                          Description |
| --------- | :------: | ---------------------------------------------------: |
| `lang`    | `String` | Language to assign (example: `fr_FR`, `en_EN`, etc.) |

### getLang ()

Retrieves the user's language

### toJson ()

Returns all the data of the user in order to save his progress in the script

### fromJson ()

Restores the user's progress thanks to the JSON saved by `toJson()`

| Parameter |   Type   |   Description |
| --------- | :------: | ------------: |
| `json`    | `Object` | User progress |
