# Notifications, invites and the lobby

> Lia.requestNotifications, Lia.inviteFriend, Lia.inviteLink, Lia.share and Lia.lobby. From the Lia developer docs: https://docs.lialabs.org/reference/sdk-notifications-and-invites

## Notifications

Your server sends notifications with [`POST /notifications`](/reference/server-api#post-notifications). Your page only asks for permission. See [Notifications](/concepts/notifications).

### Lia.requestNotifications()

Asks the person, in Lia's own sheet, to let your app send them notifications. If they already did, it answers at once without asking.

```js
const { allowed } = await Lia.requestNotifications();
```

Resolves with `{ allowed }`. `Lia.notificationsAllowed` is updated too.

| Error | When |
| --- | --- |
| `notifications_off` | Your app may not send notifications (the Lia team turned them off for it). |
| `busy` | Another of Lia's screens is open. |

## Invites

See [Invites and links](/concepts/invites).

### Lia.inviteFriend(options)

Opens Lia's friend picker. Each friend picked gets a card in their Lia chat that opens your app with your startParam. The sheet also lets the person share your invite link anywhere.

```js
const { invited } = await Lia.inviteFriend({ startParam: "room-k3x9" });
```

| Option | Type | |
| --- | --- | --- |
| `startParam` | string | Optional. 1 to 64 of letters, digits, `_` and `-`. |
| `idempotencyKey` | string | Optional (SDK 1.5). With the same key, each friend gets that invite's card once. See [Idempotency keys](/reference/sdk-payments-and-ads#idempotency-keys). |

Resolves with `{ invited }`: `true` once anyone was invited or the link was shared. Your app never learns who.

Errors: `bad_start_param`, `bad_idempotency_key`, `busy`.

### Lia.inviteLink(startParam)

Your app's invite link, with an optional startParam. Anyone can open it: with Lia, it opens your app with the startParam; without, it points to the App Store. Call it after `Lia.init()`.

```js
const link = Lia.inviteLink("room-k3x9");
// "https://api.lialabs.org/play/your-app?start=room-k3x9"
```

Returns a string (not a promise). Throws `not_ready` before `init()` has answered, and `bad_start_param` for a startParam that doesn't fit.

### Lia.share(text)

Opens the phone's share sheet with your text, for any app on the phone. Resolves with `null` once the sheet closes.

```js
await Lia.share("I scored 1280 in Tilt Runner. Beat me: " + Lia.inviteLink());
```

| Parameter | Type | |
| --- | --- | --- |
| `text` | string | Up to 500 characters. |

Errors: `bad_text`.

## The lobby

Public tables anyone on Lia can find (SDK 1.6). Your server lists and seats them; see [Public tables](/concepts/lobby).

### Lia.lobby

#### Lia.lobby.tables(options)

The open tables in your app, newest first. Never the player's own tables, full or expired ones, or those of anyone they blocked or who blocked them.

```js
const { tables, next } = await Lia.lobby.tables({ stake: 5 });
// [{ id: "t8k2d", game: "your-app", host: { name: "amara" }, seats: 2, taken: 1, title: "Quick game", stake: 5, pot: 0, createdAt, expiresAt }]
const more = next ? await Lia.lobby.tables({ stake: 5, cursor: next }) : null;
```

| Option | Type | |
| --- | --- | --- |
| `stake` | number | Optional. Only tables at this stake, in LIA (`0` for free ones). |
| `cursor` | string | Optional. `next` from the page before. |
| `limit` | number | Optional. 1 to 50, 20 by default. |

Resolves with `{ tables, next }`: `next` is the cursor for more, or `null`. Each table:

| Field | Type | |
| --- | --- | --- |
| `id` | string | The table's id, as your server listed it. |
| `game` | string | Your app's id. |
| `host` | object | `{ name }`: the host's Lia username. |
| `seats`, `taken` | number | Seats in all, and taken (the host's included). |
| `title` | string or null | Up to 40 characters. |
| `stake`, `pot` | number | In LIA, as your server listed them (for show). |
| `createdAt`, `expiresAt` | number | Milliseconds since 1970. |

To sit, send the table's `id` to your server, which seats the player with [`POST /lobby/tables/:id/sit`](/reference/server-api#post-lobby-tables-id-sit). Someone who chose your table in Lia's own lobby arrives with `Lia.startParam` set to `lobby-<table id>`: seat them the same way.

Errors: `bad_stake`, `bad_cursor`, `bad_session` (the session couldn't be renewed), `not_in_lia`.

#### Lia.lobby.report(playerId, reason, options)

Reports a player to the Lia team. They're also blocked for the person reporting, so neither sees the other's tables again.

```js
await Lia.lobby.report("p_3f9c0a6d1b2e4f5a6b7c", "unfair", { tableId: "t8k2d", note: "Left every game when losing" });
```

| Parameter | Type | |
| --- | --- | --- |
| `playerId` | string | The player's id in your app. |
| `reason` | string | `"name"`, `"unfair"`, `"abuse"` or `"other"`. |
| `options.tableId` | string | Optional. The table it happened at. |
| `options.note` | string | Optional, up to 300 characters. |

Resolves with `{ reported: true }`. Errors: `bad_reason`, `unknown_player`, `slow_down` (more than 20 reports in a day), `bad_note`, `bad_tableId`.
