# Messaging apps

Talk to Harness from Discord, Slack, Signal, Matrix, Microsoft Teams, WhatsApp, LINE or WeChat, as from
[Telegram](telegram.md). Each app is set up in **Settings -> Messaging** with a few fields, then linked: you send the
code shown there to the bot in a private conversation, and from then on only you (the linked owners) get answers.
Everything is off until you set it up; `maxxing messaging status|link|test|restart|on|off` does the same from a
terminal and `maxxing doctor` checks every app.

In every app: a reply to a message of a session continues that session, `/new [text]` starts one, `/sessions` lists
the recent ones, `/open N` continues one of the list, `/stop` stops the current turn, `/status` says which session you
are in, `/close` archives it and `/help` lists the commands (typed as plain text where the app has no commands of its
own). Files and voice notes work where the app sends them. Alerts with their buttons (Allow / Deny), job reports,
server problems and agent results land there too, each one switchable in the app's settings.

## One session = one place (modes Simple / Threads / Mirror)

Settings -> Messaging -> the app -> **Conversations**:

| Mode | What you get |
|---|---|
| **Simple** (default) | one conversation with the bot. A message continues the session you wrote to in the last 2 hours, else starts a new one; a reply to a message of a session continues it. Nothing is created in the app |
| **Threads** | the app mirrors the Sessions page: one **place** per open session (a channel, a room, a group or a thread, depending on the app: see the table below), plus *Crons*, *Alerts* and *Notifications* places |
| **Mirror** | the same, and every turn made elsewhere (the web UI, Telegram, another app) is copied into the session's place: your message, then the answer |

It works like the [Telegram threads](telegram.md#threads-one-per-open-session):

| You do | In the app |
|---|---|
| Open or start a session in the web UI | its place appears a few seconds later (a new session waits for its short title, up to a minute, so the place is named once) |
| Rename a session | its place is renamed (at most once every 5 minutes; changing only the project's emoji renames nothing) |
| **Archive** a session, or send `/close` in its place | the place gets "📦 Session archived: this place closes." and is closed (deleted, archived or left, depending on the app). The conversation stays in the web UI |
| Delete the place by hand in the app while the session is open | the session gets a new place (at once when the app tells the bot, else the next time something is sent to it) |
| Write in the home conversation (your private chat with the bot) | the message goes to its session as in Simple mode, is copied into that session's place, and the answer comes there ("↪ … continues in …") |
| Write in a session's place | it goes to that session: no mention of the bot needed there |
| Go back to **Simple**, or choose another kind of place | the places opened by Harness are closed (and opened again in the new kind) |

Which sessions get a place: the ones you talk to (not those started by scheduled jobs: their reports go to *Crons*),
not archived, active in the last **30 days** or running, the most recent first, up to a limit per app (below). A
session that leaves that window loses its place and gets it back when it is used again. The sync runs a few seconds
after any change and every 10 minutes; when a place cannot be made (a missing permission, no server to create it in),
Settings -> Messaging shows why.

The report places are opened the first time they are needed: **⏰ Crons** (job reports), **🚨 Alerts** (alerts and
server problems), **🔔 Notifications** (the notifications feed and agent results). In Simple mode, all of it goes to
the home conversation.

**The bell.** A session with **Notify** on: when a turn made elsewhere ends, its place (or the home conversation in
Simple mode) gets "✅ title - preview" with a link to the web UI. In Mirror mode, the copies are silent unless the
session has Notify on. A turn that came from the app itself, or from a scheduled job, is never copied back.

### What a session becomes in each app

| App | Option *Session places* | A session is | Closing it | At most |
|---|---|---|---|---|
| [Discord](#discord) | `channels` (default) | a private text channel in the category of its project (the reports in a "Harness Maxxing" category) | the channel is deleted | 45 |
| | `forum` | a post in a private forum "harness-maxxing" of that category | the post is archived and locked | 50 |
| | `threads` | a thread in a server text channel | the thread is archived and locked | 50 |
| [Slack](#slack) | `channels` (default) | a private channel (`hm-…`), you invited | the channel is archived | 50 |
| | `threads` | a thread in your conversation with the bot | its first message is marked archived | 50 |
| [Signal](#signal) | `groups` (default) | a Signal group (in your chat list) | you are removed, the bot leaves the group | 30 |
| | `none` | no places: Simple or Mirror only | | |
| [Matrix](#matrix) | `rooms` (default) | a room in the space of its project, inside a private space "Harness Maxxing" | the room leaves the space, you are removed, the bot leaves | 50 |
| | `threads` | a thread in your room with the bot | its first message is marked archived | 50 |
| [Teams](#teams) | `posts` (default) | a post in one channel of a team | its first message is marked archived (a bot cannot delete posts) | 50 |
| | `channels` | a standard channel of that team | the channel is deleted | 50 |
| [WhatsApp](#whatsapp), [LINE](#line), [WeChat](#wechat) | | no places: Simple or Mirror only | | |

The places are private: only the linked owners and the bot are in them (Teams: a channel is as private as its team).

Grouped by project: on Discord (`channels`) each project gets its own category, and on Matrix (`rooms`) its own space
inside "Harness Maxxing"; the report places (jobs, alerts, notifications, Jarvis) stay in "Harness Maxxing". A place
made before, or one whose project was renamed, is moved there (the same channel or room, its history kept), and a
project category or space that no open session uses any more is removed. The other apps have nothing a bot can group
places in: Slack sections, Signal folders and Telegram have no API for it, Teams channels have no folders, and
WhatsApp, LINE and WeChat have no places at all.

**WhatsApp, LINE and WeChat** have no threads, and a bot cannot create private groups there, so they keep one
conversation: the **Threads** mode is not offered. **Mirror** works: each turn made elsewhere is copied into that
conversation under the session's title in bold, and a reply to the copy continues that session (WeChat has no
replies: a message continues the last session you wrote to in the last 2 hours; `/open N` picks another one).

## Discord

Setup (Settings -> Messaging -> Discord):

1. https://discord.com/developers/applications -> **New Application**.
2. **Bot -> Reset Token**: paste the token in **Bot token**.
3. **Bot -> Privileged Gateway Intents -> Message Content Intent**: on (without it Discord refuses the connection).
4. Open the **invite link** shown in Settings to add the bot to your server, then send it the link code in a direct
   message.

For the session places the bot needs the permission **Manage Channels**. A bot added before this version does not
have it: open the invite link of Settings -> Messaging -> Discord again and accept (the error shown says so too).

- **Server id**: only when the bot is in several servers, the one where the session channels go (Discord: right click
  the server -> Copy Server ID, with Developer Mode on).
- **Session places**: `channels` (one private channel per session, like Telegram's threads), `forum` or `threads`.
  Each project gets a private category (named like the project, with its emoji), its sessions' channels inside
  without the project in their name (`blog-plan-the-launch`); the report channels are in the "Harness Maxxing"
  category. @everyone cannot see these categories nor their channels; the bot and you can. A channel you create
  yourself in the "Harness Maxxing" category becomes the place of a new session; a session channel you move out of
  these categories stays where you put it. At most 45 sessions get a channel (the most recent), so no category goes
  over Discord's 50 channels.
- **Thread channel id**: `threads` only, the server text channel the session threads open in (empty: the home
  conversation, which must then be a server channel: Discord has no threads in direct messages).

Slash commands `/new`, `/sessions`, `/open`, `/stop`, `/status`, `/close` and `/help` work everywhere, `/close` in a
session channel included.

## Slack

Setup: api.slack.com/apps -> **Create New App -> From a manifest**, paste the manifest shown in Settings ->
Messaging -> Slack, **Install to Workspace**, then paste the **Bot token** (`xoxb-…`) and an **App-level token**
(`xapp-…`, Basic Information -> App-Level Tokens, scope `connections:write`). Send the link code to the bot in a
direct message (Slack sidebar -> Apps -> Harness Maxxing). No public address needed (Socket Mode).

The session places need new permissions (scopes). An app installed before this version: open Settings -> Messaging
-> Slack, copy the manifest, paste it in api.slack.com/apps -> your app -> **App Manifest**, Save, then **reinstall**
the app to the workspace (the error "reinstall the app with the new manifest" says the same).

- **Session places**: `channels` (default: a private channel per session, named from the session, its topic and
  purpose giving the project, topic and web link; you are invited) or `threads` (a thread per session in your
  conversation with the bot).
- Commands: `/harness <command>` (for example `/harness sessions`; `/harness close` in a session channel archives it).
  Slack runs no slash command inside a thread: there, write `!close` (or `@Harness Maxxing /close`).
- Archiving or deleting a session channel in Slack, or removing the bot from it, gives the session a new one while
  it is open.

## Signal

Harness runs signal-cli on the server (downloaded and checked on first use; not available on arm64 servers). Two
ways to connect (**Connection**):

- `link` (recommended): Harness becomes a linked device of a Signal account, by QR code (Signal -> Settings ->
  Linked devices -> Link new device). Best with a **second number** for Harness: you write to that number from your
  own Signal and link with the code shown in Settings. Your own account works too: then you talk to Harness in
  **Note to Self**, and Harness ignores your other chats.
- `register`: a spare number registered by Harness itself (a captcha when Signal asks for one, then the SMS code).

**Session places** (`groups` by default): Signal has no threads, so each open session gets a **Signal group** of its
own (name = the session title cut to 32 characters, description = where it lives and its web link), at most 30 since
each one shows in your chat list. `none` keeps one conversation (Simple or Mirror only). Leaving or deleting a
session's group gives the session a new one while it is open.

With your own account (link + Note to Self), the groups have you as their only member and Harness writes in them as
you: your phone does not ring for its answers. To be notified, use a second number for Harness.

## Matrix

Setup: a separate Matrix account for the bot (matrix.org or your own server). Give its **Homeserver**, its **Bot user
id** (`@name:server`) and its password (used once; only the resulting token is kept) or an access token. From your
own account, start a direct message with the bot, **end-to-end encryption off**, and send it the link code.

Harness cannot read end-to-end encrypted rooms: in one, the bot posts one notice and ignores the room.

- **Places** `rooms` (default): the bot creates a private space **Harness Maxxing** and invites you once: **accept
  the invitation of the space**. Each project gets a space inside it (you are invited too), each session a room of
  its project's space (named without the project), without encryption; join it from the space (Element lists it there) or accept its invitation. Closing a session takes its room out of the space and removes
  you (Element keeps it greyed with **Forget**, its history readable).
- When your homeserver turns encryption on in every new private room, one room per session is not possible: the
  error says so; choose `threads` (or, on your own Synapse, change `encryption_enabled_by_default_for_room_type`).
- **Places** `threads`: one thread per session in your room with the bot.
- No buttons on Matrix: answer a choice with its number, or react 1️⃣ 2️⃣… (👍 = 1, 👎 = 2) on the bot's message.

## Teams

Setup: an **Azure Bot** (Single Tenant) whose messaging endpoint is the address shown in Settings -> Messaging ->
Teams (the server needs a public HTTPS address), its **Microsoft App ID**, a **Client secret** and the **Tenant ID**.
Download the **Teams app package** from Settings and upload it in Teams (Apps -> Manage your apps -> Upload an app),
open the bot in a personal chat and send it the link code.

Personal chats have no threads, so the session places live in a team:

1. Add the app to a team (best: a team of your own: its members see the session posts or channels).
2. **Mention the bot once** in the channel where the sessions should go, or paste that channel's link in **Channel
   for the sessions** (… next to the channel -> Get link to channel).

- **Session places** `posts` (default): one post per session in that channel. Replies in a post reach Harness
  without mentioning the bot thanks to a permission of the app package (`ChannelMessage.Read.Group`): a package
  downloaded before this version lacks it, so download it again and update the app in Teams (Apps -> Manage your
  apps).
- **Session places** `channels`: one standard channel per session in that team. After choosing it, **download the
  app package again**, update the app in Teams and, as an owner of the team, accept its channel permissions
  (`Channel.Create.Group`, `ChannelSettings.ReadWrite.Group`, `Channel.Delete.Group`); your admin may have to allow
  resource-specific consent for apps. Private channels are not used (bots get no messages there).

Sending files is not available on Teams yet.

## WhatsApp

Two ways to connect (**Connection**):

- `cloud` (recommended): the official WhatsApp Cloud API of Meta (a business number of a Meta app), with Harness's
  webhook address (needs a public HTTPS address). Meta lets a business write first only within 24 hours of your last
  message: Harness answers, but cannot start a conversation after that.
- `web`: your own number as a linked device (WhatsApp -> Settings -> Linked devices -> Link a device, scan the QR
  code). Unofficial: WhatsApp may ban numbers that use it. You talk to Harness in **Message yourself**; every other
  chat is ignored and Harness never writes to your contacts.

One conversation only: Simple or Mirror (see [above](#what-a-session-becomes-in-each-app)).

## LINE

A Messaging API channel of a LINE Official Account, with Harness's webhook address (needs a public HTTPS address).
The first answer to a message is free; anything else (the next parts of a long answer, a late answer, alerts and
reports) counts against the monthly message quota of the Official Account's plan, and LINE refuses once it is used
up. Buttons are quick replies under the last message. Files and audio answers are not sent.

One conversation only: Simple or Mirror (see [above](#what-a-session-becomes-in-each-app)).

## WeChat

Personal WeChat, through Tencent's iLink bot API: scan the QR code of Settings -> Messaging -> WeChat with WeChat;
whoever scans it becomes the owner (no link code). When the bot's session expires, scan again. No buttons: answer a
choice with its number.

One conversation only: Simple or Mirror (see [above](#what-a-session-becomes-in-each-app)).
