# Your chat app

Your chat app is your people's own app for your agents: your name, your look and your sign-in, at an address of yours.
This guide explains how it works and how to set it up in your console, for the people who run it and for developers.

## Its address

- **Your address.** Your chat app is at your handle on the chat app's domain, such as `https://acme.example.com`.
  Deliver → Chat app in the console shows it, beside a copy button and "Open the app".
- **https.** It's served over https with a certificate of its own, and an `http://` address is sent there.
- **Your own domain.** An address of your own, such as `chat.yourcompany.com`, comes later.

## Opening it

Your chat app is closed until an owner or a manager opens it in Deliver → Chat app.
- **While it's closed**, its address shows "{name} isn't open yet." and signs no one in. Closing it again asks first.
- **Preview as you** opens it as you'd see it, even while it's closed. An owner, a manager or a builder can preview.
- **Its look.**
  - Its name, its welcome line, its support address (which its emails reply to), its logos for light and dark, and its
    icon are set on the same page.
  - Its colours, font and corners are your brand's (Deliver → Brand).
  - Installed on a phone or a computer, it keeps your name and icon.

## Who can join

Access → Sign-in says who can make an account:
- invited people only, the default;
- anyone;
- anyone with an address at your domains.

Access → People invites people by address.
- **An invitation.** It lasts 14 days, one an address. It can be sent again or revoked, and can put the person in
  groups as they join.
- **Where only invited people join**, the sign-in page offers no sign-up: it reads "New to {name}? Enter the address
  your invitation went to, or ask your admin for one." An address with no account that has an invitation is offered
  sign-up for it; one without reads "There's no {name} account for {email}. Ask your admin for an invitation." No code
  is sent to an address that may not join.
- **Where people at your domains join**, sign-up asks for a work email.
- **Where your identity provider makes accounts** (Access → Single sign-on, Who signs in), an address at its domains is
  sent to it to sign in, whoever may join otherwise.
- **Someone who may not join** is told before any code is sent:
  - where only invited people join: "{email} has no open invitation to {name}. Use the address your invitation went
    to, or ask your admin to send you one." An invitation that lapsed reads so too.
  - where people at your domains join: "That address isn't one {name} takes. Use your work email, or ask your admin
    for an invitation."
  - signing in through your identity provider: "Ask {name}'s admin for an invitation."

## How people sign in

The ways to sign in are an email code, a password and passkeys, each on unless you turn it off in Access → Sign-in.
- **A way that's off** reads "That way of signing in is turned off here."
- **Two-step verification** is off, required for admins (the default), or required for everyone. A person it's
  required of sets it up before their first session.
- **Single sign-on** adds your organization's own sign-in beside them (below).

People manage their own account in Settings › Security: their password, passkeys, two-step verification, their devices
and their recent activity.

## Single sign-on

Single sign-on signs your people in to the chat app with your organization's identity provider, over OpenID Connect.
Set it up in Access → Single sign-on, or in the chat app's own admin area:

1. **Add identity provider.** Give its issuer URL, such as `https://login.yourcompany.com`. Its discovery document is
   read, and must offer an authorization and a token endpoint. For a provider with no discovery document, enter its
   endpoints manually: its issuer, its authorization, token and UserInfo endpoints, and its JWKS URI.
2. **Its OAuth client.** At your identity provider, create a confidential OAuth client (an OpenID Connect application)
   for the authorization code flow, with the redirect URI and the scopes the form shows:
   - the redirect URI is your chat app's address and `/api/v1/passport/sso/callback`;
   - the scopes are `openid email profile`, and your groups claim's scope where your provider lists one;
   - its ID tokens are signed with an asymmetric key, such as RS256 or ES256, never with the client secret.

   Paste its client ID and secret, and save: they're checked at your provider's token endpoint, and the secret is never
   shown again. The provider's page opens.
3. **Who signs in**, on the provider's page.
   - **Your domains.** People whose address is at them sign in with your provider, and your provider's word on such an
     address is trusted: make sure people can't change their own email there.
   - **Required.** Such an address must use single sign-on: it reads "This address signs in with your organization's
     account." at every other way in.
   - **Accounts made.** With it on, people at your domains get an account the first time they sign in, even when only
     invited people may join.
   - **Groups.** Your provider's groups claim, picked from the claims it lists, puts each person in your groups, value
     by value, at every sign-in.
4. **Test, then turn it on.** Both are at the top of the provider's page. Test sign-in signs in through it in a window:
   you see what your provider said and what would happen, and nothing is made. Turn on is beside it once your provider
   accepts its OAuth client. A test and turning it on use what's saved, so save your changes first.

People then see "Continue with {provider}" on the sign-in page. Someone signed in this way confirms it's them through
your provider too, when "Confirm it's you" asks.

One identity provider can serve both: single sign-on to the chat app, and embed sign-in, your site's tokens for the
embed. A person known on your site and in the chat app is then one person, with one history.

## People, groups and the admin area

- **People.** Access → People lists your people and invitations. Each person is an admin or a user, can be suspended,
  restored or removed, and can belong to groups.
- **Groups.** Access → Groups holds up to 100. An agent can be narrowed to some of them, so only their people meet it.
- **The admin area.** The chat app has an admin area for your organization's IT admins, in your brand. It's Admin in
  an admin's own menu, with five sections:
  - People: your people and invitations;
  - Groups: your groups and the agents each sees;
  - Sign-in: who can join, the ways in, two-step and single sign-on;
  - Usage: the last 30 days, with no costs;
  - Activity: what changed, and who changed it.

  An admin needs two-step verification on to use the admin area, unless Access → Sign-in turns it off; one who signs in
  through single sign-on has their provider's sign-in instead. A change past the hour after their sign-in asks
  "Confirm it's you" first.

## Agents in it

- **Putting an agent in.** A published agent joins the chat app from its Share tab: "Put it in the chat app", then
  "Who sees it in the chat app", Everyone or These groups.
- **The order.** Deliver → Chat app sets the order people meet your agents in, and the agent new chats start with.
- **What people see** of an agent is what its version in use shows: its name, picture, title, description and
  starter prompts.

## What your people can do

- **Home.** It greets them, with the agent they last chose and the others. New chat (⌘⇧O on a Mac, Ctrl+Shift+O
  elsewhere) starts a chat, and Search (⌘K on a Mac, Ctrl+K elsewhere) finds one by its words.
- **History.** One history across every agent, by day. They rename, pin and delete chats, and pin the agents they use
  most. Pinned holds both.
- **Settings.** Its sections are Profile, Memory, Connected accounts, Files, Security, Appearance and Data.
  - Memory holds About you, what they tell every agent about themselves, and what each agent remembers of them, with
    Forget.
  - Data deletes every conversation, or their account.
- **The embed.** When your site and the chat app sign them in through the same identity provider (single sign-on,
  above), a conversation they had in the embed on your site is in their history too, marked "From the website".

## For developers: the routes it uses

On your chat app's address, the app calls the routes below under `/api/v1`, with the access token its sign-in issues.
They're the person routes the API host serves, each in the [API reference](https://hados.io/api/docs), taking your chat app's
tokens instead of your API keys. The sign-in itself is under `/api/v1/passport`, its discovery document at
`/api/v1/passport/.well-known/openid-configuration`.

| Route | What it is |
|---|---|
| `GET /me` | Who's signed in: their name, language, time zone, role, photo and pins |
| `GET`, `PUT /me/about` | About you |
| `PUT /me/photo` | Their photo |
| `PUT`, `DELETE /me/pins/{kind}/{id}` | A pin, of a chat or an agent |
| `GET /me/search` | Their chats by their words |
| `DELETE /me/conversations` | Every conversation of theirs, at once |
| `GET /me/memory` | What each agent remembers of them |
| `GET /me/connections` | Their connected accounts |
| `GET /me/files` | The files agents kept for them |
| `GET /agents` | The agents in the chat app they may use, in its order |
| `GET`, `POST /agents/{id}/conversations` | Their chats with an agent, and a new one |
| `GET /conversations` | Their chats with every agent |
| `/admin/…` | The admin area's routes, for admins alone |

## What goes wrong

| People read | Because |
|---|---|
| "{name} isn't open yet." | The chat app is closed: open it in Deliver → Chat app. |
| "There's no {name} account for {email}. Ask your admin for an invitation." | At the sign-in page: that address has no account and may not make one. Invite it, or widen who can join. |
| "{email} has no open invitation to {name}. …" | Only invited people join, and that address has no invitation, or its invitation lapsed after 14 days: send it again, or widen who can join. |
| "That address isn't one {name} takes. …" | Their address isn't at your domains: invite it, or add its domain in Access → Sign-in. |
| "Ask {name}'s admin for an invitation." | They may not join: invite them, or widen who can join. |
| "That way of signing in is turned off here." | The way they tried is off in Access → Sign-in. |
| "This address signs in with your organization's account." | Their address is at a domain where single sign-on is required. |
| "Confirm it's you" | An admin's sign-in is over an hour old for a change in the admin area, or a person is changing their own account. |

The admin area also says, in words, when an admin must turn two-step verification on before they can use it.
