> Documentation index: https://docs.dev.repp.co.il/llms.txt - fetch it to find every page of these docs.

# Messenger SDK

```html
<script src="https://embed.dev.repp.co.il/v1/repp-embed.js"></script>
```

Plain JavaScript with no dependencies. It reads nothing of your page but the elements you give it, and draws its button in a shadow root of its own, so your styles and Repp's never meet.

## ReppEmbed.load

**Load options**

| Option | Type | Description |
| --- | --- | --- |
| `publishableKey` | string | Your `rpk_…` key. Required. |
| `fetchClientSecret` | `({ component, classId }) => Promise<string>` | Required. Called for every frame Repp loads and whenever a session runs out: ask your server for a [session](https://docs.dev.repp.co.il/partners-sessions.md) and return its `client_secret`. |
| `embedOrigin` | string | Repp's embed host. Defaults to where the script came from. |

It answers an instance: `boot`, `mount`, `open`, `on` and `destroy`. `ReppEmbed.version` is the script's version.

## boot(options)

Draws the button and loads the panel, hidden, and answers the messenger. One per instance: a second `boot` answers the same one.

**Boot options**

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `alignment` | `"left"` or `"right"` | `"left"` | Which bottom corner the button floats in. Left is the end side of a Hebrew page. |
| `horizontalPadding` | number (px) | `20` | From the page's side edge. |
| `verticalPadding` | number (px) | `20` | From the page's bottom edge. |
| `hideLauncher` | boolean | `false` | No floating button: you open the panel yourself, with your own button or `show()`. |
| `customLauncherSelector` | CSS selector | — | Your own buttons that open and close the panel. Each gets `aria-expanded`, the button's count (what waits and what is new) as `data-repp-waiting`, and of it what is new as `data-repp-unread`, so you can draw a badge. |
| `zIndex` | integer | `2147483000` | The button's and the panel's stacking order. |

## The panel

Three tabs at the panel's foot, as in Intercom's Messenger (Home, Messages, Help): Home to start something, Activity to follow each class and space as a conversation, Account for the business's card in Repp and the connection. Each tab keeps its own screens: back returns within the tab, switching tabs keeps each one where it was, and pressing the tab already open returns it to its first screen. Until the business is connected the panel is only the connect card, with no tabs.

**Tabs**

| Tab | showSpace | What it holds |
| --- | --- | --- |
| Home | `home` | A greeting and two big actions, one under the other: a substitute trainer for one of your classes (pick the class, then its request's steps), and renting out a space (the business's spaces and your rooms, each opening its screen or opening for rent). Under them what waits for the business (offers to choose from, booking requests to approve), at most three, as the same rows as Activity's, each opening its class or space inside this tab. |
| Activity | `activity` | Conversations, as Intercom's Messages: one row per item, a class asked for a substitute trainer or a space, never a feed of lines. A row leads with a picture (the faces of the trainers who answered, the chosen trainer's face, the style's object while nobody answered yet, or the space's photo), then its name, one short line of what happened last, its time, a dot on what this person has not seen, and a small red pill when it waits for the business ("to choose", "to approve"). Two chips filter it (substitute trainers, spaces); what waits comes first, then the newest. A row opens the item inside this tab: a short timeline of what happened to it, then its one action. The tab carries the count of what is new, and opening it marks it seen. |
| Account | `account` | The business's card in Repp, as trainers see it in Repp's index (its photo, name, rating and town), with what is still missing by name; then the card's parts (name, photo, a few words, styles, what the place has, where it is), each edited in a small screen inside this tab, by the same rules as on Repp's own site. An `owner` or a `manager` edits, `staff` read. Under it the connection: the Repp business and since when, who is here (the person and role you sent), the text messages switch, disconnecting (an owner only) and help. |

`showSpace(space)` opens the panel at one of these places. `requests` and `updates`, the names of the panel's earlier tabs, still work and open Activity.

**showSpace**

| space | Opens |
| --- | --- |
| `home` | The Home tab, on its first screen. |
| `activity` | The Activity tab, on its list. Marks what is new as seen. |
| `account` | The Account tab, on the business's card in Repp. |
| `spaces` | The spaces screen over Home: the business's spaces on Repp, then your rooms to open for rent. Back returns to Home. |
| `requests` | An older name: opens Activity, as `activity` does. |
| `updates` | An older name: opens Activity, as `activity` does. |

**The business's card.** The Account tab opens on the business as Repp's index shows it to trainers, and edits it in place: the name, the photo, a few words (up to 400 characters, never a phone, an email or a link: Repp refuses them with its own words), the styles held there, what the place has, and where it is (a region and an address). It is the same card the business edits on Repp's own site, saved by the same rules; nothing of it reaches your page or your server, and there is no need to send the business to Repp's site for it.

**Text messages.** The Account tab has one switch: a text message to the business when something closes on a class or room that came from your system. It is on by default; an `owner` or a `manager` changes it, `staff` read it. Phone notifications are set in the business's own account on Repp. Nothing of it reaches your page or your server.

**Disconnecting.** Only an `owner` sees it, quiet, and confirms it in place. Your system then stops seeing Repp's states (your page hears `disconnected`); nothing in Repp is deleted, and requests already posted stay in Repp.

## The messenger

**Methods**

| Method or property | What it does |
| --- | --- |
| `show()` | Opens the panel where it was. |
| `hide()` | Closes it. Escape on the page and the button close it too. |
| `toggle()` | Opens or closes it. |
| `showSpace(space)` | Opens the panel at one of its places (see The panel, above): `home`, `activity`, `account`, `spaces`, `requests`, `updates`. Opening `activity` marks what is new as seen. |
| `showSubstitute(classId)` | Opens the panel on one of your classes (`partner_class_id`), over the Activity tab's list (back returns to it): its request, or asking for a substitute trainer for it. A class the session does not hold makes the panel ask `fetchClientSecret` once for a new session, so your server sends the class. |
| `isOpen` | Whether the panel is open (read only). |
| `waitingCount` | The count on the button (read only): what waits for the business (classes with offers to choose from, booking requests of its spaces waiting for its yes) and what happened on its classes and rooms that this person has not seen yet. Opening the panel's Activity tab clears what is new. |
| `on(name, listener)` | Listens to an [event](https://docs.dev.repp.co.il/partners-events.md). Returns a function that stops listening. |
| `shutdown()` | Removes the button and the panel, for a person who signs out. `boot()` brings them back. |

## As markup

`<repp-messenger>` boots the messenger once `ReppEmbed.load` ran, and shuts it down when it leaves the page. Its attributes: `alignment` (`left` or `right`) and `hide-launcher`.

```html
<repp-messenger alignment="left"></repp-messenger>
```

## Components

Before the messenger, Repp Embed had three single components. They still work, each with a [session](https://docs.dev.repp.co.il/partners-sessions.md) of its own:

**Components**

| Component | In code | As markup | What it is |
| --- | --- | --- | --- |
| `connect` | `repp.mount("connect", element)` | `<repp-connect>` | The card of your system's connected apps: connect, and a quiet disconnect. |
| `class-status` | `repp.mount("class-status", element, { classId })` | `<repp-class-status class-id="…">` | A chip on a class in your calendar, saying where its request stands. A click opens `substitute`. |
| `substitute` | `repp.open("substitute", { classId, returnFocus })` | `<repp-substitute class-id="…">` | A window over the page to ask for a substitute trainer for one class. With the messenger booted, the button opens the panel on that class instead. |

`mount` and `open` answer a handle with `on` and `unmount`; `repp.destroy()` removes everything, for a single-page app.
