# Telegram: when and how the bot is triggered

The ProperTrust bot is @propertrustservicebot. It can do two things for an agreement: invite single parties and let them read and sign in the private chat, or run the whole round in a group. You trigger the first by passing Telegram handles, the second with `telegram_moderate`.

## When to use it

Use Telegram when the party is easier to reach there than by e-mail, when you have no e-mail address at all, or when the parties already talk in a Telegram group. Do not use it for a wording that must stay inside ProperTrust: what the bot shows passes through Telegram (see `confidentiality`). When in doubt, pass the e-mail only.

## One to one: pass the handle

Give a party a `telegram` handle in `agreement_create` or `agreement_add_party`. `@jane_buyer`, `jane_buyer` and `t.me/jane_buyer` are all accepted. An `email` next to it is optional.

```json
{
  "title": "Purchase of concrete mixer M200",
  "wording": "## 1. Subject\n…",
  "parties": [ { "name": "Jane Buyer", "telegram": "@jane_buyer" } ]
}
```

The bot is triggered at once, and the answer tells you per party what happened, under `telegram`:

```json
"telegram": [
  { "party_id": "01…", "name": "Jane Buyer", "telegram": "@jane_buyer",
    "status": "needs_start_link",
    "start_link": "https://t.me/propertrustservicebot?start=p_…",
    "note": "The bot has never talked to this Telegram account, and Telegram does not let a bot write first. Pass the start link on; the bot takes over when the person opens it." }
]
```

| `status` | Meaning | What you do |
|---|---|---|
| `contacted` | The bot knows this account and has sent the invitation into the private chat. | Nothing. Poll `agreement_get`. |
| `needs_start_link` | The bot may not write to this account: the person never opened a chat with the bot, or blocked it. | Give the `start_link` to your principal to send to that person, in Telegram or any other way. The bot takes over the moment the person opens it. |

This limit is Telegram's, not ours: **a bot cannot start a conversation.** It is the normal case for somebody who has never used ProperTrust. So always be ready to hand out the start link.

The start link is personal like the join link: the first Telegram account that opens it takes the seat.

### What the party sees in the private chat

1. The invitation: who invites, the title, a button "Read and sign here" and a button to the website.
2. The ProperTrust terms, to accept with a button (once per Telegram account).
3. A link to connect or create a ProperTrust account (once). The party registers without a beta code and confirms its e-mail.
4. The wording, one clause per message, each with "Read and understood" and "Explain this clause".
5. The signature prompt with the document hash: "I agree and sign" or "I do not sign".
6. After completion: the link to its edition.

The party can stop and continue later with `/sign` in the chat, or switch to the website at any point; both show the same state.

### What you see

In `agreement_get`, per party: `telegram.handle`, and `telegram.state`: `not_contacted`, `contacted` (the bot wrote), `opened` (the party opened the chat and the seat is bound to that Telegram account), then the normal `status` moves through `joined`, `read`, `signed`. A signature given this way has `method: pt-telegram`.

If the owner's own account is connected to Telegram, the bot also tells the owner in the private chat when a party signs or declines.

### Triggering again

- `telegram_invite` runs the bot again for one agreement: it writes to parties it has not written to yet, and returns the status and start link of every party with a handle. With `again: true` it also repeats the invitation to parties that were contacted before.
- `agreement_remind` reminds by e-mail and through the bot.
- The bot writes to the same party at most once in six hours, however often you call.

Trigger the bot when it is needed, not on a timer: after creating the agreement (automatic), after you learn that a party has now opened the bot, and for a reminder your principal asked for.

## In a group: `telegram_moderate`

When all parties sit in one Telegram group, the bot can run the round there: it posts the PDF and every clause into the group, each member confirms and signs in the private chat, and the group sees who has signed.

Conditions:

1. The bot is a member of the group, and every member has accepted the terms in the private chat with it. `telegram_groups` shows the groups of the account and `on_the_record: true` when that is done.
2. The account behind your key is connected to Telegram and is a member of that group.
3. The agreement is `collecting` and owned by that account.

Then call `telegram_moderate` with the group id from `telegram_groups` and the agreement id. The bot writes into the group at once. The members of the group become the parties; they need no e-mail invitation.

The bot cannot be added to a group through the API. A person adds it in Telegram.

## What the bot never does

- It does not sign for anybody and does not count silence as consent.
- It does not write to an account that never opened a chat with it.
- It does not show a wording to a Telegram account that does not hold a seat.

## Evidence

A step taken in Telegram is recorded with the Telegram user id, the id of the button press and the message id, next to the time and the document hash. In a moderated group, the chat itself is kept as a hash-chained record that members can export. Identity in Telegram rests on the Telegram account and the ProperTrust account connected to it; the handle alone proves nothing, and handles can change. If it matters who exactly signs, raise `require_level` or use e-mail to an address your principal knows.
