@shhhum/simplex-chat 0.0.0-stage → 7.1.0-beta.6.1

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.
Files changed (105) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +129 -2
  3. package/dist/api.d.ts +439 -0
  4. package/dist/api.js +911 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/bot.d.ts +34 -0
  7. package/dist/bot.js +194 -0
  8. package/dist/bot.js.map +1 -0
  9. package/dist/cli.d.ts +4 -0
  10. package/dist/cli.js +46 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/core.d.ts +138 -0
  13. package/dist/core.js +144 -0
  14. package/dist/core.js.map +1 -0
  15. package/dist/index.d.ts +19 -0
  16. package/dist/index.js +23 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/libs.d.ts +12 -0
  19. package/dist/libs.js +210 -0
  20. package/dist/libs.js.map +1 -0
  21. package/dist/release.d.ts +5 -0
  22. package/dist/release.js +20 -0
  23. package/dist/release.js.map +1 -0
  24. package/dist/simplex.d.ts +12 -0
  25. package/dist/simplex.js +22 -0
  26. package/dist/util.d.ts +15 -0
  27. package/dist/util.js +91 -0
  28. package/dist/util.js.map +1 -0
  29. package/docs/Namespace.api.md +33 -0
  30. package/docs/Namespace.bot.md +24 -0
  31. package/docs/Namespace.core.md +50 -0
  32. package/docs/Namespace.util.md +25 -0
  33. package/docs/README.md +12 -0
  34. package/docs/api.Class.ChatApi.md +1851 -0
  35. package/docs/api.Class.ChatCommandError.md +205 -0
  36. package/docs/api.Enumeration.ConnReqType.md +27 -0
  37. package/docs/api.Interface.BotAddressSettings.md +60 -0
  38. package/docs/api.TypeAlias.DbConfig.md +62 -0
  39. package/docs/api.TypeAlias.EventSubscriberFunc.md +31 -0
  40. package/docs/api.TypeAlias.EventSubscribers.md +11 -0
  41. package/docs/api.Variable.defaultBotAddressSettings.md +11 -0
  42. package/docs/bot.Function.run.md +21 -0
  43. package/docs/bot.Function.subscribeChatItems.md +27 -0
  44. package/docs/bot.Interface.BotConfig.md +87 -0
  45. package/docs/bot.Interface.BotOptions.md +81 -0
  46. package/docs/bot.TypeAlias.BotDbOpts.md +21 -0
  47. package/docs/core.Class.ChatAPIError.md +205 -0
  48. package/docs/core.Class.ChatInitError.md +205 -0
  49. package/docs/core.DBMigrationError.Interface.ErrorMigration.md +41 -0
  50. package/docs/core.DBMigrationError.Interface.ErrorNotADatabase.md +33 -0
  51. package/docs/core.DBMigrationError.Interface.ErrorSQL.md +41 -0
  52. package/docs/core.DBMigrationError.Interface.InvalidConfirmation.md +25 -0
  53. package/docs/core.DBMigrationError.Interface.InvalidQueueSize.md +25 -0
  54. package/docs/core.DBMigrationError.TypeAlias.Tag.md +11 -0
  55. package/docs/core.Enumeration.MigrationConfirmation.md +43 -0
  56. package/docs/core.Function.chatCloseStore.md +23 -0
  57. package/docs/core.Function.chatDecryptFile.md +31 -0
  58. package/docs/core.Function.chatEncryptFile.md +31 -0
  59. package/docs/core.Function.chatMigrateInit.md +37 -0
  60. package/docs/core.Function.chatReadFile.md +27 -0
  61. package/docs/core.Function.chatRecvMsgWait.md +27 -0
  62. package/docs/core.Function.chatSendCmd.md +27 -0
  63. package/docs/core.Function.chatWriteFile.md +31 -0
  64. package/docs/core.Function.loadLibrary.md +24 -0
  65. package/docs/core.Interface.APIResult.md +31 -0
  66. package/docs/core.Interface.CryptoArgs.md +27 -0
  67. package/docs/core.Interface.UpMigration.md +25 -0
  68. package/docs/core.MTRError.Interface.MTREDifferent.md +33 -0
  69. package/docs/core.MTRError.Interface.MTRENoDown.md +33 -0
  70. package/docs/core.MTRError.TypeAlias.Tag.md +11 -0
  71. package/docs/core.MigrationError.Interface.MEDowngrade.md +33 -0
  72. package/docs/core.MigrationError.Interface.MEUpgrade.md +33 -0
  73. package/docs/core.MigrationError.Interface.MigrationError.md +33 -0
  74. package/docs/core.MigrationError.TypeAlias.Tag.md +11 -0
  75. package/docs/core.Namespace.DBMigrationError.md +19 -0
  76. package/docs/core.Namespace.MTRError.md +16 -0
  77. package/docs/core.Namespace.MigrationError.md +17 -0
  78. package/docs/core.TypeAlias.Backend.md +11 -0
  79. package/docs/core.TypeAlias.DBMigrationError.md +11 -0
  80. package/docs/core.TypeAlias.MTRError.md +11 -0
  81. package/docs/core.TypeAlias.MigrationError.md +11 -0
  82. package/docs/util.Function.botAddressSettings.md +21 -0
  83. package/docs/util.Function.chatInfoName.md +21 -0
  84. package/docs/util.Function.chatInfoRef.md +21 -0
  85. package/docs/util.Function.ciBotCommand.md +21 -0
  86. package/docs/util.Function.ciContentText.md +21 -0
  87. package/docs/util.Function.contactAddressStr.md +21 -0
  88. package/docs/util.Function.fromLocalProfile.md +21 -0
  89. package/docs/util.Function.reactionText.md +21 -0
  90. package/docs/util.Function.senderName.md +25 -0
  91. package/docs/util.Interface.BotCommand.md +25 -0
  92. package/examples/squaring-bot-readme.js +17 -0
  93. package/examples/squaring-bot.ts +42 -0
  94. package/package.json +55 -4
  95. package/src/api.ts +997 -0
  96. package/src/bot.ts +221 -0
  97. package/src/cli.ts +42 -0
  98. package/src/core.ts +240 -0
  99. package/src/index.ts +22 -0
  100. package/src/libs.ts +202 -0
  101. package/src/release.ts +19 -0
  102. package/src/simplex.d.ts +12 -0
  103. package/src/simplex.js +22 -0
  104. package/src/util.ts +92 -0
  105. package/tsconfig.json +23 -0
package/README.md CHANGED
@@ -1,3 +1,130 @@
1
- # Temporary Holding Version
1
+ # SimpleX Chat Node.js library
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This library replaced now deprecated [SimpleX Chat WebRTC TypeScript client](https://www.npmjs.com/package/@simplex-chat/webrtc-client).
4
+
5
+ ## Use cases
6
+
7
+ - chat bots: you can implement any logic of connecting with and communicating with SimpleX Chat users. Using chat groups a chat bot can connect SimpleX Chat users with each other.
8
+ - control of the equipment: e.g. servers or home automation. SimpleX Chat provides secure and authorised connections, so this is more secure than using rest APIs.
9
+ - any scenarios of scripted message sending.
10
+ - chat and chat-based interfaces.
11
+
12
+ Please share your use cases and implementations.
13
+
14
+ ## Quick start: a simple bot
15
+
16
+ ```
17
+ npm i simplex-chat@6.5.1
18
+ ```
19
+
20
+ Simple bot that replies with squares of numbers you send to it:
21
+
22
+ ```javascript
23
+ (async () => {
24
+ const {bot} = await import("simplex-chat")
25
+ // if you are running from this GitHub repo:
26
+ // const {bot} = await import("../dist/index.js")
27
+ await bot.run({
28
+ profile: {displayName: "Squaring bot example", fullName: ""},
29
+ dbOpts: {type: "sqlite", filePrefix: "./squaring_bot"},
30
+ options: {
31
+ addressSettings: {welcomeMessage: "Send a number, I will square it.",
32
+ },
33
+ onMessage: async (ci, content, chat) => {
34
+ const n = +content.text
35
+ const reply = typeof n === "number" && !isNaN(n)
36
+ ? `${n} * ${n} = ${n * n}`
37
+ : `this is not a number`
38
+ await chat.apiSendTextReply(ci, reply)
39
+ }
40
+ })
41
+ })()
42
+ ```
43
+
44
+ If you installed this package as dependency, you can run this example with:
45
+
46
+ ```sh
47
+ node ./node_modules/simplex-chat/examples/squaring-bot-readme.js
48
+ ```
49
+
50
+ If you run it on Mac, the first time it will take 20-30 seconds for MacOS to verify the library.
51
+
52
+ If you cloned this repository, you can:
53
+
54
+ ```
55
+ cd ./packages/simplex-chat-nodejs
56
+ npm install
57
+ npm run build
58
+ SIMPLEX_ADDON_PATH=build/Release/simplex.node node ./examples/squaring-bot-readme.js
59
+ ```
60
+
61
+ Building the Node.js add-on from source needs [node-gyp](https://github.com/nodejs/node-gyp) build tools.
62
+
63
+ There is an example with more options in [./examples/squaring-bot.ts](./examples/squaring-bot.ts).
64
+
65
+ You can run it with: `npx ts-node ./examples/squaring-bot.ts`
66
+
67
+ A larger example, with a business address and commands as keys: [SimpleX Calculator](../../apps/simplex-calculator-bot/).
68
+
69
+ ## Native library
70
+
71
+ `libsimplex` and the prebuilt Node.js add-on are downloaded on first use into the user cache (`$XDG_CACHE_HOME/simplex-chat` or `~/.cache/simplex-chat` on Linux, `~/Library/Caches/simplex-chat` on macOS, `%LOCALAPPDATA%\simplex-chat` on Windows), shared with the Python library. To download them ahead of time, for example in a Dockerfile, run as the user that runs the app:
72
+
73
+ ```bash
74
+ npx simplex-chat install # sqlite (default)
75
+ npx simplex-chat install --backend postgres # Linux x86_64 only
76
+ ```
77
+
78
+ Set `SIMPLEX_LIBS_DIR` to a directory with a local build of `libsimplex` and its dependencies to use it instead; it must be built for the backend in use. Set `SIMPLEX_ADDON_PATH` to a locally built add-on (`build/Release/simplex.node`) to use it instead of the downloaded one.
79
+
80
+ `ChatApi.init` loads the library for `DbConfig.type`; the low-level `core` functions require `core.loadLibrary(backend)` first.
81
+
82
+ ## PostgreSQL backend
83
+
84
+ `DbConfig.type` selects the backend; one backend per process.
85
+
86
+ - `libpq5` must be installed on the host system (`apt install libpq5` on Debian/Ubuntu)
87
+ - PostgreSQL backend is only available for Linux x86_64
88
+ - A PostgreSQL server accessible via connection string
89
+
90
+ ```ts
91
+ // SQLite (default)
92
+ dbOpts: {type: "sqlite", filePrefix: "./data/bot"}
93
+ // optional: encryptionKey: "<sqlcipher-key>"
94
+
95
+ // PostgreSQL
96
+ dbOpts: {
97
+ type: "postgres",
98
+ connectionString: "postgres://user:pass@host/db",
99
+ // schemaPrefix: "bot", // optional — defaults to "simplex_v1"
100
+ }
101
+ ```
102
+
103
+ ## Documentation
104
+
105
+ The library docs are [here](./docs/README.md).
106
+
107
+ Library provides these modules:
108
+ - [bot](./docs/Namespace.bot.md): a simple declarative API to run a chat-bot with a single function call. It automates creating and updating of the bot profile, address and bot commands shown in the app UI.
109
+ - [api](./docs/Namespace.api.md): an API to send chat commands and receive chat events to/from chat core. You need to use it in bot event handlers, and for any other use cases.
110
+ - [core](./docs/Namespace.core.md): a low level API to the core library - the same that is used in desktop clients. You are unlikely to ever need to use this module directly.
111
+ - [util](./docs/Namespace.util.md): useful functions for chat events and types.
112
+
113
+
114
+ This library uses [@simplex-chat/types](https://www.npmjs.com/package/@simplex-chat/types) package with auto-generated [bot API types](../../bots/api/README.md).
115
+
116
+ ## Supported chat functions
117
+
118
+ Library provides types and functions to:
119
+
120
+ - create and change user profile (although, in most cases you can do it manually, via SimpleX Chat terminal app).
121
+ - create and accept invitations or connect with the contacts.
122
+ - create and manage long-term user address, accepting connection requests automatically.
123
+ - send, receive, delete and update messages, and add message reactions.
124
+ - create, join and manage group.
125
+ - send and receive files.
126
+ - etc.
127
+
128
+ ## License
129
+
130
+ [AGPL v3](./LICENSE)
package/dist/api.d.ts ADDED
@@ -0,0 +1,439 @@
1
+ import { CEvt, ChatEvent, ChatResponse, T } from "@simplex-chat/types";
2
+ import * as core from "./core";
3
+ export declare class ChatCommandError extends Error {
4
+ message: string;
5
+ response: ChatResponse;
6
+ constructor(message: string, response: ChatResponse);
7
+ }
8
+ /**
9
+ * Connection request types.
10
+ * @enum {string}
11
+ */
12
+ export declare enum ConnReqType {
13
+ Invitation = "invitation",
14
+ Contact = "contact"
15
+ }
16
+ /**
17
+ * Bot address settings.
18
+ */
19
+ export interface BotAddressSettings {
20
+ /**
21
+ * Automatically accept contact requests.
22
+ * @default true
23
+ */
24
+ autoAccept?: boolean;
25
+ /**
26
+ * Optional welcome message to show before connection to the users.
27
+ * @default undefined (no welcome message)
28
+ */
29
+ welcomeMessage?: T.MsgContent | string | undefined;
30
+ /**
31
+ * Business contact address.
32
+ * For all requests business chats will be created where other participants can be added.
33
+ * @default false
34
+ */
35
+ businessAddress?: boolean;
36
+ }
37
+ export declare const defaultBotAddressSettings: BotAddressSettings;
38
+ export type EventSubscriberFunc<K extends CEvt.Tag> = (event: ChatEvent & {
39
+ type: K;
40
+ }, chat: ChatApi) => void | Promise<void>;
41
+ export type EventSubscribers = {
42
+ [K in CEvt.Tag]?: EventSubscriberFunc<K>;
43
+ };
44
+ /**
45
+ * Database configuration. `type` selects the libsimplex backend loaded by
46
+ * `ChatApi.init`; one backend per process.
47
+ */
48
+ export type DbConfig = {
49
+ /** SQLite backend (default). */
50
+ type: "sqlite";
51
+ /** File prefix — two schema files are named `<prefix>_chat.db` and `<prefix>_agent.db`. */
52
+ filePrefix: string;
53
+ /** Optional SQLCipher encryption key. Empty/omitted = unencrypted. */
54
+ encryptionKey?: string;
55
+ } | {
56
+ /** PostgreSQL backend (Linux x86_64 only, libpq5 required). */
57
+ type: "postgres";
58
+ /** Schema prefix used to namespace tables. Defaults to `"simplex_v1"` when omitted. */
59
+ schemaPrefix?: string;
60
+ /** PostgreSQL connection string (e.g. `postgres://user:pass@host/db`). */
61
+ connectionString: string;
62
+ };
63
+ /**
64
+ * Main API class for interacting with the chat core library.
65
+ */
66
+ export declare class ChatApi {
67
+ protected ctrl_: bigint | undefined;
68
+ private receiveEvents;
69
+ private eventsLoop;
70
+ private subscribers;
71
+ private receivers;
72
+ private constructor();
73
+ /**
74
+ * Initializes the ChatApi, loading libsimplex for `db.type` (downloaded on first use).
75
+ * @param {DbConfig} db - Database configuration (sqlite or postgres).
76
+ * @param {core.MigrationConfirmation} [confirm=core.MigrationConfirmation.YesUp] - Migration confirmation mode.
77
+ * @param {number} [queueSize] - Size of internal queues, the core default is used when omitted.
78
+ */
79
+ static init(db: DbConfig, confirm?: core.MigrationConfirmation, queueSize?: number): Promise<ChatApi>;
80
+ /**
81
+ * Start chat controller. Must be called with the existing user profile.
82
+ */
83
+ startChat(): Promise<void>;
84
+ /**
85
+ * Stop chat controller.
86
+ * `close` calls it before closing the database.
87
+ * Usually doesn't need to be called in chat bots.
88
+ */
89
+ stopChat(): Promise<void>;
90
+ /**
91
+ * Stop chat controller and close chat database.
92
+ * The database is not closed if stopping fails.
93
+ * Usually doesn't need to be called in chat bots.
94
+ */
95
+ close(): Promise<void>;
96
+ private stopEventsLoop;
97
+ private runEventsLoop;
98
+ /**
99
+ * Subscribe multiple event handlers at once.
100
+ * @param subscribers - An object mapping event types (CEvt.Tag) to their subscriber functions.
101
+ * @throws {Error} If the same function is subscribed to event.
102
+ */
103
+ on<K extends CEvt.Tag>(subscribers: EventSubscribers): void;
104
+ /**
105
+ * Subscribe a handler to a specific event.
106
+ * @param {CEvt.Tag} event - The event type to subscribe to.
107
+ * @param subscriber - The subscriber function for the event.
108
+ * @throws {Error} If the same function is subscribed to event.
109
+ */
110
+ on<K extends CEvt.Tag>(event: K, subscriber: EventSubscriberFunc<K>): void;
111
+ private on_;
112
+ /**
113
+ * Subscribe a handler to any event.
114
+ * @param receiver - The receiver function for any event.
115
+ * @throws {Error} If the same function is subscribed to event.
116
+ */
117
+ onAny(receiver: EventSubscriberFunc<CEvt.Tag>): void;
118
+ /**
119
+ * Subscribe a handler to a specific event to be delivered one time.
120
+ * @param {CEvt.Tag} event - The event type to subscribe to.
121
+ * @param subscriber - The subscriber function for the event.
122
+ * @throws {Error} If the same function is subscribed to event.
123
+ */
124
+ once<K extends CEvt.Tag>(event: K, subscriber: EventSubscriberFunc<K>): void;
125
+ /**
126
+ * Waits for specific event, with an optional predicate.
127
+ * Returns `undefined` on timeout if specified.
128
+ */
129
+ wait<K extends CEvt.Tag>(event: K): Promise<ChatEvent & {
130
+ type: K;
131
+ }>;
132
+ wait<K extends CEvt.Tag>(event: K, predicate: ((event: ChatEvent & {
133
+ type: K;
134
+ }) => boolean) | undefined): Promise<ChatEvent & {
135
+ type: K;
136
+ }>;
137
+ wait<K extends CEvt.Tag>(event: K, timeout: number): Promise<ChatEvent & {
138
+ type: K;
139
+ } | undefined>;
140
+ wait<K extends CEvt.Tag>(event: K, predicate: ((event: ChatEvent & {
141
+ type: K;
142
+ }) => boolean) | undefined, timeout: number): Promise<ChatEvent & {
143
+ type: K;
144
+ } | undefined>;
145
+ /**
146
+ * Unsubscribe all or a specific handler from a specific event.
147
+ * @param {CEvt.Tag} event - The event type to unsubscribe from.
148
+ * @param subscriber - An optional subscriber function for the event.
149
+ */
150
+ off<K extends CEvt.Tag>(event: K, subscriber?: EventSubscriberFunc<K> | undefined): void;
151
+ /**
152
+ * Unsubscribe all or a specific handler from any events.
153
+ * @param receiver - An optional subscriber function for the event.
154
+ */
155
+ offAny(receiver?: EventSubscriberFunc<CEvt.Tag> | undefined): void;
156
+ /**
157
+ * Chat controller is initialized
158
+ */
159
+ get initialized(): boolean;
160
+ /**
161
+ * Chat controller is started
162
+ */
163
+ get started(): boolean;
164
+ /**
165
+ * Chat controller reference
166
+ */
167
+ get ctrl(): bigint;
168
+ sendChatCmd(cmd: string): Promise<ChatResponse>;
169
+ recvChatEvent(wait?: number): Promise<ChatEvent | undefined>;
170
+ /**
171
+ * Create bot address.
172
+ * Network usage: interactive.
173
+ */
174
+ apiCreateUserAddress(userId: number): Promise<T.CreatedConnLink>;
175
+ /**
176
+ * Deletes a user address.
177
+ * Network usage: background.
178
+ */
179
+ apiDeleteUserAddress(userId: number): Promise<void>;
180
+ /**
181
+ * Get bot address and settings.
182
+ * Network usage: no.
183
+ */
184
+ apiGetUserAddress(userId: number): Promise<T.UserContactLink | undefined>;
185
+ /**
186
+ * Add address to bot profile.
187
+ * Network usage: interactive.
188
+ */
189
+ apiSetProfileAddress(userId: number, enable: boolean): Promise<T.UserProfileUpdateSummary>;
190
+ /**
191
+ * Set bot address settings.
192
+ * Network usage: interactive.
193
+ */
194
+ apiSetAddressSettings(userId: number, { autoAccept, welcomeMessage, businessAddress }: BotAddressSettings): Promise<void>;
195
+ apiSetUserDomain(userId: number, simplexDomain?: string): Promise<T.User>;
196
+ /**
197
+ * Send messages.
198
+ * Network usage: background.
199
+ */
200
+ apiSendMessages(chat: [T.ChatType, number] | T.ChatRef | T.ChatInfo, messages: T.ComposedMessage[], liveMessage?: boolean): Promise<T.AChatItem[]>;
201
+ /**
202
+ * Send text message.
203
+ * Network usage: background.
204
+ */
205
+ apiSendTextMessage(chat: [T.ChatType, number] | T.ChatRef | T.ChatInfo, text: string, inReplyTo?: number): Promise<T.AChatItem[]>;
206
+ /**
207
+ * Send text message in reply to received message.
208
+ * Network usage: background.
209
+ */
210
+ apiSendTextReply(chatItem: T.AChatItem, text: string): Promise<T.AChatItem[]>;
211
+ /**
212
+ * Update message.
213
+ * Network usage: background.
214
+ */
215
+ apiUpdateChatItem(chatType: T.ChatType, chatId: number, chatItemId: number, msgContent: T.MsgContent, liveMessage: false): Promise<T.ChatItem>;
216
+ /**
217
+ * Delete message.
218
+ * Network usage: background.
219
+ */
220
+ apiDeleteChatItems(chatType: T.ChatType, chatId: number, chatItemIds: number[], deleteMode: T.CIDeleteMode): Promise<T.ChatItemDeletion[]>;
221
+ /**
222
+ * Moderate message. Requires Moderator role (and higher than message author's).
223
+ * Network usage: background.
224
+ */
225
+ apiDeleteMemberChatItem(groupId: number, chatItemIds: number[]): Promise<T.ChatItemDeletion[]>;
226
+ /**
227
+ * Add/remove message reaction.
228
+ * Network usage: background.
229
+ */
230
+ apiChatItemReaction(chatType: T.ChatType, chatId: number, chatItemId: number, add: boolean, reaction: T.MsgReaction): Promise<T.ACIReaction>;
231
+ /**
232
+ * Receive file.
233
+ * Network usage: no.
234
+ */
235
+ apiReceiveFile(fileId: number): Promise<T.AChatItem>;
236
+ /**
237
+ * Cancel file.
238
+ * Network usage: background.
239
+ */
240
+ apiCancelFile(fileId: number): Promise<void>;
241
+ /**
242
+ * Add contact to group. Requires bot to have Admin role.
243
+ * Network usage: interactive.
244
+ */
245
+ apiAddMember(groupId: number, contactId: number, memberRole: T.GroupMemberRole): Promise<T.GroupMember>;
246
+ /**
247
+ * Add member of another group to group. Requires bot to have Admin role in the group, and direct messages allowed for its role in another group.
248
+ * Network usage: interactive.
249
+ */
250
+ apiAddMemberViaGroup(groupId: number, viaGroupId: number, groupMemberId: number, memberRole: T.GroupMemberRole): Promise<T.GroupMember>;
251
+ /**
252
+ * Join group.
253
+ * Network usage: interactive.
254
+ */
255
+ apiJoinGroup(groupId: number): Promise<T.GroupInfo>;
256
+ /**
257
+ * Accept group member. Requires Admin role.
258
+ * Network usage: background.
259
+ */
260
+ apiAcceptMember(groupId: number, groupMemberId: number, memberRole: T.GroupMemberRole): Promise<T.GroupMember>;
261
+ /**
262
+ * Set members role. Requires Admin role.
263
+ * Network usage: background.
264
+ */
265
+ apiSetMembersRole(groupId: number, groupMemberIds: number[], memberRole: T.GroupMemberRole): Promise<void>;
266
+ /**
267
+ * Block members. Requires Moderator role.
268
+ * Network usage: background.
269
+ */
270
+ apiBlockMembersForAll(groupId: number, groupMemberIds: number[], blocked: boolean): Promise<void>;
271
+ /**
272
+ * Remove members. Requires Admin role.
273
+ * Network usage: background.
274
+ */
275
+ apiRemoveMembers(groupId: number, memberIds: number[], withMessages?: boolean): Promise<T.GroupMember[]>;
276
+ /**
277
+ * Leave group.
278
+ * Network usage: background.
279
+ */
280
+ apiLeaveGroup(groupId: number): Promise<T.GroupInfo>;
281
+ /**
282
+ * Get group members.
283
+ * Network usage: no.
284
+ */
285
+ apiListMembers(groupId: number): Promise<T.GroupMember[]>;
286
+ /**
287
+ * Create group.
288
+ * Network usage: no.
289
+ */
290
+ apiNewGroup(userId: number, groupProfile: T.GroupProfile): Promise<T.GroupInfo>;
291
+ /**
292
+ * Update group profile.
293
+ * Network usage: background.
294
+ */
295
+ apiUpdateGroupProfile(groupId: number, groupProfile: T.GroupProfile): Promise<T.GroupInfo>;
296
+ /**
297
+ * Create group link.
298
+ * Network usage: interactive.
299
+ */
300
+ apiCreateGroupLink(groupId: number, memberRole: T.GroupMemberRole): Promise<string>;
301
+ /**
302
+ * Set member role for group link.
303
+ * Network usage: no.
304
+ */
305
+ apiSetGroupLinkMemberRole(groupId: number, memberRole: T.GroupMemberRole): Promise<void>;
306
+ /**
307
+ * Delete group link.
308
+ * Network usage: background.
309
+ */
310
+ apiDeleteGroupLink(groupId: number): Promise<void>;
311
+ /**
312
+ * Get group link.
313
+ * Network usage: no.
314
+ */
315
+ apiGetGroupLink(groupId: number): Promise<T.GroupLink>;
316
+ apiGetGroupLinkStr(groupId: number): Promise<string>;
317
+ /**
318
+ * Create 1-time invitation link.
319
+ * Network usage: interactive.
320
+ */
321
+ apiCreateLink(userId: number): Promise<string>;
322
+ /**
323
+ * Determine SimpleX link type and if the bot is already connected via this link.
324
+ * Network usage: interactive.
325
+ */
326
+ apiConnectPlan(userId: number, connectionLink: string): Promise<[T.ConnectionPlan, T.CreatedConnLink]>;
327
+ /**
328
+ * Connect via prepared SimpleX link. The link can be 1-time invitation link, contact address or group link
329
+ * Network usage: interactive.
330
+ */
331
+ apiConnect(userId: number, incognito: boolean, preparedLink: T.CreatedConnLink): Promise<ConnReqType>;
332
+ /**
333
+ * Connect via SimpleX link as string in the active user profile.
334
+ * Network usage: interactive.
335
+ */
336
+ apiConnectActiveUser(connLink: string): Promise<ConnReqType>;
337
+ private handleConnectResult;
338
+ /**
339
+ * Accept contact request.
340
+ * Network usage: interactive.
341
+ */
342
+ apiAcceptContactRequest(contactReqId: number): Promise<T.Contact>;
343
+ /**
344
+ * Reject contact request. The user who sent the request is **not notified**.
345
+ * Network usage: no.
346
+ */
347
+ apiRejectContactRequest(contactReqId: number): Promise<void>;
348
+ /**
349
+ * Get contacts.
350
+ * Network usage: no.
351
+ */
352
+ apiListContacts(userId: number): Promise<T.Contact[]>;
353
+ /**
354
+ * Get groups.
355
+ * Network usage: no.
356
+ */
357
+ apiListGroups(userId: number, contactId?: number, search?: string): Promise<T.GroupInfo[]>;
358
+ /**
359
+ * Get chat previews (paginated).
360
+ * Network usage: no.
361
+ *
362
+ * Prefer this over apiListContacts / apiListGroups for any scan: those
363
+ * methods load every record into memory in a single response and will fail
364
+ * on large databases.
365
+ */
366
+ apiGetChats(userId: number, pagination: T.PaginationByTime, query?: T.ChatListQuery, pendingConnections?: boolean): Promise<T.AChat[]>;
367
+ /**
368
+ * Delete chat.
369
+ * Network usage: background.
370
+ */
371
+ apiDeleteChat(chatType: T.ChatType, chatId: number, deleteMode?: T.ChatDeleteMode): Promise<void>;
372
+ /**
373
+ * Set group custom data.
374
+ * Network usage: no.
375
+ */
376
+ apiSetGroupCustomData(groupId: number, customData?: object): Promise<void>;
377
+ /**
378
+ * Set contact custom data.
379
+ * Network usage: no.
380
+ */
381
+ apiSetContactCustomData(contactId: number, customData?: object): Promise<void>;
382
+ /**
383
+ * Set auto-accept member contacts.
384
+ * Network usage: no.
385
+ */
386
+ apiSetAutoAcceptMemberContacts(userId: number, onOff: boolean): Promise<void>;
387
+ /**
388
+ * Get chat items.
389
+ * Network usage: no.
390
+ */
391
+ apiGetChat(chatType: T.ChatType, chatId: number, count: number): Promise<any>;
392
+ /**
393
+ * Get active user profile
394
+ * Network usage: no.
395
+ */
396
+ apiGetActiveUser(): Promise<T.User | undefined>;
397
+ /**
398
+ * Create new user profile
399
+ * Network usage: no.
400
+ */
401
+ apiCreateActiveUser(profile?: T.Profile): Promise<T.User>;
402
+ /**
403
+ * Get all user profiles
404
+ * Network usage: no.
405
+ */
406
+ apiListUsers(): Promise<T.UserInfo[]>;
407
+ /**
408
+ * Set active user profile
409
+ * Network usage: no.
410
+ */
411
+ apiSetActiveUser(userId: number, viewPwd?: string): Promise<T.User>;
412
+ /**
413
+ * Delete user profile.
414
+ * Network usage: background.
415
+ */
416
+ apiDeleteUser(userId: number, delSMPQueues: boolean, viewPwd?: string): Promise<void>;
417
+ /**
418
+ * Update user profile.
419
+ * Network usage: background.
420
+ */
421
+ apiUpdateProfile(userId: number, profile: T.Profile): Promise<T.UserProfileUpdateSummary | undefined>;
422
+ /**
423
+ * Configure chat preference overrides for the contact.
424
+ * Network usage: background.
425
+ */
426
+ apiSetContactPrefs(contactId: number, preferences: T.Preferences): Promise<void>;
427
+ /**
428
+ * Create a direct message contact with a group member.
429
+ * Returns the created contact.
430
+ * Network usage: interactive.
431
+ */
432
+ apiCreateMemberContact(groupId: number, groupMemberId: number): Promise<T.Contact>;
433
+ /**
434
+ * Send a direct message invitation to a group member contact.
435
+ * The contact must have been created with {@link apiCreateMemberContact}.
436
+ * Network usage: interactive.
437
+ */
438
+ apiSendMemberContactInvitation(contactId: number, message?: T.MsgContent | string): Promise<T.Contact>;
439
+ }