@wirecat/tg-cli 0.63.0 → 0.65.0
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/commands/bot.d.ts.map +1 -1
- package/dist/commands/bot.js +14 -3
- package/dist/commands/bot.js.map +1 -1
- package/dist/commands/checks.d.ts +3 -0
- package/dist/commands/checks.d.ts.map +1 -0
- package/dist/commands/checks.js +21 -0
- package/dist/commands/checks.js.map +1 -0
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js +7 -1
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/session.d.ts.map +1 -1
- package/dist/commands/session.js +7 -4
- package/dist/commands/session.js.map +1 -1
- package/dist/telegram/account.d.ts +29 -0
- package/dist/telegram/account.d.ts.map +1 -0
- package/dist/telegram/account.js +66 -0
- package/dist/telegram/account.js.map +1 -0
- package/dist/telegram/adapter.d.ts +66 -212
- package/dist/telegram/adapter.d.ts.map +1 -1
- package/dist/telegram/adapter.js +191 -1722
- package/dist/telegram/adapter.js.map +1 -1
- package/dist/telegram/bot-history.d.ts +2 -0
- package/dist/telegram/bot-history.d.ts.map +1 -1
- package/dist/telegram/bot-history.js +4 -4
- package/dist/telegram/bot-history.js.map +1 -1
- package/dist/telegram/chats.d.ts +30 -0
- package/dist/telegram/chats.d.ts.map +1 -0
- package/dist/telegram/chats.js +103 -0
- package/dist/telegram/chats.js.map +1 -0
- package/dist/telegram/contacts.d.ts +24 -0
- package/dist/telegram/contacts.d.ts.map +1 -0
- package/dist/telegram/contacts.js +82 -0
- package/dist/telegram/contacts.js.map +1 -0
- package/dist/telegram/errors.d.ts +9 -1
- package/dist/telegram/errors.d.ts.map +1 -1
- package/dist/telegram/errors.js +34 -12
- package/dist/telegram/errors.js.map +1 -1
- package/dist/telegram/feature.d.ts +52 -0
- package/dist/telegram/feature.d.ts.map +1 -0
- package/dist/telegram/feature.js +73 -0
- package/dist/telegram/feature.js.map +1 -0
- package/dist/telegram/folders.d.ts +11 -0
- package/dist/telegram/folders.d.ts.map +1 -0
- package/dist/telegram/folders.js +104 -0
- package/dist/telegram/folders.js.map +1 -0
- package/dist/telegram/groups.d.ts +101 -0
- package/dist/telegram/groups.d.ts.map +1 -0
- package/dist/telegram/groups.js +386 -0
- package/dist/telegram/groups.js.map +1 -0
- package/dist/telegram/join-requests.d.ts +2 -1
- package/dist/telegram/join-requests.d.ts.map +1 -1
- package/dist/telegram/join-requests.js +2 -2
- package/dist/telegram/join-requests.js.map +1 -1
- package/dist/telegram/login.d.ts +20 -0
- package/dist/telegram/login.d.ts.map +1 -0
- package/dist/telegram/login.js +113 -0
- package/dist/telegram/login.js.map +1 -0
- package/dist/telegram/messages.d.ts +134 -0
- package/dist/telegram/messages.d.ts.map +1 -0
- package/dist/telegram/messages.js +379 -0
- package/dist/telegram/messages.js.map +1 -0
- package/dist/telegram/polls.d.ts +23 -4
- package/dist/telegram/polls.d.ts.map +1 -1
- package/dist/telegram/polls.js +83 -3
- package/dist/telegram/polls.js.map +1 -1
- package/dist/telegram/proxy.d.ts +3 -1
- package/dist/telegram/proxy.d.ts.map +1 -1
- package/dist/telegram/proxy.js +2 -2
- package/dist/telegram/proxy.js.map +1 -1
- package/dist/telegram/registration.d.ts +5 -1
- package/dist/telegram/registration.d.ts.map +1 -1
- package/dist/telegram/registration.js +66 -12
- package/dist/telegram/registration.js.map +1 -1
- package/dist/telegram/send-as.d.ts +2 -1
- package/dist/telegram/send-as.d.ts.map +1 -1
- package/dist/telegram/send-as.js +2 -2
- package/dist/telegram/send-as.js.map +1 -1
- package/dist/telegram/sending.d.ts.map +1 -1
- package/dist/telegram/sending.js +2 -1
- package/dist/telegram/sending.js.map +1 -1
- package/dist/telegram/stats.d.ts +8 -2
- package/dist/telegram/stats.d.ts.map +1 -1
- package/dist/telegram/stats.js +54 -0
- package/dist/telegram/stats.js.map +1 -1
- package/dist/telegram/topics.d.ts +36 -0
- package/dist/telegram/topics.d.ts.map +1 -0
- package/dist/telegram/topics.js +276 -0
- package/dist/telegram/topics.js.map +1 -0
- package/dist/telegram/upload.d.ts.map +1 -1
- package/dist/telegram/upload.js +2 -1
- package/dist/telegram/upload.js.map +1 -1
- package/dist/telegram/watch.d.ts +13 -0
- package/dist/telegram/watch.d.ts.map +1 -0
- package/dist/telegram/watch.js +112 -0
- package/dist/telegram/watch.js.map +1 -0
- package/dist/update.d.ts +3 -23
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +10 -37
- package/dist/update.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/skills/tg-cli/SKILL.md +1 -1
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import type { Words } from "./feature.js";
|
|
2
|
+
export declare const pollClosed: (words: Words) => string;
|
|
1
3
|
/**
|
|
2
4
|
* Telegram's refusals as the closed list of codes a script branches on. Only the error's name
|
|
3
5
|
* travels into the message — never a parameter the caller passed, which may be somebody's text.
|
|
4
6
|
*/
|
|
5
|
-
export declare const toCliError: (error: unknown, login?: string) => unknown;
|
|
7
|
+
export declare const toCliError: (error: unknown, words: Words, login?: string) => unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Errors from mtcute's background work, which no command awaits. Without a listener mtcute prints each with
|
|
10
|
+
* its stack. A login resets the connections on purpose, and the old one reports itself closed (seen 2026-10-16
|
|
11
|
+
* right after a 2FA password); mtcute reconnects, and a request that really fails still throws to its caller.
|
|
12
|
+
*/
|
|
13
|
+
export declare const backgroundError: (write: (line: string) => void, verbose: boolean, words: Words) => (error: Error) => void;
|
|
6
14
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/telegram/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/telegram/errors.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAczC,eAAO,MAAM,UAAU,UAAW,KAAK,KAAG,MAAsE,CAAA;AAwHhH;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,OAAO,SAAS,KAAK,qBAAmC,OAsEzF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,UAClB,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,WAAW,OAAO,SAAS,KAAK,aACtD,KAAK,KAAG,IAQf,CAAA"}
|
package/dist/telegram/errors.js
CHANGED
|
@@ -10,6 +10,7 @@ const NOT_FOUND = new Set([
|
|
|
10
10
|
"MSG_ID_INVALID",
|
|
11
11
|
"MESSAGE_ID_INVALID",
|
|
12
12
|
]);
|
|
13
|
+
export const pollClosed = (words) => `this poll is closed; ${words("polls.show")} has its result`;
|
|
13
14
|
/** Refusals whose name alone would not tell a person what to do. */
|
|
14
15
|
const EXPLAINED = {
|
|
15
16
|
CHANNEL_PRIVATE: ["permission_error", "you cannot access this channel or supergroup"],
|
|
@@ -28,8 +29,8 @@ const EXPLAINED = {
|
|
|
28
29
|
PHONE_NOT_OCCUPIED: ["not_found", "nobody Telegram lets you find has this number"],
|
|
29
30
|
USER_NOT_MUTUAL_CONTACT: [
|
|
30
31
|
"permission_error",
|
|
31
|
-
"Telegram lets you add someone who left or was removed only if you are each other's contacts — " +
|
|
32
|
-
|
|
32
|
+
(words) => "Telegram lets you add someone who left or was removed only if you are each other's contacts — " +
|
|
33
|
+
`send them the invite link instead (${words("chats.link.show", "<chat>")})`,
|
|
33
34
|
],
|
|
34
35
|
USER_PRIVACY_RESTRICTED: ["permission_error", "their privacy settings do not let you add them to a group"],
|
|
35
36
|
CHAT_ADMIN_REQUIRED: ["permission_error", "only an admin of this chat may do that"],
|
|
@@ -39,10 +40,13 @@ const EXPLAINED = {
|
|
|
39
40
|
"validation_error",
|
|
40
41
|
"a channel's polls cannot show who voted — create it with --anonymous",
|
|
41
42
|
],
|
|
42
|
-
MESSAGE_POLL_CLOSED: ["validation_error",
|
|
43
|
+
MESSAGE_POLL_CLOSED: ["validation_error", pollClosed],
|
|
43
44
|
REVOTE_NOT_ALLOWED: ["validation_error", "this poll takes one vote, and yours is final — it cannot be changed"],
|
|
44
45
|
OPTIONS_TOO_MUCH: ["validation_error", "this poll takes one answer; give one id"],
|
|
45
|
-
OPTION_INVALID: [
|
|
46
|
+
OPTION_INVALID: [
|
|
47
|
+
"validation_error",
|
|
48
|
+
(words) => `that is not an answer of this poll — ${words("polls.show")} lists them`,
|
|
49
|
+
],
|
|
46
50
|
POLL_VOTE_REQUIRED: ["permission_error", "Telegram shows who voted only once you have voted in this poll"],
|
|
47
51
|
BROADCAST_FORBIDDEN: ["permission_error", "a channel does not show who voted in its polls"],
|
|
48
52
|
POLL_ANSWERS_INVALID: ["validation_error", "Telegram refused how many answers this poll has"],
|
|
@@ -56,16 +60,17 @@ const EXPLAINED = {
|
|
|
56
60
|
QUIZ_MULTIPLE_INVALID: ["validation_error", "a quiz takes one answer; not with --multiple"],
|
|
57
61
|
CHAT_PUBLIC_REQUIRED: [
|
|
58
62
|
"validation_error",
|
|
59
|
-
"Telegram would not make this group ask everyone for approval — make an invite link that needs it: " +
|
|
60
|
-
"
|
|
63
|
+
(words) => "Telegram would not make this group ask everyone for approval — make an invite link that needs it: " +
|
|
64
|
+
words("chats.link.create", "<chat> --approval"),
|
|
61
65
|
],
|
|
62
66
|
MEGAGROUP_REQUIRED: ["validation_error", "that works only in a supergroup"],
|
|
63
67
|
BROADCAST_REQUIRED: ["validation_error", "that works only in a channel"],
|
|
64
68
|
};
|
|
65
69
|
const revoked = (login) => ["authentication_error", `Telegram ended this login — run ${login}`, "revoked"];
|
|
66
|
-
const frozen = () => [
|
|
70
|
+
const frozen = (_login, words) => [
|
|
67
71
|
"permission_error",
|
|
68
|
-
"Telegram froze this account: it can read but not write —
|
|
72
|
+
"Telegram froze this account: it can read but not write — " +
|
|
73
|
+
`${words("doctor", "--online")} shows until when, and where to appeal`,
|
|
69
74
|
"frozen",
|
|
70
75
|
];
|
|
71
76
|
/**
|
|
@@ -115,7 +120,7 @@ const argumentKind = (message) => ARGUMENT_KINDS.find(([pattern]) => pattern.tes
|
|
|
115
120
|
* Telegram's refusals as the closed list of codes a script branches on. Only the error's name
|
|
116
121
|
* travels into the message — never a parameter the caller passed, which may be somebody's text.
|
|
117
122
|
*/
|
|
118
|
-
export const toCliError = (error, login = "
|
|
123
|
+
export const toCliError = (error, words, login = words("session.start")) => {
|
|
119
124
|
if (isCliError(error))
|
|
120
125
|
return error;
|
|
121
126
|
if (RpcError.is(error, "FLOOD_WAIT_%d")) {
|
|
@@ -133,15 +138,17 @@ export const toCliError = (error, login = "`tg session start`") => {
|
|
|
133
138
|
}
|
|
134
139
|
const standing = STANDINGS[error.text];
|
|
135
140
|
if (standing) {
|
|
136
|
-
const [code, message, state] = standing(login);
|
|
141
|
+
const [code, message, state] = standing(login, words);
|
|
137
142
|
return new CliError(code, message, { ...details, standing: { state, hint: message } });
|
|
138
143
|
}
|
|
139
144
|
if (error.code === RpcError.UNAUTHORIZED) {
|
|
140
145
|
return new CliError("authentication_error", `not logged in, or the session was ended — run ${login}`, details);
|
|
141
146
|
}
|
|
142
147
|
const explained = EXPLAINED[error.text];
|
|
143
|
-
if (explained)
|
|
144
|
-
|
|
148
|
+
if (explained) {
|
|
149
|
+
const [code, message] = explained;
|
|
150
|
+
return new CliError(code, typeof message === "string" ? message : message(words), details);
|
|
151
|
+
}
|
|
145
152
|
if (NOT_FOUND.has(error.text))
|
|
146
153
|
return new CliError("not_found", `Telegram does not know that (${error.text})`, details);
|
|
147
154
|
if (error.code === RpcError.FORBIDDEN)
|
|
@@ -183,4 +190,19 @@ export const toCliError = (error, login = "`tg session start`") => {
|
|
|
183
190
|
}
|
|
184
191
|
return error;
|
|
185
192
|
};
|
|
193
|
+
/**
|
|
194
|
+
* Errors from mtcute's background work, which no command awaits. Without a listener mtcute prints each with
|
|
195
|
+
* its stack. A login resets the connections on purpose, and the old one reports itself closed (seen 2026-10-16
|
|
196
|
+
* right after a 2FA password); mtcute reconnects, and a request that really fails still throws to its caller.
|
|
197
|
+
*/
|
|
198
|
+
export const backgroundError = (write, verbose, words) => (error) => {
|
|
199
|
+
if (/^Connection closed/.test(error.message)) {
|
|
200
|
+
if (verbose)
|
|
201
|
+
write(`[client] ${error.message}`);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const mapped = toCliError(error, words);
|
|
205
|
+
const message = mapped instanceof Error ? mapped.message : String(mapped);
|
|
206
|
+
write(`[client] ${message.split("\n", 1)[0]}`);
|
|
207
|
+
};
|
|
186
208
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/telegram/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,EAAE,GACH,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/telegram/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,EAAE,GACH,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGxE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAA;AAEvB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,iBAAiB;IACjB,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,uBAAuB;IACvB,gBAAgB;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,CAAA;IACzE,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,CAAC,KAA6B,EAAE,OAAgB,EAAE,KAAY,EAAE,EAAE,CAClE,CAAC,KAAY,EAAQ,EAAE;IACrB,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7C,IAAI,OAAO;YAAE,KAAK,CAAC,YAAY,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAM;IACR,CAAC;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACvC,MAAM,OAAO,GAAG,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACzE,KAAK,CAAC,YAAY,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAChD,CAAC,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type InputPeerLike, Long, type TelegramClient, Message as TgMessage, type tl } from "@mtcute/node";
|
|
2
|
+
import { type Message, type MessageHit } from "@wirecat/cli-core";
|
|
3
|
+
/** The commands a message sends a person to; the command layer names them in its own words. */
|
|
4
|
+
export declare const CHECKS: readonly ["account.sessions.list", "bot.auth.set", "chats.folders.list", "chats.link.create", "chats.link.list", "chats.link.show", "chats.list", "chats.members.list", "chats.requests.list", "chats.send-as", "chats.show", "config.set", "doctor", "polls.show", "session.start", "topics.list"];
|
|
5
|
+
export type Check = (typeof CHECKS)[number];
|
|
6
|
+
/** A command as the person types it, arguments included, in one pair of backticks. */
|
|
7
|
+
export type Words = (check: Check, args?: string) => string;
|
|
8
|
+
/** What may have happened, where to look, and what to weigh before a repeat. */
|
|
9
|
+
export interface Unanswered {
|
|
10
|
+
what: string;
|
|
11
|
+
check: Check;
|
|
12
|
+
after?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Without the command layer's words, a check is named by its command path alone. */
|
|
15
|
+
export declare const bareCheck: Words;
|
|
16
|
+
export declare const unansweredText: ({ what, check, after }: Unanswered, words: Words) => string;
|
|
17
|
+
/** What the features beside the adapter share: one client, one way to name a chat, one way to fail. */
|
|
18
|
+
export interface Feature {
|
|
19
|
+
client: TelegramClient;
|
|
20
|
+
login: string | undefined;
|
|
21
|
+
checks: Words;
|
|
22
|
+
/** The logged-in user's id from the session, without a request; `null` before a login. */
|
|
23
|
+
self: () => string | null;
|
|
24
|
+
inputOf: (reference: string) => Promise<InputPeerLike>;
|
|
25
|
+
call: <T>(work: () => Promise<T>) => Promise<T>;
|
|
26
|
+
/** A call that carries a `random_id`, so a retry repeats it. */
|
|
27
|
+
send: <T>(work: () => Promise<T>) => Promise<T>;
|
|
28
|
+
/** A write with no id to repeat it by: no answer means it may have happened, and `what` says what to do. */
|
|
29
|
+
write: <T>(what: string | Unanswered, work: () => Promise<T>) => Promise<T>;
|
|
30
|
+
unanswered: (error: unknown, what: string | Unanswered, details?: Record<string, unknown>) => unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface Sent {
|
|
33
|
+
message: Message;
|
|
34
|
+
/** Telegram's `random_id` for this send, as a string. Repeat it with `--operation-id` after an unknown outcome. */
|
|
35
|
+
sendId: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const repeatWith: (sendId: string, sendAs: string | undefined) => string;
|
|
38
|
+
export declare const retryDetails: (sendId: string, sendAs: string | undefined) => {
|
|
39
|
+
operation_id: string;
|
|
40
|
+
sendAs?: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
/** No answer is not a refusal: the write may have reached Telegram. Anything else is left for `call` to map. */
|
|
43
|
+
export declare const unknownIfUnanswered: (error: unknown, what: string, details?: Record<string, unknown>) => unknown;
|
|
44
|
+
/** `https://t.me/name`, `t.me/name` or `@name`, as the name alone. */
|
|
45
|
+
export declare const publicName: (link: string) => string;
|
|
46
|
+
export declare const messageNumber: (id: string, rule?: string) => number;
|
|
47
|
+
export declare const topicNumber: (id: string) => number;
|
|
48
|
+
export declare const parseSendId: (typed: string) => Long;
|
|
49
|
+
export declare const forwardedCopy: (updates: tl.TypeUpdates) => TgMessage | undefined;
|
|
50
|
+
export declare const remoteMessage: (message: TgMessage) => Message;
|
|
51
|
+
export declare const remoteHit: (message: TgMessage, source: "remote_fetch" | "remote_update") => MessageHit;
|
|
52
|
+
//# sourceMappingURL=feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../src/telegram/feature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,IAAI,EAAc,KAAK,cAAc,EAAE,OAAO,IAAI,SAAS,EAAE,KAAK,EAAE,EAAE,MAAM,cAAc,CAAA;AAEvH,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,mBAAmB,CAAA;AAInF,+FAA+F;AAC/F,eAAO,MAAM,MAAM,YACjB,uBAAuB,EACvB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,aAAa,CACL,CAAA;AACV,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3C,sFAAsF;AACtF,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAE3D,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;IACZ,KAAK,CAAC,EAAE,M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,SAAS;;;CAGrE,CAAA;AAEF,gHAAgH;AAChH,eAAO,MAAM,mBAAmB,UAAW,OAAO,QAAQ,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAQ,OAMzG,CAAA;AAED,sEAAsE;AACtE,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAIf,CAAA;AAE3B,eAAO,MAAM,aAAa,OAAQ,MAAM,oBAAsC,MAG7E,CAAA;AAED,eAAO,MAAM,WAAW,OAAQ,MAAM,KAAG,MAKxC,CAAA;AAED,eAAO,MAAM,WAAW,UAAW,MAAM,KAAG,IAI3C,CAAA;AAED,eAAO,MAAM,aAAa,YAAa,EAAE,CAAC,WAAW,KAAG,SAAS,GAAG,SAInE,CAAA;AAED,eAAO,MAAM,aAAa,YAAa,SAAS,KAAG,OACiD,CAAA;AAEpG,eAAO,MAAM,SAAS,YAAa,SAAS,UAAU,cAAc,GAAG,eAAe,KAAG,UAGvF,CAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Long, PeersIndex, Message as TgMessage } from "@mtcute/node";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { observedCounters } from "@wirecat/cli-core";
|
|
4
|
+
import { toCliError } from "./errors.js";
|
|
5
|
+
import { toMessage, toMessageHit } from "./map.js";
|
|
6
|
+
/** The commands a message sends a person to; the command layer names them in its own words. */
|
|
7
|
+
export const CHECKS = [
|
|
8
|
+
"account.sessions.list",
|
|
9
|
+
"bot.auth.set",
|
|
10
|
+
"chats.folders.list",
|
|
11
|
+
"chats.link.create",
|
|
12
|
+
"chats.link.list",
|
|
13
|
+
"chats.link.show",
|
|
14
|
+
"chats.list",
|
|
15
|
+
"chats.members.list",
|
|
16
|
+
"chats.requests.list",
|
|
17
|
+
"chats.send-as",
|
|
18
|
+
"chats.show",
|
|
19
|
+
"config.set",
|
|
20
|
+
"doctor",
|
|
21
|
+
"polls.show",
|
|
22
|
+
"session.start",
|
|
23
|
+
"topics.list",
|
|
24
|
+
];
|
|
25
|
+
/** Without the command layer's words, a check is named by its command path alone. */
|
|
26
|
+
export const bareCheck = (check, args) => `\`${check.replaceAll(".", " ")}${args === undefined ? "" : ` ${args}`}\``;
|
|
27
|
+
export const unansweredText = ({ what, check, after }, words) => `${what}; check ${words(check)}${after === undefined ? "" : ` ${after}`}`;
|
|
28
|
+
export const repeatWith = (sendId, sendAs) => sendAs === undefined ? `--operation-id ${sendId}` : `--operation-id ${sendId} --send-as ${sendAs}`;
|
|
29
|
+
export const retryDetails = (sendId, sendAs) => ({
|
|
30
|
+
operation_id: sendId,
|
|
31
|
+
...(sendAs === undefined ? {} : { sendAs }),
|
|
32
|
+
});
|
|
33
|
+
/** No answer is not a refusal: the write may have reached Telegram. Anything else is left for `call` to map. */
|
|
34
|
+
export const unknownIfUnanswered = (error, what, details = {}) => {
|
|
35
|
+
const known = toCliError(error, bareCheck);
|
|
36
|
+
if (known instanceof CliError && ["timeout", "network_error"].includes(known.code)) {
|
|
37
|
+
return new CliError("outcome_unknown", `no answer from Telegram — ${what}`, { ...details, cause: known.code });
|
|
38
|
+
}
|
|
39
|
+
return error;
|
|
40
|
+
};
|
|
41
|
+
/** `https://t.me/name`, `t.me/name` or `@name`, as the name alone. */
|
|
42
|
+
export const publicName = (link) => link
|
|
43
|
+
.replace(/^(https?:\/\/)?(t\.me|telegram\.me)\//, "")
|
|
44
|
+
.replace(/^@/, "")
|
|
45
|
+
.replace(/[/?].*$/, "");
|
|
46
|
+
export const messageNumber = (id, rule = "`id<` takes a message id") => {
|
|
47
|
+
if (!/^\d+$/.test(id))
|
|
48
|
+
throw new CliError("validation_error", `${rule}, got "${id}"`);
|
|
49
|
+
return Number(id);
|
|
50
|
+
};
|
|
51
|
+
export const topicNumber = (id) => {
|
|
52
|
+
if (!/^[1-9]\d*$/.test(id) || Number(id) > 2147483647) {
|
|
53
|
+
throw new CliError("validation_error", "--topic needs a positive Telegram topic id");
|
|
54
|
+
}
|
|
55
|
+
return Number(id);
|
|
56
|
+
};
|
|
57
|
+
export const parseSendId = (typed) => {
|
|
58
|
+
if (!/^-?\d{1,20}$/.test(typed))
|
|
59
|
+
throw new CliError("validation_error", "--operation-id is the number a failed send printed");
|
|
60
|
+
return Long.fromString(typed);
|
|
61
|
+
};
|
|
62
|
+
export const forwardedCopy = (updates) => {
|
|
63
|
+
if (updates._ !== "updates" && updates._ !== "updatesCombined")
|
|
64
|
+
return undefined;
|
|
65
|
+
const update = updates.updates.find((one) => one._ === "updateNewMessage" || one._ === "updateNewChannelMessage");
|
|
66
|
+
return update && "message" in update ? new TgMessage(update.message, PeersIndex.from(updates)) : undefined;
|
|
67
|
+
};
|
|
68
|
+
export const remoteMessage = (message) => observedCounters(toMessage(message), new Date().toISOString(), ["views", "reactions", "comments"]);
|
|
69
|
+
export const remoteHit = (message, source) => ({
|
|
70
|
+
...toMessageHit(message),
|
|
71
|
+
...observedCounters(toMessage(message), new Date().toISOString(), ["views", "reactions", "comments"], source),
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../../src/telegram/feature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,IAAI,EAAE,UAAU,EAAuB,OAAO,IAAI,SAAS,EAAW,MAAM,cAAc,CAAA;AACvH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAiC,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAElD,+FAA+F;AAC/F,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,uBAAuB;IACvB,cAAc;IACd,oBAAoB;IACpB,mBAAmB;IACnB,iBAAiB;IACjB,iBAAiB;IACjB,YAAY;IACZ,oBAAoB;IACpB,q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ange, FolderRules } from "@wirecat/cli-core";
|
|
2
|
+
import type { Feature } from "./feature.js";
|
|
3
|
+
export declare const folders: (feature: Feature) => Promise<Folder[]>;
|
|
4
|
+
export declare const createFolder: (feature: Feature, title: string, chatIds: string[], rules?: FolderRules) => Promise<Folder>;
|
|
5
|
+
/** Telegram replaces a folder's chats as a list, so the ones it has are read and only the asked ones change. */
|
|
6
|
+
export declare const updateFolder: (feature: Feature, folderId: string, change: FolderChange) => Promise<Folder>;
|
|
7
|
+
export declare const deleteFolder: (feature: Feature, folderId: string) => Promise<void>;
|
|
8
|
+
/** "All chats" (id 0) keeps its place: only Premium accounts may move it, and tg does not list it. */
|
|
9
|
+
export declare const orderFolders: (feature: Feature, folderIds: string[]) => Promise<void>;
|
|
10
|
+
export declare const joinFolder: (feature: Feature, link: string) => Promise<Folder>;
|
|
11
|
+
//# sourceMappingURL=folders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folders.d.ts","sourceRoot":"","sources":["../../src/telegram/folders.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAkB3C,eAAO,MAAM,OAAO,YAAa,OAAO,KAAG,OAAO,CAAC,MAAM,EAAE,CACsD,CAAA;AAEjH,eAAO,MAAM,YAAY,YAAa,OAAO,SAAS,MAAM,WAAW,MAAM,EAAE,UAAS,WAAW,oBAoBhG,CAAA;AAEH,gHAAgH;AAChH,eAAO,MAAM,YAAY,YAAa,OAAO,YAAY,MAAM,UAAU,YAAY,KAAG,OAAO,CAAC,MAAM,CA2CrG,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,OAAO,YAAY,MAAM,KAAG,OAAO,CAAC,IAAI,CAG1E,CAAA;AAEJ,sGAAsG;AACtG,eAAO,MAAM,YAAY,YAAa,OAAO,aAAa,MAAM,EAAE,KAAG,OAAO,CAAC,IAAI,CAO7E,CAAA;AAEJ,eAAO,MAAM,UAAU,YAAa,OAAO,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAgBvE,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getMarkedPeerId, tl } from "@mtcute/node";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { ruleFlags } from "./folder-rules.js";
|
|
4
|
+
import { toFolder } from "./map.js";
|
|
5
|
+
const filtersOf = async ({ client }) => (await client.getFolders()).filters;
|
|
6
|
+
/**
|
|
7
|
+
* mtcute answers with the folder it sent, but Telegram drops what it does not take — an emoji that is not
|
|
8
|
+
* one of its folder icons, measured live 2026-10-08 — so the answer is read back.
|
|
9
|
+
*/
|
|
10
|
+
const storedFolder = async (feature, sent) => {
|
|
11
|
+
const stored = sent._ === "dialogFilterDefault"
|
|
12
|
+
? undefined
|
|
13
|
+
: (await filtersOf(feature)).find((one) => one._ !== "dialogFilterDefault" && one.id === sent.id);
|
|
14
|
+
return toFolder(stored ?? sent);
|
|
15
|
+
};
|
|
16
|
+
export const folders = (feature) => feature.call(async () => (await filtersOf(feature)).map(toFolder).filter((one) => one !== null));
|
|
17
|
+
export const createFolder = (feature, title, chatIds, rules = {}) => feature.write({
|
|
18
|
+
what: "the folder may have been made",
|
|
19
|
+
check: "chats.folders.list",
|
|
20
|
+
after: "before repeating — a repeat makes a second one",
|
|
21
|
+
}, async () => {
|
|
22
|
+
const peers = (ids = []) => Promise.all(ids.map((id) => feature.client.resolvePeer(Number(id))));
|
|
23
|
+
const pinned = new Set(rules.pin);
|
|
24
|
+
const made = await feature.client.createFolder({
|
|
25
|
+
title: { _: "textWithEntities", text: title, entities: [] },
|
|
26
|
+
includePeers: await peers(chatIds.filter((id) => !pinned.has(id))),
|
|
27
|
+
pinnedPeers: await peers(rules.pin),
|
|
28
|
+
excludePeers: await peers(rules.exclude),
|
|
29
|
+
...(rules.emoji === undefined ? {} : { emoticon: rules.emoji }),
|
|
30
|
+
...ruleFlags(rules),
|
|
31
|
+
});
|
|
32
|
+
return storedFolder(feature, made);
|
|
33
|
+
});
|
|
34
|
+
/** Telegram replaces a folder's chats as a list, so the ones it has are read and only the asked ones change. */
|
|
35
|
+
export const updateFolder = (feature, folderId, change) => {
|
|
36
|
+
const { title, add = [], remove = [], exclude = [], pin = [], emoji, include, skip } = change;
|
|
37
|
+
return feature.write("the folder may have changed — repeating it is safe", async () => {
|
|
38
|
+
const current = (await filtersOf(feature)).find((one) => one._ !== "dialogFilterDefault" && String(one.id) === folderId);
|
|
39
|
+
if (!current || current._ === "dialogFilterDefault")
|
|
40
|
+
throw new CliError("not_found", `no folder ${folderId}`);
|
|
41
|
+
const rulesAsked = include !== undefined || skip !== undefined || exclude.length > 0;
|
|
42
|
+
if (rulesAsked && current._ === "dialogFilterChatlist")
|
|
43
|
+
throw new CliError("validation_error", "a folder shared by a link holds only its chats; it takes no rules");
|
|
44
|
+
// A chat sits on one list at a time: pinning or excluding it takes it off the others.
|
|
45
|
+
const idOf = (peer) => String(getMarkedPeerId(peer));
|
|
46
|
+
const off = (peers, ...ids) => {
|
|
47
|
+
const gone = new Set(ids.flat());
|
|
48
|
+
return peers.filter((peer) => !gone.has(idOf(peer)));
|
|
49
|
+
};
|
|
50
|
+
const resolved = (ids, have) => {
|
|
51
|
+
const held = new Set(have.map(idOf));
|
|
52
|
+
return Promise.all(ids.filter((id) => !held.has(id)).map((id) => feature.client.resolvePeer(Number(id))));
|
|
53
|
+
};
|
|
54
|
+
const include0 = off(current.includePeers, remove, pin, exclude);
|
|
55
|
+
const pinned0 = off(current.pinnedPeers, remove, exclude);
|
|
56
|
+
const listsChanged = add.length > 0 || remove.length > 0 || pin.length > 0 || exclude.length > 0;
|
|
57
|
+
const excluded0 = current._ === "dialogFilter" ? off(current.excludePeers, remove, add, pin) : [];
|
|
58
|
+
const changed = await feature.client.editFolder({
|
|
59
|
+
folder: current._ === "dialogFilter" ? current : current.id,
|
|
60
|
+
modification: {
|
|
61
|
+
...(title === undefined ? {} : { title: { _: "textWithEntities", text: title, entities: [] } }),
|
|
62
|
+
...(emoji === undefined ? {} : { emoticon: emoji }),
|
|
63
|
+
...ruleFlags({ ...(include === undefined ? {} : { include }), ...(skip === undefined ? {} : { skip }) }),
|
|
64
|
+
...(listsChanged
|
|
65
|
+
? {
|
|
66
|
+
includePeers: [...include0, ...(await resolved(add, [...include0, ...pinned0]))],
|
|
67
|
+
pinnedPeers: [...pinned0, ...(await resolved(pin, pinned0))],
|
|
68
|
+
...(current._ === "dialogFilter"
|
|
69
|
+
? { excludePeers: [...excluded0, ...(await resolved(exclude, excluded0))] }
|
|
70
|
+
: {}),
|
|
71
|
+
}
|
|
72
|
+
: {}),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return storedFolder(feature, changed);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
export const deleteFolder = (feature, folderId) => feature.write("the folder may have been deleted — repeating it is safe", async () => {
|
|
79
|
+
await feature.client.deleteFolder(Number(folderId));
|
|
80
|
+
});
|
|
81
|
+
/** "All chats" (id 0) keeps its place: only Premium accounts may move it, and tg does not list it. */
|
|
82
|
+
export const orderFolders = (feature, folderIds) => feature.write("the folders may be in the new order already — repeating it is safe", async () => {
|
|
83
|
+
const current = (await filtersOf(feature)).map((one) => (one._ === "dialogFilterDefault" ? 0 : one.id));
|
|
84
|
+
const order = folderIds.map(Number);
|
|
85
|
+
const all = current.indexOf(0);
|
|
86
|
+
if (all >= 0)
|
|
87
|
+
order.splice(all, 0, 0);
|
|
88
|
+
await feature.client.setFoldersOrder(order);
|
|
89
|
+
});
|
|
90
|
+
export const joinFolder = (feature, link) => feature.write({
|
|
91
|
+
what: "the folder may have been joined",
|
|
92
|
+
check: "chats.folders.list",
|
|
93
|
+
after: "before repeating — a repeat joins nothing new",
|
|
94
|
+
}, async () => {
|
|
95
|
+
try {
|
|
96
|
+
return toFolder(await feature.client.joinChatlist(link));
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (tl.RpcError.is(error, "INVITE_SLUG_EXPIRED") || tl.RpcError.is(error, "INVITE_SLUG_INVALID"))
|
|
100
|
+
throw new CliError("not_found", "this folder link is invalid or has expired");
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=folders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folders.js","sourceRoot":"","sources":["../../src/telegram/folders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,MAAM,SAAS,GAAG,KAAK,EAAE,EAAE,MAAM,EAAW,EAAkC,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAA;AAEpH;;;GAGG;AACH,MAAM,YAAY,GAAG,KAAK,EAAE,OAAgB,EAAE,IAAyB,EAAmB,EAAE;IAC1F,MAAM,MAAM,GACV,IAAI,CAAC,CAAC,KAAK,qBAAqB;QAC9B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,qBAAqB,IAAI,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAA;IACrG,OAAO,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAW,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAqB,EAAE,CAC7D,OAAO,CAAC,IAAI,CAAC,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J,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,IAAY,EAAmB,EAAE,CAC5E,OAAO,CAAC,KAAK,CACX;IACE,IAAI,EAAE,iCAAiC;IACvC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,+CAA+C;CACvD,EACD,KAAK,IAAI,EAAE;IACT,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAW,CAAA;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,CAAC;YAC9F,MAAM,IAAI,QAAQ,CAAC,WAAW,EAAE,4CAA4C,CAAC,CAAA;QAC/E,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC,CACF,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type InputPeerLike, type Peer } from "@mtcute/node";
|
|
2
|
+
import type { AdminRight, ChatEvents, GroupCard, GroupChange, GroupMember, InviteLinkChange, LinkTarget, Page } from "@wirecat/cli-core";
|
|
3
|
+
import { type Feature } from "./feature.js";
|
|
4
|
+
import { GROUP_SETTINGS } from "./map.js";
|
|
5
|
+
export { GROUP_SETTINGS };
|
|
6
|
+
/** The rights `chats admins add --can` offers: max's, less `read`. */
|
|
7
|
+
export declare const ADMIN_RIGHTS: AdminRight[];
|
|
8
|
+
/**
|
|
9
|
+
* A supergroup's own count is its member list's total: its chat object and its full info both said 1 for a
|
|
10
|
+
* group of 2, seen live. A list hidden from non-admins answers only part of the group, so then the full info's
|
|
11
|
+
* count stands, which the shorter list never reaches. A basic group's list total is only the page it read.
|
|
12
|
+
*/
|
|
13
|
+
export declare const groupCount: ({ client }: Feature, group: Peer, listTotal: number | null) => Promise<number | null>;
|
|
14
|
+
/** `null` when the group hides its member list from us: that is an answer about the group, not a failure. */
|
|
15
|
+
export declare const membersOf: ({ client, login, checks }: Feature, peer: InputPeerLike) => Promise<import("@mtcute/node").ArrayWithTotal<import("@mtcute/node").ChatMember> | null>;
|
|
16
|
+
/** An invite is previewed; one the owner already joined, or a public link, is read as the chat. Nothing joins. */
|
|
17
|
+
export declare const inspect: (feature: Feature, link: string) => Promise<LinkTarget>;
|
|
18
|
+
/**
|
|
19
|
+
* A page of a group's members, 200 a request, a second apart. Telegram gives at most `MEMBERS_MAX` of a big
|
|
20
|
+
* group, and a group that hides its list answers only its admins or refuses.
|
|
21
|
+
*/
|
|
22
|
+
export declare const members: (feature: Feature, reference: string, { limit, offset }: {
|
|
23
|
+
limit?: number;
|
|
24
|
+
offset: number;
|
|
25
|
+
}) => Promise<Page<GroupMember> & {
|
|
26
|
+
chatId: string;
|
|
27
|
+
participantsCount: number | null;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Service messages back to `since`, newest page first, at most `EVENT_PAGES` of them — a busy
|
|
31
|
+
* group's week can be thousands. The people a message names only by id are looked up in one call.
|
|
32
|
+
*/
|
|
33
|
+
export declare const chatEvents: (feature: Feature, reference: string, { since }: {
|
|
34
|
+
since: number;
|
|
35
|
+
}) => Promise<ChatEvents>;
|
|
36
|
+
/**
|
|
37
|
+
* A group's admins and its creator, for `review --unanswered`; `null` when the group hides them.
|
|
38
|
+
* A basic group ignores the `admins` filter and answers everyone, hence the status check.
|
|
39
|
+
*/
|
|
40
|
+
export declare const admins: (feature: Feature, reference: string) => Promise<string[] | null>;
|
|
41
|
+
/** Each reference as a user id, in order; a group or a channel is not a person and is refused. */
|
|
42
|
+
export declare const people: (feature: Feature, references: string[]) => Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Always a supergroup, never a legacy group: a legacy group turns into a supergroup on some changes
|
|
45
|
+
* and its id changes with it. The people are added after, so a group exists even if some cannot be.
|
|
46
|
+
*/
|
|
47
|
+
export declare const createGroup: (feature: Feature, title: string, invited: string[], { channel }: {
|
|
48
|
+
channel: boolean;
|
|
49
|
+
}) => Promise<GroupCard>;
|
|
50
|
+
/** An invite link, or a public one; a group that asks its admins first answers `requested`. */
|
|
51
|
+
export declare const join: (feature: Feature, link: string) => Promise<GroupCard | {
|
|
52
|
+
requested: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const leave: (feature: Feature, reference: string) => Promise<{
|
|
55
|
+
chatId: string;
|
|
56
|
+
}>;
|
|
57
|
+
export declare const group: (feature: Feature, reference: string) => Promise<GroupCard>;
|
|
58
|
+
/**
|
|
59
|
+
* Telegram keeps what members may do as rights taken away, and sets them all at once: the current
|
|
60
|
+
* ones are read first, and only the switches asked for change.
|
|
61
|
+
*/
|
|
62
|
+
export declare const updateGroup: (feature: Feature, chatId: string, { title, description, settings }: GroupChange) => Promise<GroupCard>;
|
|
63
|
+
/** A new primary link for the owner; the old one stops working. */
|
|
64
|
+
export declare const resetInviteLink: (feature: Feature, chatId: string) => Promise<GroupCard>;
|
|
65
|
+
export declare const createInviteLink: (feature: Feature, chatId: string, { approval, expiresAt, maxUses }: {
|
|
66
|
+
approval: boolean;
|
|
67
|
+
expiresAt?: string;
|
|
68
|
+
maxUses?: number;
|
|
69
|
+
}) => Promise<import("@wirecat/cli-core").InviteLink>;
|
|
70
|
+
export declare const joinRequests: (feature: Feature, chatId: string, { limit, link, search }: {
|
|
71
|
+
limit: number;
|
|
72
|
+
link?: string;
|
|
73
|
+
search?: string;
|
|
74
|
+
}) => Promise<Page<import("@wirecat/cli-core").JoinRequest> & {
|
|
75
|
+
total: number;
|
|
76
|
+
}>;
|
|
77
|
+
export declare const answerAllJoinRequests: (feature: Feature, chatId: string, accept: boolean, link?: string) => Promise<void>;
|
|
78
|
+
/** Telegram shows an admin only their own links; the creator could ask for others', which we do not. */
|
|
79
|
+
export declare const inviteLinks: (feature: Feature, chatId: string, { limit, revoked }: {
|
|
80
|
+
limit: number;
|
|
81
|
+
revoked: boolean;
|
|
82
|
+
}) => Promise<{
|
|
83
|
+
items: import("@wirecat/cli-core").InviteLink[];
|
|
84
|
+
hasMore: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
export declare const revokeInviteLink: (feature: Feature, chatId: string, link: string) => Promise<import("@wirecat/cli-core").InviteLink>;
|
|
87
|
+
export declare const updateInviteLink: (feature: Feature, chatId: string, link: string, { approval, expiresAt, maxUses }: InviteLinkChange) => Promise<import("@wirecat/cli-core").InviteLink>;
|
|
88
|
+
export declare const answerJoinRequest: (feature: Feature, chatId: string, personId: string, accept: boolean) => Promise<{
|
|
89
|
+
already: boolean;
|
|
90
|
+
}>;
|
|
91
|
+
/** A supergroup shows new members its history by its own setting, never per person: `history` is refused. */
|
|
92
|
+
export declare const addMembers: (feature: Feature, chatId: string, added: string[], { history }: {
|
|
93
|
+
history?: boolean;
|
|
94
|
+
}) => Promise<{
|
|
95
|
+
notAdded: string[];
|
|
96
|
+
}>;
|
|
97
|
+
/** One request per person, in turn: Telegram rate-limits these hard. */
|
|
98
|
+
export declare const removeMembers: (feature: Feature, chatId: string, removed: string[]) => Promise<void>;
|
|
99
|
+
export declare const addAdmin: (feature: Feature, chatId: string, person: string, rights: AdminRight[]) => Promise<void>;
|
|
100
|
+
export declare const removeAdmin: (feature: Feature, chatId: string, person: string) => Promise<void>;
|
|
101
|
+
//# sourceMappingURL=groups.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../../src/telegram/groups.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAElB,KAAK,IAAI,EAKV,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,IAAI,EACL,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,cAAc,CA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