# Capabilities: messages, chats, admin, HTTP, media and notifications

The v1 API grows additively. Existing methods keep their signatures; new methods are
available in Java and, through the bridge, in TypeScript.

## 1. Permission matrix

| API | Permission |
| --- | --- |
| `Messages.getMessage/getMessages/searchMessages` | `messages.read` |
| `Messages.sendText/sendMedia/sendTyping/saveDraft` | `messages.send` |
| `Messages.editText/forwardMessages` | `messages.send` + `messages.modify` |
| `Messages.deleteMessages(FOR_ME)` | `messages.modify` |
| `Messages.deleteMessages(FOR_ALL)` on own message | `messages.modify` |
| `Messages.deleteMessages(FOR_ALL)` on another sender | `messages.modify` + `chats.admin` |
| `Messages.sendReaction` | `messages.react` |
| `Messages.markAsRead` | `telegram.actions` |
| `Chats.getDialog/getDialogs/permissions` | `chats.read` |
| `Chats.getMembers` | `chats.members.read` |
| `Chats.join/leave` | `chats.join` |
| `Chats.createGroup/createChannel` | `chats.create` |
| `ChatAdmin.*` | `chats.admin` |
| `Automation.*` | `messages.automation` plus each action's permission |
| `Events.*` | matching read permission |
| `Interceptors.outgoing` | `messages.send` |
| `Interceptors.notification` | `notifications.manage` |
| `Http.request` | `network` |
| `Media.pickFile/readAsset` | `media.read` |
| `Media.sendPhoto/sendDocument/sendVoice/sendSticker` | `media.write` + `messages.send` |
| `Notifications.list` | `notifications.read` |
| `Notifications.cancel/update` | `notifications.manage` |
| `ResourcesHost.apply` | `ui.resources`; strings also `ui.strings` |
| `Screens.replace/addSlot` | `ui.screens` plus the screen content permissions |
| `InternalHost` | `internal.access` and kind `java`/`hybrid` |

`messages.background` remains known for old packages but is inert. It never grants
automation. `ChatAdmin.pinMessage` is the only pin path; `Messages` does not expose a
second pin method.

Every mutating call rejects secret chats and protected surfaces. Pinning, deleting for
all and admin actions check the signed-in account's `ChatObject` rights before the
upstream call; the server remains authoritative.

## 2. Sending and editing

```java
SendTextRequest request = SendTextRequest.builder()
        .account(account)
        .dialogId(dialogId)
        .text("Hello")
        .replyToMessageId(0)
        .silent(false)
        .origin(Origin.PLUGIN_UI)
        .build();
context.messages().sendText(request);
```

`SendTextRequest` accepts 1–4,096 UTF-16 units. `SendMediaRequest` accepts a photo,
document, voice or sticker with a caption of 0–1,024 units. Entity offsets must be
inside the text and must not overlap. Violations return `E_INVALID_ARGUMENT`.

`Origin.EVENT` and `Origin.SCHEDULE` require `messages.automation`. Rate limits per
plugin and account: sends 20/min and 500/day; edits 30/min; deletes 60/min and
2,000/day; reactions 30/min; forwards 20/min.

Pinning is an admin action:

```java
context.chatAdmin().pinMessage(account, dialogId, messageId, true);
```

## 3. Deleting

`DeleteRequest.mode` is `FOR_ME` or `FOR_ALL`. The host never silently changes the
mode. Deleting another user's message for everyone requires `messages.modify`,
`chats.admin` and a current admin right. A denial returns a clear error and changes
nothing.

`ChatAdmin.deleteMessagesForAll` and `Messages.deleteMessages(FOR_ALL)` share the
same rights check, confirmation and audit path.

## 4. Chats and members

```java
List<ChatMemberSnapshot> members =
        context.chats().getMembers(account, dialogId, 50, 0);
ChatPermissionsSnapshot rights =
        context.chats().permissions(account, dialogId);
```

Member lists are bounded and paginated. `join`/`leave` cover public groups and
channels. `createGroup` and `createChannel` require `chats.create`. The host never
bypasses a server restriction; a rejected request completes with `E_TELEGRAM` and the
Telegram error text and code.

## 5. Chat administration

`ChatAdmin` covers delete-for-all, ban, unban, kick, mute, unmute, promote, demote,
restrict, pin, unpin, title, description, photo, invite links, clear history, delete
chat and slow mode. Destructive actions require a one-time per-plugin confirmation when
automation is enabled; manual calls may show a host confirmation sheet. The manager can
revoke the confirmation.

`ChatAdmin` actions are audited with action, account, dialog id, target id, message ids
and result. Message text is never recorded.

## 6. HTTP

`Http.request` accepts HTTPS only. Request bodies are capped at 1 MB, responses at 5 MB,
headers at 50 entries and 4 KB per value. Timeouts are 10 s connect, 30 s read, 60 s
total. Redirects default to on with a maximum of 5; every redirect is re-validated and
a redirect to a private address is rejected. Loopback, link-local, private, multicast
and unspecified addresses are rejected before the connection.

Each plugin has an isolated client with no cookies, no shared cache and no automatic
authorization headers. The per-plugin limit is 60 requests/min and 1,000/day. Failures
use `E_NETWORK_POLICY` (policy) or `E_RATE_LIMIT`.

## 7. Media

`Media.pickFile` opens the host picker; `Media.readAsset` reads a packaged asset from
`assets/` with traversal protection. Sending supports photo, document, voice and
sticker with caption, reply, silent and schedule options. Calls, payments and media
streaming are out of scope.

```java
context.media().sendPhoto(SendMediaRequest.builder()
        .account(account)
        .dialogId(dialogId)
        .kind(MediaKind.PHOTO)
        .source(MediaSource.asset("assets/photo.webp"))
        .caption("From a plugin")
        .build());
```

## 8. Notifications

`Notifications.list` returns bounded snapshots with account, dialog id, title, text,
channel id and timestamp. `cancel` and `update` require `notifications.manage`. The notification interceptor can
change title, text and channel id or cancel a per-chat notification; secret-chat
notifications are never delivered to plugins.

## 9. Errors

| Code | Meaning |
| --- | --- |
| `E_PERMISSION` | Permission missing, revoked, or internal access not granted |
| `E_INVALID_ARGUMENT` | Validation failed; no state changed |
| `E_RATE_LIMIT` | Per-plugin rate limit reached |
| `E_TELEGRAM` | Telegram server rejected the operation; text and code are preserved |
| `E_NETWORK_POLICY` | URL, address, redirect or size violated the HTTP policy |
| `E_CONFIRMATION_REQUIRED` | Destructive action needs the one-time confirmation |
| `E_AUTOMATION_DISABLED` | Global automation switch is off |
| `E_UNSUPPORTED` | The host build lacks the capability |
