@myronsi/messenger-api 2.1.0-alpha.45 → 2.1.0-alpha.46.next.165

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ws-docs.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "markdown": "# WebSocket protocol (API contract v2)\r\n\r\nThe JSON Schemas in `websocket/client/` (client → server) and `websocket/server/` (server → client) are the source of truth. Every event has an example in `websocket/examples/`, validated against its schema by `npm run check`. TypeScript types are generated into `dist/ws-events.d.ts` (`ClientEvent`, `ServerEvent`).\r\n\r\n## Connecting\r\n\r\n1. `POST /api/v2/ws/ticket` (authenticated) returns `{ \"ticket\": \"…\", \"expires_in\": 30 }`. The ticket is single-use and short-lived, so no access token ends up in a URL or a log.\r\n2. Open **one connection per browser tab**: `wss://<host>/api/v2/ws?ticket=<ticket>&api_version=<contract version>`. The connection carries the events of all chats of the user. `api_version` is optional and takes the place of the `X-Client-Api-Version` header, which browsers cannot send on a WebSocket.\r\n3. The first server event is `hello` with `api_version` and `min_client_api_version`. A client that reconnects after a deploy compares them with the contract version it was built for and shows an upgrade notice instead of failing at random.\r\n4. When the ticket is invalid or expired the server closes the connection with code `4401`. A client whose `api_version` is no longer served is closed with `4426` after `hello`.\r\n\r\n## Close codes\r\n\r\n| Code | Meaning | Client |\r\n| --- | --- | --- |\r\n| `1012` | `reconnect`: the server is restarting, or it lost its pub/sub connection and events may be missing | reconnect with backoff, then load what was missed (`after` cursor) |\r\n| `1013` | the client did not keep up with its events, or sent more than 64 events that are not handled yet | reconnect, then catch up |\r\n| `4401` | invalid ticket, or the session ended (logout, revoked, password changed) | get a new ticket; if that fails, sign in again |\r\n| `4426` | the client's contract version is no longer served | show the upgrade notice |\r\n| `4429` | the user opened more than 10 connections on this server; the oldest one is closed | do not reconnect this tab automatically |\r\n\r\n## Envelope\r\n\r\nServer → client:\r\n\r\n```json\r\n{ \"type\": \"message\", \"event_id\": \"7217400317439950849\", \"chat_id\": \"42\", \"data\": { \"message\": { \"…\": \"…\" } } }\r\n```\r\n\r\nClient → server:\r\n\r\n```json\r\n{ \"type\": \"message\", \"client_temp_id\": \"c-1\", \"chat_id\": \"42\", \"data\": { \"type\": \"text\", \"content\": \"Hello!\" } }\r\n```\r\n\r\n- All IDs are strings (Snowflake IDs do not fit into a JavaScript number).\r\n- `event_id` is unique and increases per server; it is only for deduplication and logs.\r\n- `chat_id` is always `null` in `hello`, `presence` and `approval_request_created`, which do not belong to a chat. `ack` and `error` repeat the `chat_id` of the client event they answer, and it is `null` for connection-level errors.\r\n- Unknown event `type`s must be ignored by clients, so new event types are not a breaking change.\r\n- A user who is removed from a chat (or whose chat is deleted) receives `chat_deleted` and no further events of that chat.\r\n\r\n## Acknowledgements\r\n\r\nEvery client event except `typing` (which is not acknowledged and carries no `client_temp_id`) has a `client_temp_id` (1–64 characters, unique per client). The server answers with exactly one of:\r\n\r\n- `ack` — `client_temp_id`, and for `message` the stored `message_id` and `created_at`. Sending the same `client_temp_id` again returns the same `ack` (idempotent), which makes retries after a reconnect safe.\r\n- `error` — `client_temp_id` and `data.code`/`data.message`, and `data.field` when one setting or field caused it (for example `voice_video_messages`). `code` is one of the stable codes of `ErrorCode` in `openapi.yaml` (the same codes as the REST `application/problem+json` errors).\r\n\r\nThe sender also receives the broadcast `message` event with the stored message (its `client_temp_id` is included, so the client can replace its pending copy).\r\n\r\n## Client → server events\r\n\r\n| Type | Purpose |\r\n| --- | --- |\r\n| `message` | Send a message (`type` `text`, `file` or `voice`; files are referenced by `attachment_id`, never by URL) |\r\n| `resend` | Deliver a stored but undelivered message again |\r\n| `edit` | Edit your own text message |\r\n| `delete` | Delete a message for yourself (`scope: me`) or everyone |\r\n| `read` | Mark messages as read up to `message_id` |\r\n| `reaction_add`, `reaction_remove` | Add or remove a reaction |\r\n| `typing` | Typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`, not acknowledged). Repeat `is_typing: true` every 3 s while it lasts, send `false` when it ends |\r\n\r\n## Server → client events\r\n\r\n| Type | Meaning |\r\n| --- | --- |\r\n| `hello` | First event: `api_version`, `min_client_api_version`, `user_id` |\r\n| `ack`, `error` | Result of a client event, references `client_temp_id` |\r\n| `message`, `edit`, `delete` | Message created, edited or deleted; `delete` with `removed_by_moderation` when moderation removed it (the sender's copy also carries `moderation_reason`) |\r\n| `reaction_add`, `reaction_remove` | Reactions changed |\r\n| `read` | A user read up to `message_id` |\r\n| `typing` | A user is typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`); hide it after 6 s without a repeat |\r\n| `chat_created`, `chat_deleted`, `chat_list_update` | Chat list changes |\n| `history_cleared` | Messages up to `before_message_id` were cleared for you (`scope: me`) or everyone |\r\n| `pin_update` | A message was pinned or unpinned for everyone (to all members) or only for you (`scope: me`, to your own sessions); carries `pinned_message_count` for you |\r\n| `group_created`, `group_updated` | Group changes (members, roles, name, avatar) |\r\n| `approval_request_created` | New request in the inbox |\r\n| `presence` | A user came online or went offline |\n| `account_status` | Your account status changed (`AccountStatus`); only your own sessions get it |\r\n| `report_outcome` | The moderation team reviewed something you reported (`ReportOutcome`); only your own sessions get it |\r\n| `user_updated` | A user you share a chat with changed their profile (`profile_version`) |\n| `attachment_updated` | An optimized copy of an attachment you can see is ready (or failed): replace it in your messages |\n| `call_updated` | A call of the chat changed (state, participants, epoch); carries the whole call, keep the highest `version` |\n| `call_keys` | Sealed call sender keys for this session only (`docs/calls-e2ee.md`) |\r\n\r\n## Compatibility\r\n\r\nAdding an event type or an optional field is a MINOR change; removing or renaming an event or field, or making a field required, is MAJOR (see `docs/api-compatibility.md`). Clients must ignore unknown events and unknown fields.\r\n",
2
+ "markdown": "# WebSocket protocol (API contract v2)\r\n\r\nThe JSON Schemas in `websocket/client/` (client → server) and `websocket/server/` (server → client) are the source of truth. Every event has an example in `websocket/examples/`, validated against its schema by `npm run check`. TypeScript types are generated into `dist/ws-events.d.ts` (`ClientEvent`, `ServerEvent`).\r\n\r\n## Connecting\r\n\r\n1. `POST /api/v2/ws/ticket` (authenticated) returns `{ \"ticket\": \"…\", \"expires_in\": 30 }`. The ticket is single-use and short-lived, so no access token ends up in a URL or a log.\r\n2. Open **one connection per browser tab**: `wss://<host>/api/v2/ws?ticket=<ticket>&api_version=<contract version>`. The connection carries the events of all chats of the user. `api_version` is optional and takes the place of the `X-Client-Api-Version` header, which browsers cannot send on a WebSocket.\r\n3. The first server event is `hello` with `api_version` and `min_client_api_version`. A client that reconnects after a deploy compares them with the contract version it was built for and shows an upgrade notice instead of failing at random.\r\n4. When the ticket is invalid or expired the server closes the connection with code `4401`. A client whose `api_version` is no longer served is closed with `4426` after `hello`.\r\n\r\n## Close codes\r\n\r\n| Code | Meaning | Client |\r\n| --- | --- | --- |\r\n| `1012` | `reconnect`: the server is restarting, or it lost its pub/sub connection and events may be missing | reconnect with backoff, then load what was missed (`after` cursor) |\r\n| `1013` | the client did not keep up with its events, or sent more than 64 events that are not handled yet | reconnect, then catch up |\r\n| `4401` | invalid ticket, or the session ended (logout, revoked, password changed) | get a new ticket; if that fails, sign in again |\r\n| `4426` | the client's contract version is no longer served | show the upgrade notice |\r\n| `4429` | the user opened more than 10 connections on this server; the oldest one is closed | do not reconnect this tab automatically |\r\n\r\n## Envelope\r\n\r\nServer → client:\r\n\r\n```json\r\n{ \"type\": \"message\", \"event_id\": \"7217400317439950849\", \"chat_id\": \"42\", \"data\": { \"message\": { \"…\": \"…\" } } }\r\n```\r\n\r\nClient → server:\r\n\r\n```json\r\n{ \"type\": \"message\", \"client_temp_id\": \"c-1\", \"chat_id\": \"42\", \"data\": { \"type\": \"text\", \"content\": \"Hello!\" } }\r\n```\r\n\r\n- All IDs are strings (Snowflake IDs do not fit into a JavaScript number).\r\n- `event_id` is unique and increases per server; it is only for deduplication and logs.\r\n- `chat_id` is always `null` in `hello`, `presence` and `approval_request_created`, which do not belong to a chat. `ack` and `error` repeat the `chat_id` of the client event they answer, and it is `null` for connection-level errors.\r\n- Unknown event `type`s must be ignored by clients, so new event types are not a breaking change.\r\n- A user who is removed from a chat (or whose chat is deleted) receives `chat_deleted` and no further events of that chat.\r\n\r\n## Acknowledgements\r\n\r\nEvery client event except `typing` (which is not acknowledged and carries no `client_temp_id`) has a `client_temp_id` (1–64 characters, unique per client). The server answers with exactly one of:\r\n\r\n- `ack` — `client_temp_id`, and for `message` the stored `message_id` and `created_at`. Sending the same `client_temp_id` again returns the same `ack` (idempotent), which makes retries after a reconnect safe.\r\n- `error` — `client_temp_id` and `data.code`/`data.message`, and `data.field` when one setting or field caused it (for example `voice_video_messages`). `code` is one of the stable codes of `ErrorCode` in `openapi.yaml` (the same codes as the REST `application/problem+json` errors).\r\n\r\nThe sender also receives the broadcast `message` event with the stored message (its `client_temp_id` is included, so the client can replace its pending copy).\r\n\r\n## Client → server events\r\n\r\n| Type | Purpose |\r\n| --- | --- |\r\n| `message` | Send a message (`type` `text`, `file` or `voice`; files are referenced by `attachment_id`, never by URL) |\r\n| `resend` | Deliver a stored but undelivered message again |\r\n| `edit` | Edit your own text message |\r\n| `delete` | Delete a message for yourself (`scope: me`) or everyone |\r\n| `read` | Mark messages as read up to `message_id` |\r\n| `reaction_add`, `reaction_remove` | Add or remove a reaction |\r\n| `typing` | Typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`, not acknowledged). Repeat `is_typing: true` every 3 s while it lasts, send `false` when it ends |\r\n\r\n## Server → client events\r\n\r\n| Type | Meaning |\r\n| --- | --- |\r\n| `hello` | First event: `api_version`, `min_client_api_version`, `user_id` |\r\n| `ack`, `error` | Result of a client event, references `client_temp_id` |\r\n| `message`, `edit`, `delete` | Message created, edited or deleted; `delete` with `removed_by_moderation` when moderation removed it (the sender's copy also carries `moderation_reason`) |\r\n| `reaction_add`, `reaction_remove` | Reactions changed |\r\n| `read` | A user read up to `message_id` |\r\n| `typing` | A user is typing, recording a voice message, choosing a sticker or sending a photo, video or file (`action`); hide it after 6 s without a repeat |\r\n| `chat_created`, `chat_deleted`, `chat_list_update` | Chat list changes |\n| `history_cleared` | Messages up to `before_message_id` were cleared for you (`scope: me`) or everyone |\r\n| `pin_update` | A message was pinned or unpinned for everyone (to all members) or only for you (`scope: me`, to your own sessions); carries `pinned_message_count` for you |\r\n| `import_update` | An imported history of the chat started, finished or is being removed (to all members); reload the chat on `done` and `removing` |\n| `import_sender_update` | A name of an imported history was suggested for a member, declined, confirmed or withdrawn; suggestions and declines go only to the importer and that member |\n| `group_created`, `group_updated` | Group changes (members, roles, name, avatar) |\r\n| `approval_request_created` | New request in the inbox |\r\n| `presence` | A user came online or went offline |\n| `account_status` | Your account status changed (`AccountStatus`); only your own sessions get it |\r\n| `report_outcome` | The moderation team reviewed something you reported (`ReportOutcome`); only your own sessions get it |\r\n| `user_updated` | A user you share a chat with changed their profile (`profile_version`) |\n| `attachment_updated` | An optimized copy of an attachment you can see is ready (or failed): replace it in your messages |\n| `call_updated` | A call of the chat changed (state, participants, epoch); carries the whole call, keep the highest `version` |\n| `call_keys` | Sealed call sender keys for this session only (`docs/calls-e2ee.md`) |\r\n\r\n## Compatibility\r\n\r\nAdding an event type or an optional field is a MINOR change; removing or renaming an event or field, or making a field required, is MAJOR (see `docs/api-compatibility.md`). Clients must ignore unknown events and unknown fields.\r\n",
3
3
  "examples": {
4
4
  "client/delete.json": {
5
5
  "type": "delete",
@@ -520,6 +520,30 @@
520
520
  "actor_id": "7"
521
521
  }
522
522
  },
523
+ "server/import_sender_update.json": {
524
+ "type": "import_sender_update",
525
+ "event_id": "7217400317439950014",
526
+ "chat_id": "42",
527
+ "data": {
528
+ "import_id": "3",
529
+ "sender": {
530
+ "key": "s2",
531
+ "name": "Bert K.",
532
+ "message_count": 1502,
533
+ "state": "pending",
534
+ "user_id": "7"
535
+ }
536
+ }
537
+ },
538
+ "server/import_update.json": {
539
+ "type": "import_update",
540
+ "event_id": "7217400317439950013",
541
+ "chat_id": "42",
542
+ "data": {
543
+ "import_id": "3",
544
+ "state": "done"
545
+ }
546
+ },
523
547
  "server/message.json": {
524
548
  "type": "message",
525
549
  "event_id": "7217400317439950009",
@@ -1,4 +1,4 @@
1
- /* Generated from api/openapi.yaml 2.1.0-alpha.45. Do not edit. */
1
+ /* Generated from api/openapi.yaml 2.1.0-alpha.46. Do not edit. */
2
2
 
3
3
  /**
4
4
  * Any WebSocket event, in either direction.
@@ -48,6 +48,8 @@ export type ServerEvent =
48
48
  | ServerGroupUpdatedEvent
49
49
  | ServerHelloEvent
50
50
  | ServerHistoryClearedEvent
51
+ | ServerImportSenderUpdateEvent
52
+ | ServerImportUpdateEvent
51
53
  | ServerMessageEvent
52
54
  | ServerPinUpdateEvent
53
55
  | ServerPresenceEvent
@@ -137,6 +139,7 @@ export type CallIdentityKey = string;
137
139
  export type ChatType = "direct" | "group";
138
140
  export type MessageType = "text" | "file" | "voice" | "system" | "sticker";
139
141
  export type StickerPackSlug = string;
142
+ export type ImportSource = "telegram" | "whatsapp";
140
143
  export type SystemEventKind =
141
144
  | "group_created"
142
145
  | "member_added"
@@ -145,7 +148,10 @@ export type SystemEventKind =
145
148
  | "member_left"
146
149
  | "call"
147
150
  | "message_pinned"
148
- | "message_unpinned";
151
+ | "message_unpinned"
152
+ | "history_imported"
153
+ | "history_import_ended"
154
+ | "imported_note";
149
155
  /**
150
156
  * A moderator may delete other members' messages; owners and admins also manage the group.
151
157
  */
@@ -193,6 +199,21 @@ export type ErrorCode =
193
199
  *
194
200
  */
195
201
  export type PublicName = string;
202
+ /**
203
+ * The client's key for one name of the export.
204
+ */
205
+ export type ImportSenderKey = string;
206
+ /**
207
+ * `me`: the importer's own messages. `unassigned`: shown as text. `pending`: suggested for `user_id`, who has
208
+ * not answered. `confirmed`: `user_id` confirmed; the messages show their account. `declined`: the suggested
209
+ * member said no; shown as text.
210
+ *
211
+ */
212
+ export type ImportSenderState = "me" | "unassigned" | "pending" | "confirmed" | "declined";
213
+ /**
214
+ * `running`: messages are being added. `done`: finished. `removing`: being removed.
215
+ */
216
+ export type ChatImportState = "running" | "done" | "removing";
196
217
  /**
197
218
  * `me`: only for the caller. `everyone`: for every member of the chat.
198
219
  */
@@ -827,9 +848,13 @@ export interface Message {
827
848
  ];
828
849
  reactions: Reaction[];
829
850
  read_by: ReadReceipt[];
851
+ /**
852
+ * When the message was sent; for an imported message, when it was sent in the other messenger.
853
+ */
830
854
  created_at: Timestamp;
831
855
  edited_at: Timestamp | null;
832
856
  is_deleted: boolean;
857
+ import?: MessageImport;
833
858
  /**
834
859
  * `true` when moderation removed the message; it is then also `is_deleted`. Clients show "Removed by
835
860
  * moderation" instead of the deleted placeholder. Absent otherwise.
@@ -940,6 +965,25 @@ export interface ReadReceipt {
940
965
  user_id: Id;
941
966
  read_at: Timestamp;
942
967
  }
968
+ /**
969
+ * Set on messages that came from an import.
970
+ */
971
+ export interface MessageImport {
972
+ import_id: Id;
973
+ source: ImportSource;
974
+ original_at: Timestamp;
975
+ /**
976
+ * The name in the export; absent on system messages.
977
+ */
978
+ sender_name?: string;
979
+ /**
980
+ * `me`: the importer's own message, `sender` is the importer. `confirmed`: the member confirmed the name,
981
+ * `sender` is that member. `unconfirmed`: `sender` is `null`; show `sender_name` as text. Absent on system
982
+ * messages.
983
+ *
984
+ */
985
+ sender_state?: "me" | "confirmed" | "unconfirmed";
986
+ }
943
987
  /**
944
988
  * Why moderation removed something, shown only to its author.
945
989
  */
@@ -957,6 +1001,8 @@ export interface ModerationRemovalReason {
957
1001
  * are the display names at the time of the event. `target` fields are set for `member_added` and
958
1002
  * `member_removed`. `call` is set for `call` messages: one per call, posted when the call ends, `actor` is the
959
1003
  * initiator. `message_id` and `snippet` are set for `message_pinned` and `message_unpinned`.
1004
+ * `history_imported` opens and `history_import_ended` closes an imported history; both carry `import`, and
1005
+ * `actor` is the importer. `imported_note` is a line of the export that is not a message; its text is `text`.
960
1006
  *
961
1007
  */
962
1008
  export interface SystemEvent {
@@ -977,6 +1023,11 @@ export interface SystemEvent {
977
1023
  */
978
1024
  snippet?: string;
979
1025
  message_type?: MessageType;
1026
+ import?: ImportSummary;
1027
+ /**
1028
+ * The line of the export, for `imported_note`.
1029
+ */
1030
+ text?: string;
980
1031
  }
981
1032
  /**
982
1033
  * The call a `call` system message records.
@@ -990,6 +1041,13 @@ export interface CallSummary {
990
1041
  */
991
1042
  duration_seconds: number | null;
992
1043
  }
1044
+ export interface ImportSummary {
1045
+ import_id: Id;
1046
+ source: ImportSource;
1047
+ message_count: number;
1048
+ first_at: Timestamp;
1049
+ last_at: Timestamp;
1050
+ }
993
1051
  /**
994
1052
  * A chat was deleted, or you were removed from it.
995
1053
  */
@@ -1155,6 +1213,36 @@ export interface ServerHistoryClearedEvent {
1155
1213
  actor_id: Id;
1156
1214
  };
1157
1215
  }
1216
+ /**
1217
+ * A name of an imported history changed. A suggestion (pending) and a decline go only to the importer and the suggested member; that member shows the confirm banner for pending. A confirmation or its withdrawal goes to every member: render the messages of that name again (or load the chat again).
1218
+ */
1219
+ export interface ServerImportSenderUpdateEvent {
1220
+ type: "import_sender_update";
1221
+ event_id: Id;
1222
+ chat_id: Id;
1223
+ data: {
1224
+ import_id: Id;
1225
+ sender: {
1226
+ key: ImportSenderKey;
1227
+ name: string;
1228
+ message_count: number;
1229
+ state: ImportSenderState;
1230
+ user_id?: Id;
1231
+ };
1232
+ };
1233
+ }
1234
+ /**
1235
+ * An imported history of the chat started, finished or is being removed; goes to every member. On done and removing, load the chat's history again; GET /chats/{chat_id}/imports lists the imports.
1236
+ */
1237
+ export interface ServerImportUpdateEvent {
1238
+ type: "import_update";
1239
+ event_id: Id;
1240
+ chat_id: Id;
1241
+ data: {
1242
+ import_id: Id;
1243
+ state: ChatImportState;
1244
+ };
1245
+ }
1158
1246
  /**
1159
1247
  * A new message in a chat.
1160
1248
  */