@inline-openclaw/inline 0.0.18 → 0.0.19
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/index.js +37064 -22
- package/dist/index.js.map +149 -1
- package/package.json +2 -2
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/inline/accounts.d.ts +0 -20
- package/dist/inline/accounts.d.ts.map +0 -1
- package/dist/inline/accounts.js +0 -84
- package/dist/inline/accounts.js.map +0 -1
- package/dist/inline/actions.d.ts +0 -4
- package/dist/inline/actions.d.ts.map +0 -1
- package/dist/inline/actions.js +0 -1364
- package/dist/inline/actions.js.map +0 -1
- package/dist/inline/channel.d.ts +0 -4
- package/dist/inline/channel.d.ts.map +0 -1
- package/dist/inline/channel.js +0 -867
- package/dist/inline/channel.js.map +0 -1
- package/dist/inline/config-schema.d.ts +0 -453
- package/dist/inline/config-schema.d.ts.map +0 -1
- package/dist/inline/config-schema.js +0 -75
- package/dist/inline/config-schema.js.map +0 -1
- package/dist/inline/media.d.ts +0 -9
- package/dist/inline/media.d.ts.map +0 -1
- package/dist/inline/media.js +0 -213
- package/dist/inline/media.js.map +0 -1
- package/dist/inline/members-tool.d.ts +0 -6
- package/dist/inline/members-tool.d.ts.map +0 -1
- package/dist/inline/members-tool.js +0 -135
- package/dist/inline/members-tool.js.map +0 -1
- package/dist/inline/message-content.d.ts +0 -51
- package/dist/inline/message-content.d.ts.map +0 -1
- package/dist/inline/message-content.js +0 -305
- package/dist/inline/message-content.js.map +0 -1
- package/dist/inline/message-tools.d.ts +0 -10
- package/dist/inline/message-tools.d.ts.map +0 -1
- package/dist/inline/message-tools.js +0 -395
- package/dist/inline/message-tools.js.map +0 -1
- package/dist/inline/monitor.d.ts +0 -26
- package/dist/inline/monitor.d.ts.map +0 -1
- package/dist/inline/monitor.js +0 -1098
- package/dist/inline/monitor.js.map +0 -1
- package/dist/inline/normalize.d.ts +0 -3
- package/dist/inline/normalize.d.ts.map +0 -1
- package/dist/inline/normalize.js +0 -25
- package/dist/inline/normalize.js.map +0 -1
- package/dist/inline/policy.d.ts +0 -19
- package/dist/inline/policy.d.ts.map +0 -1
- package/dist/inline/policy.js +0 -107
- package/dist/inline/policy.js.map +0 -1
- package/dist/inline/space-members.d.ts +0 -22
- package/dist/inline/space-members.d.ts.map +0 -1
- package/dist/inline/space-members.js +0 -57
- package/dist/inline/space-members.js.map +0 -1
- package/dist/runtime.d.ts +0 -4
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -11
- package/dist/runtime.js.map +0 -1
package/dist/inline/actions.js
DELETED
|
@@ -1,1364 +0,0 @@
|
|
|
1
|
-
import { createActionGate, jsonResult, readReactionParams, readNumberParam, readStringParam, } from "openclaw/plugin-sdk";
|
|
2
|
-
import { InlineSdkClient, Method, } from "@inline-chat/realtime-sdk";
|
|
3
|
-
import { resolveInlineAccount, resolveInlineToken } from "./accounts.js";
|
|
4
|
-
import { uploadInlineMediaFromUrl } from "./media.js";
|
|
5
|
-
import { summarizeInlineMessageContent } from "./message-content.js";
|
|
6
|
-
import { normalizeInlineTarget } from "./normalize.js";
|
|
7
|
-
import { buildInlineUserDisplayName, getSpaceMembersWithUsers } from "./space-members.js";
|
|
8
|
-
const ACTION_GROUPS = [
|
|
9
|
-
{ key: "send", defaultEnabled: true, actions: ["send", "sendAttachment"] },
|
|
10
|
-
{ key: "reply", defaultEnabled: true, actions: ["reply", "thread-reply"] },
|
|
11
|
-
{ key: "reactions", defaultEnabled: true, actions: ["react", "reactions"] },
|
|
12
|
-
{ key: "read", defaultEnabled: true, actions: ["read"] },
|
|
13
|
-
{ key: "search", defaultEnabled: true, actions: ["search"] },
|
|
14
|
-
{ key: "edit", defaultEnabled: true, actions: ["edit"] },
|
|
15
|
-
{
|
|
16
|
-
key: "channels",
|
|
17
|
-
defaultEnabled: true,
|
|
18
|
-
actions: [
|
|
19
|
-
"channel-info",
|
|
20
|
-
"channel-edit",
|
|
21
|
-
"renameGroup",
|
|
22
|
-
"channel-list",
|
|
23
|
-
"channel-create",
|
|
24
|
-
"channel-delete",
|
|
25
|
-
"channel-move",
|
|
26
|
-
"thread-list",
|
|
27
|
-
"thread-create",
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
key: "participants",
|
|
32
|
-
defaultEnabled: true,
|
|
33
|
-
actions: ["addParticipant", "removeParticipant", "kick", "leaveGroup", "member-info"],
|
|
34
|
-
},
|
|
35
|
-
{ key: "delete", defaultEnabled: true, actions: ["delete", "unsend"] },
|
|
36
|
-
{ key: "pins", defaultEnabled: true, actions: ["pin", "unpin", "list-pins"] },
|
|
37
|
-
{ key: "permissions", defaultEnabled: true, actions: ["permissions"] },
|
|
38
|
-
];
|
|
39
|
-
const ACTION_TO_GATE_KEY = new Map();
|
|
40
|
-
for (const group of ACTION_GROUPS) {
|
|
41
|
-
for (const action of group.actions) {
|
|
42
|
-
ACTION_TO_GATE_KEY.set(action, group.key);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const SUPPORTED_ACTIONS = Array.from(ACTION_TO_GATE_KEY.keys());
|
|
46
|
-
const GET_MESSAGES_METHOD = typeof Method.GET_MESSAGES === "number" &&
|
|
47
|
-
Number.isInteger(Method.GET_MESSAGES) &&
|
|
48
|
-
Method.GET_MESSAGES > 0
|
|
49
|
-
? Method.GET_MESSAGES
|
|
50
|
-
: null;
|
|
51
|
-
function normalizeChatId(raw) {
|
|
52
|
-
const normalized = normalizeInlineTarget(raw) ?? raw.trim();
|
|
53
|
-
if (!/^[0-9]+$/.test(normalized)) {
|
|
54
|
-
throw new Error(`inline action: invalid chat target "${raw}" (expected numeric chat id)`);
|
|
55
|
-
}
|
|
56
|
-
return normalized;
|
|
57
|
-
}
|
|
58
|
-
function readFlexibleId(params, key) {
|
|
59
|
-
const direct = params[key];
|
|
60
|
-
if (typeof direct === "bigint")
|
|
61
|
-
return direct.toString();
|
|
62
|
-
if (typeof direct === "number") {
|
|
63
|
-
if (!Number.isFinite(direct) || !Number.isInteger(direct))
|
|
64
|
-
return undefined;
|
|
65
|
-
return String(direct);
|
|
66
|
-
}
|
|
67
|
-
if (typeof direct === "string") {
|
|
68
|
-
const trimmed = direct.trim();
|
|
69
|
-
return trimmed || undefined;
|
|
70
|
-
}
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
function readBooleanParam(params, key) {
|
|
74
|
-
const value = params[key];
|
|
75
|
-
if (typeof value === "boolean")
|
|
76
|
-
return value;
|
|
77
|
-
if (typeof value === "string") {
|
|
78
|
-
const trimmed = value.trim().toLowerCase();
|
|
79
|
-
if (trimmed === "true")
|
|
80
|
-
return true;
|
|
81
|
-
if (trimmed === "false")
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
function parseInlineId(raw, label) {
|
|
87
|
-
if (typeof raw === "bigint") {
|
|
88
|
-
if (raw < 0n) {
|
|
89
|
-
throw new Error(`inline action: invalid ${label} "${raw.toString()}"`);
|
|
90
|
-
}
|
|
91
|
-
return raw;
|
|
92
|
-
}
|
|
93
|
-
if (typeof raw === "number") {
|
|
94
|
-
if (!Number.isFinite(raw) || !Number.isInteger(raw) || raw < 0) {
|
|
95
|
-
throw new Error(`inline action: invalid ${label} "${String(raw)}"`);
|
|
96
|
-
}
|
|
97
|
-
return BigInt(raw);
|
|
98
|
-
}
|
|
99
|
-
if (typeof raw === "string") {
|
|
100
|
-
const trimmed = raw.trim();
|
|
101
|
-
if (!trimmed) {
|
|
102
|
-
throw new Error(`inline action: missing ${label}`);
|
|
103
|
-
}
|
|
104
|
-
if (!/^[0-9]+$/.test(trimmed)) {
|
|
105
|
-
throw new Error(`inline action: invalid ${label} "${raw}"`);
|
|
106
|
-
}
|
|
107
|
-
return BigInt(trimmed);
|
|
108
|
-
}
|
|
109
|
-
throw new Error(`inline action: missing ${label}`);
|
|
110
|
-
}
|
|
111
|
-
function parseOptionalInlineId(raw, label) {
|
|
112
|
-
if (raw == null)
|
|
113
|
-
return undefined;
|
|
114
|
-
return parseInlineId(raw, label);
|
|
115
|
-
}
|
|
116
|
-
function parseInlineIdList(raw, label) {
|
|
117
|
-
if (raw == null)
|
|
118
|
-
return [];
|
|
119
|
-
if (Array.isArray(raw)) {
|
|
120
|
-
return raw.map((item) => parseInlineId(item, label));
|
|
121
|
-
}
|
|
122
|
-
if (typeof raw === "string") {
|
|
123
|
-
const trimmed = raw.trim();
|
|
124
|
-
if (!trimmed)
|
|
125
|
-
return [];
|
|
126
|
-
const chunks = trimmed
|
|
127
|
-
.split(",")
|
|
128
|
-
.map((item) => item.trim())
|
|
129
|
-
.filter(Boolean);
|
|
130
|
-
if (chunks.length <= 1) {
|
|
131
|
-
return [parseInlineId(trimmed, label)];
|
|
132
|
-
}
|
|
133
|
-
return chunks.map((item) => parseInlineId(item, label));
|
|
134
|
-
}
|
|
135
|
-
return [parseInlineId(raw, label)];
|
|
136
|
-
}
|
|
137
|
-
function parseInlineIdListFromParams(params, key) {
|
|
138
|
-
const direct = params[key];
|
|
139
|
-
if (direct != null) {
|
|
140
|
-
return parseInlineIdList(direct, key);
|
|
141
|
-
}
|
|
142
|
-
return [];
|
|
143
|
-
}
|
|
144
|
-
function parseInlineListValue(raw, label) {
|
|
145
|
-
if (raw == null)
|
|
146
|
-
return [];
|
|
147
|
-
if (Array.isArray(raw)) {
|
|
148
|
-
return raw.flatMap((entry) => parseInlineListValue(entry, label));
|
|
149
|
-
}
|
|
150
|
-
if (typeof raw === "bigint")
|
|
151
|
-
return [raw.toString()];
|
|
152
|
-
if (typeof raw === "number") {
|
|
153
|
-
if (!Number.isFinite(raw) || !Number.isInteger(raw) || raw < 0) {
|
|
154
|
-
throw new Error(`inline action: invalid ${label} "${String(raw)}"`);
|
|
155
|
-
}
|
|
156
|
-
return [String(raw)];
|
|
157
|
-
}
|
|
158
|
-
if (typeof raw === "string") {
|
|
159
|
-
const trimmed = raw.trim();
|
|
160
|
-
if (!trimmed)
|
|
161
|
-
return [];
|
|
162
|
-
return trimmed
|
|
163
|
-
.split(",")
|
|
164
|
-
.map((entry) => entry.trim())
|
|
165
|
-
.filter(Boolean);
|
|
166
|
-
}
|
|
167
|
-
throw new Error(`inline action: invalid ${label}`);
|
|
168
|
-
}
|
|
169
|
-
function parseInlineListValuesFromParams(params, keys) {
|
|
170
|
-
const entries = keys.flatMap((key) => parseInlineListValue(params[key], key));
|
|
171
|
-
return Array.from(new Set(entries.map((entry) => entry.trim()).filter(Boolean)));
|
|
172
|
-
}
|
|
173
|
-
function resolveInlineOutboundMediaInputs(params) {
|
|
174
|
-
const plural = parseInlineListValuesFromParams(params, [
|
|
175
|
-
"mediaUrls",
|
|
176
|
-
"attachmentUrls",
|
|
177
|
-
"filePaths",
|
|
178
|
-
"paths",
|
|
179
|
-
"files",
|
|
180
|
-
]);
|
|
181
|
-
const single = parseInlineListValuesFromParams(params, [
|
|
182
|
-
"mediaUrl",
|
|
183
|
-
"attachmentUrl",
|
|
184
|
-
"url",
|
|
185
|
-
"media",
|
|
186
|
-
"filePath",
|
|
187
|
-
"path",
|
|
188
|
-
"file",
|
|
189
|
-
]);
|
|
190
|
-
return Array.from(new Set([...plural, ...single]));
|
|
191
|
-
}
|
|
192
|
-
function normalizeInlineUserLookupToken(raw) {
|
|
193
|
-
return raw
|
|
194
|
-
.trim()
|
|
195
|
-
.replace(/^inline:/i, "")
|
|
196
|
-
.replace(/^user:/i, "")
|
|
197
|
-
.replace(/^@/, "")
|
|
198
|
-
.trim();
|
|
199
|
-
}
|
|
200
|
-
function parseInlineIdIfNumericToken(raw) {
|
|
201
|
-
const normalized = normalizeInlineUserLookupToken(raw);
|
|
202
|
-
if (!/^[0-9]+$/.test(normalized))
|
|
203
|
-
return undefined;
|
|
204
|
-
return BigInt(normalized);
|
|
205
|
-
}
|
|
206
|
-
function buildInlineUserHaystack(user) {
|
|
207
|
-
return [
|
|
208
|
-
String(user.id),
|
|
209
|
-
buildInlineUserDisplayName(user),
|
|
210
|
-
user.firstName ?? "",
|
|
211
|
-
user.lastName ?? "",
|
|
212
|
-
user.username ?? "",
|
|
213
|
-
]
|
|
214
|
-
.join("\n")
|
|
215
|
-
.toLowerCase();
|
|
216
|
-
}
|
|
217
|
-
function resolveInlineUsersByToken(params) {
|
|
218
|
-
const normalized = normalizeInlineUserLookupToken(params.token);
|
|
219
|
-
if (!normalized)
|
|
220
|
-
return [];
|
|
221
|
-
const lowered = normalized.toLowerCase();
|
|
222
|
-
const numericId = parseInlineIdIfNumericToken(normalized);
|
|
223
|
-
if (numericId != null) {
|
|
224
|
-
return params.users.filter((user) => user.id === numericId);
|
|
225
|
-
}
|
|
226
|
-
const byUsername = params.users.filter((user) => (user.username ?? "").trim().toLowerCase() === lowered);
|
|
227
|
-
if (byUsername.length > 0) {
|
|
228
|
-
return byUsername;
|
|
229
|
-
}
|
|
230
|
-
const byExactName = params.users.filter((user) => buildInlineUserDisplayName(user).trim().toLowerCase() === lowered);
|
|
231
|
-
if (byExactName.length > 0) {
|
|
232
|
-
return byExactName;
|
|
233
|
-
}
|
|
234
|
-
return params.users.filter((user) => buildInlineUserHaystack(user).includes(lowered));
|
|
235
|
-
}
|
|
236
|
-
async function fetchInlineUsersForResolution(client) {
|
|
237
|
-
const result = await client.invokeRaw(Method.GET_CHATS, {
|
|
238
|
-
oneofKind: "getChats",
|
|
239
|
-
getChats: {},
|
|
240
|
-
});
|
|
241
|
-
if (result.oneofKind !== "getChats") {
|
|
242
|
-
throw new Error(`inline action: expected getChats result, got ${String(result.oneofKind)}`);
|
|
243
|
-
}
|
|
244
|
-
return result.getChats.users ?? [];
|
|
245
|
-
}
|
|
246
|
-
async function resolveInlineUserIdsFromParams(params) {
|
|
247
|
-
if (params.values.length === 0)
|
|
248
|
-
return [];
|
|
249
|
-
const resolved = [];
|
|
250
|
-
const unresolved = [];
|
|
251
|
-
for (const value of params.values) {
|
|
252
|
-
const numericId = parseInlineIdIfNumericToken(value);
|
|
253
|
-
if (numericId != null) {
|
|
254
|
-
resolved.push(numericId);
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
unresolved.push(value);
|
|
258
|
-
}
|
|
259
|
-
if (unresolved.length > 0) {
|
|
260
|
-
const users = await fetchInlineUsersForResolution(params.client);
|
|
261
|
-
for (const token of unresolved) {
|
|
262
|
-
const matches = resolveInlineUsersByToken({ users, token });
|
|
263
|
-
if (matches.length === 0) {
|
|
264
|
-
throw new Error(`inline action: could not resolve ${params.label} "${token}"`);
|
|
265
|
-
}
|
|
266
|
-
if (matches.length > 1) {
|
|
267
|
-
throw new Error(`inline action: ambiguous ${params.label} "${token}"`);
|
|
268
|
-
}
|
|
269
|
-
const match = matches[0];
|
|
270
|
-
if (!match) {
|
|
271
|
-
throw new Error(`inline action: could not resolve ${params.label} "${token}"`);
|
|
272
|
-
}
|
|
273
|
-
resolved.push(match.id);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return Array.from(new Set(resolved.map((id) => id.toString()))).map((id) => BigInt(id));
|
|
277
|
-
}
|
|
278
|
-
function resolveChatIdFromParams(params) {
|
|
279
|
-
const raw = readFlexibleId(params, "chatId") ??
|
|
280
|
-
readFlexibleId(params, "channelId") ??
|
|
281
|
-
readFlexibleId(params, "to") ??
|
|
282
|
-
readStringParam(params, "to");
|
|
283
|
-
if (!raw) {
|
|
284
|
-
throw new Error("inline action requires chatId/channelId/to");
|
|
285
|
-
}
|
|
286
|
-
return BigInt(normalizeChatId(raw));
|
|
287
|
-
}
|
|
288
|
-
function resolveMessageSendTargetFromParams(params) {
|
|
289
|
-
const explicitUserIdRaw = readFlexibleId(params, "userId") ?? readStringParam(params, "userId");
|
|
290
|
-
if (explicitUserIdRaw) {
|
|
291
|
-
const userId = parseInlineId(explicitUserIdRaw, "userId");
|
|
292
|
-
return {
|
|
293
|
-
target: `user:${String(userId)}`,
|
|
294
|
-
userId,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
const rawTarget = readFlexibleId(params, "to") ?? readStringParam(params, "to");
|
|
298
|
-
if (rawTarget) {
|
|
299
|
-
const normalized = normalizeInlineTarget(rawTarget) ?? rawTarget.trim();
|
|
300
|
-
const userMatch = normalized.match(/^user:([0-9]+)$/i);
|
|
301
|
-
if (userMatch?.[1]) {
|
|
302
|
-
return {
|
|
303
|
-
target: `user:${userMatch[1]}`,
|
|
304
|
-
userId: BigInt(userMatch[1]),
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
if (!/^[0-9]+$/.test(normalized)) {
|
|
308
|
-
throw new Error(`inline action: invalid target "${rawTarget}"`);
|
|
309
|
-
}
|
|
310
|
-
return {
|
|
311
|
-
target: normalized,
|
|
312
|
-
chatId: BigInt(normalized),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
const rawChatId = readFlexibleId(params, "chatId") ??
|
|
316
|
-
readStringParam(params, "chatId") ??
|
|
317
|
-
readFlexibleId(params, "channelId") ??
|
|
318
|
-
readStringParam(params, "channelId");
|
|
319
|
-
if (!rawChatId) {
|
|
320
|
-
throw new Error("inline action requires to/chatId/channelId/userId");
|
|
321
|
-
}
|
|
322
|
-
const normalized = normalizeInlineTarget(rawChatId) ?? rawChatId.trim();
|
|
323
|
-
const userMatch = normalized.match(/^user:([0-9]+)$/i);
|
|
324
|
-
if (userMatch?.[1]) {
|
|
325
|
-
return {
|
|
326
|
-
target: `user:${userMatch[1]}`,
|
|
327
|
-
userId: BigInt(userMatch[1]),
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
if (!/^[0-9]+$/.test(normalized)) {
|
|
331
|
-
throw new Error(`inline action: invalid target "${rawChatId}"`);
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
target: normalized,
|
|
335
|
-
chatId: BigInt(normalized),
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function buildChatPeer(chatId) {
|
|
339
|
-
return {
|
|
340
|
-
type: {
|
|
341
|
-
oneofKind: "chat",
|
|
342
|
-
chat: { chatId },
|
|
343
|
-
},
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function mapMessage(message) {
|
|
347
|
-
const content = summarizeInlineMessageContent(message);
|
|
348
|
-
const reactions = (message.reactions?.reactions ?? []).map((reaction) => ({
|
|
349
|
-
emoji: reaction.emoji ?? "",
|
|
350
|
-
userId: String(reaction.userId),
|
|
351
|
-
messageId: String(reaction.messageId),
|
|
352
|
-
chatId: String(reaction.chatId),
|
|
353
|
-
date: Number(reaction.date) * 1000,
|
|
354
|
-
}));
|
|
355
|
-
return {
|
|
356
|
-
id: String(message.id),
|
|
357
|
-
fromId: String(message.fromId),
|
|
358
|
-
date: Number(message.date) * 1000,
|
|
359
|
-
text: content.text,
|
|
360
|
-
rawText: content.rawText,
|
|
361
|
-
attachmentText: content.attachmentText,
|
|
362
|
-
entityText: content.entityText,
|
|
363
|
-
out: Boolean(message.out),
|
|
364
|
-
replyToId: message.replyToMsgId != null ? String(message.replyToMsgId) : undefined,
|
|
365
|
-
attachmentUrls: content.attachmentUrls,
|
|
366
|
-
links: content.links,
|
|
367
|
-
media: content.media,
|
|
368
|
-
attachments: content.attachments,
|
|
369
|
-
entities: content.entities,
|
|
370
|
-
reactions,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
function mapChatEntry(params) {
|
|
374
|
-
const dialog = params.dialogByChatId.get(String(params.chat.id));
|
|
375
|
-
const peer = params.chat.peerId?.type;
|
|
376
|
-
let peerUser = null;
|
|
377
|
-
if (peer?.oneofKind === "user") {
|
|
378
|
-
peerUser = params.usersById.get(String(peer.user.userId)) ?? null;
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
id: String(params.chat.id),
|
|
382
|
-
title: params.chat.title,
|
|
383
|
-
spaceId: params.chat.spaceId != null ? String(params.chat.spaceId) : null,
|
|
384
|
-
isPublic: params.chat.isPublic ?? false,
|
|
385
|
-
createdBy: params.chat.createdBy != null ? String(params.chat.createdBy) : null,
|
|
386
|
-
date: params.chat.date != null ? Number(params.chat.date) * 1000 : null,
|
|
387
|
-
unreadCount: dialog?.unreadCount ?? 0,
|
|
388
|
-
archived: Boolean(dialog?.archived),
|
|
389
|
-
pinned: Boolean(dialog?.pinned),
|
|
390
|
-
peer: peer?.oneofKind === "user"
|
|
391
|
-
? {
|
|
392
|
-
kind: "user",
|
|
393
|
-
id: String(peer.user.userId),
|
|
394
|
-
username: peerUser?.username ?? null,
|
|
395
|
-
name: peerUser ? buildInlineUserDisplayName(peerUser) : null,
|
|
396
|
-
}
|
|
397
|
-
: peer?.oneofKind === "chat"
|
|
398
|
-
? { kind: "chat", id: String(peer.chat.chatId) }
|
|
399
|
-
: null,
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
async function loadMessageReactions(params) {
|
|
403
|
-
const target = await findMessageById({
|
|
404
|
-
client: params.client,
|
|
405
|
-
chatId: params.chatId,
|
|
406
|
-
messageId: params.messageId,
|
|
407
|
-
});
|
|
408
|
-
if (!target) {
|
|
409
|
-
return [];
|
|
410
|
-
}
|
|
411
|
-
const byEmoji = new Map();
|
|
412
|
-
for (const reaction of target.reactions?.reactions ?? []) {
|
|
413
|
-
const emoji = reaction.emoji ?? "";
|
|
414
|
-
if (!emoji)
|
|
415
|
-
continue;
|
|
416
|
-
const existing = byEmoji.get(emoji);
|
|
417
|
-
if (existing) {
|
|
418
|
-
existing.count += 1;
|
|
419
|
-
existing.userIds.push(String(reaction.userId));
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
byEmoji.set(emoji, {
|
|
423
|
-
emoji,
|
|
424
|
-
count: 1,
|
|
425
|
-
userIds: [String(reaction.userId)],
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
return Array.from(byEmoji.values());
|
|
429
|
-
}
|
|
430
|
-
async function findMessageById(params) {
|
|
431
|
-
const directResult = GET_MESSAGES_METHOD == null
|
|
432
|
-
? null
|
|
433
|
-
: await params.client
|
|
434
|
-
.invokeRaw(GET_MESSAGES_METHOD, {
|
|
435
|
-
oneofKind: "getMessages",
|
|
436
|
-
getMessages: {
|
|
437
|
-
peerId: buildChatPeer(params.chatId),
|
|
438
|
-
messageIds: [params.messageId],
|
|
439
|
-
},
|
|
440
|
-
})
|
|
441
|
-
.catch(() => null);
|
|
442
|
-
if (directResult?.oneofKind === "getMessages") {
|
|
443
|
-
return (directResult.getMessages.messages ?? []).find((message) => message.id === params.messageId) ?? null;
|
|
444
|
-
}
|
|
445
|
-
const result = await params.client.invokeRaw(Method.GET_CHAT_HISTORY, {
|
|
446
|
-
oneofKind: "getChatHistory",
|
|
447
|
-
getChatHistory: {
|
|
448
|
-
peerId: buildChatPeer(params.chatId),
|
|
449
|
-
offsetId: params.messageId + 1n,
|
|
450
|
-
limit: 8,
|
|
451
|
-
},
|
|
452
|
-
});
|
|
453
|
-
if (result.oneofKind !== "getChatHistory") {
|
|
454
|
-
throw new Error(`inline action: expected getChatHistory result, got ${String(result.oneofKind)}`);
|
|
455
|
-
}
|
|
456
|
-
return (result.getChatHistory.messages ?? []).find((message) => message.id === params.messageId) ?? null;
|
|
457
|
-
}
|
|
458
|
-
async function withInlineClient(params) {
|
|
459
|
-
const account = resolveInlineAccount({ cfg: params.cfg, accountId: params.accountId ?? null });
|
|
460
|
-
if (!account.configured || !account.baseUrl) {
|
|
461
|
-
throw new Error(`Inline not configured for account "${account.accountId}" (missing token or baseUrl)`);
|
|
462
|
-
}
|
|
463
|
-
const token = await resolveInlineToken(account);
|
|
464
|
-
const client = new InlineSdkClient({
|
|
465
|
-
baseUrl: account.baseUrl,
|
|
466
|
-
token,
|
|
467
|
-
});
|
|
468
|
-
await client.connect();
|
|
469
|
-
try {
|
|
470
|
-
return await params.fn(client);
|
|
471
|
-
}
|
|
472
|
-
finally {
|
|
473
|
-
await client.close().catch(() => { });
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
function toJsonSafe(value) {
|
|
477
|
-
if (typeof value === "bigint")
|
|
478
|
-
return value.toString();
|
|
479
|
-
if (Array.isArray(value))
|
|
480
|
-
return value.map((item) => toJsonSafe(item));
|
|
481
|
-
if (value && typeof value === "object") {
|
|
482
|
-
const out = {};
|
|
483
|
-
for (const [key, current] of Object.entries(value)) {
|
|
484
|
-
out[key] = toJsonSafe(current);
|
|
485
|
-
}
|
|
486
|
-
return out;
|
|
487
|
-
}
|
|
488
|
-
return value;
|
|
489
|
-
}
|
|
490
|
-
function buildDialogMap(dialogs) {
|
|
491
|
-
const map = new Map();
|
|
492
|
-
for (const dialog of dialogs) {
|
|
493
|
-
const chatId = dialog.chatId;
|
|
494
|
-
if (chatId != null) {
|
|
495
|
-
map.set(String(chatId), dialog);
|
|
496
|
-
continue;
|
|
497
|
-
}
|
|
498
|
-
const peer = dialog.peer?.type;
|
|
499
|
-
if (peer?.oneofKind === "chat") {
|
|
500
|
-
map.set(String(peer.chat.chatId), dialog);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return map;
|
|
504
|
-
}
|
|
505
|
-
function buildUserMap(users) {
|
|
506
|
-
const map = new Map();
|
|
507
|
-
for (const user of users) {
|
|
508
|
-
map.set(String(user.id), user);
|
|
509
|
-
}
|
|
510
|
-
return map;
|
|
511
|
-
}
|
|
512
|
-
async function resolveSpaceIdFromParams(params) {
|
|
513
|
-
const directSpaceId = parseOptionalInlineId(readFlexibleId(params.rawParams, "spaceId") ??
|
|
514
|
-
readFlexibleId(params.rawParams, "space") ??
|
|
515
|
-
readStringParam(params.rawParams, "spaceId"), "spaceId");
|
|
516
|
-
if (directSpaceId != null)
|
|
517
|
-
return directSpaceId;
|
|
518
|
-
const chatTarget = readFlexibleId(params.rawParams, "chatId") ??
|
|
519
|
-
readFlexibleId(params.rawParams, "channelId") ??
|
|
520
|
-
readFlexibleId(params.rawParams, "to") ??
|
|
521
|
-
readStringParam(params.rawParams, "to");
|
|
522
|
-
if (!chatTarget) {
|
|
523
|
-
throw new Error(`inline action: ${params.action} requires spaceId (or a chat target in a space)`);
|
|
524
|
-
}
|
|
525
|
-
const chatId = BigInt(normalizeChatId(chatTarget));
|
|
526
|
-
const chatResult = await params.client.invokeRaw(Method.GET_CHAT, {
|
|
527
|
-
oneofKind: "getChat",
|
|
528
|
-
getChat: { peerId: buildChatPeer(chatId) },
|
|
529
|
-
});
|
|
530
|
-
if (chatResult.oneofKind !== "getChat") {
|
|
531
|
-
throw new Error(`inline action: expected getChat result, got ${String(chatResult.oneofKind)}`);
|
|
532
|
-
}
|
|
533
|
-
const inferredSpaceId = chatResult.getChat.chat?.spaceId ?? chatResult.getChat.dialog?.spaceId;
|
|
534
|
-
if (inferredSpaceId == null) {
|
|
535
|
-
throw new Error(`inline action: ${params.action} requires a spaceId or a chat that belongs to a space`);
|
|
536
|
-
}
|
|
537
|
-
return inferredSpaceId;
|
|
538
|
-
}
|
|
539
|
-
function listAllActions() {
|
|
540
|
-
const out = new Set();
|
|
541
|
-
for (const group of ACTION_GROUPS) {
|
|
542
|
-
for (const action of group.actions) {
|
|
543
|
-
out.add(action);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return Array.from(out);
|
|
547
|
-
}
|
|
548
|
-
function isActionEnabled(params) {
|
|
549
|
-
const key = ACTION_TO_GATE_KEY.get(params.action);
|
|
550
|
-
if (!key)
|
|
551
|
-
return false;
|
|
552
|
-
const group = ACTION_GROUPS.find((item) => item.key === key);
|
|
553
|
-
if (!group)
|
|
554
|
-
return false;
|
|
555
|
-
const account = resolveInlineAccount({
|
|
556
|
-
cfg: params.cfg,
|
|
557
|
-
accountId: params.accountId ?? null,
|
|
558
|
-
});
|
|
559
|
-
const gate = createActionGate((account.config.actions ?? {}));
|
|
560
|
-
return gate(key, group.defaultEnabled);
|
|
561
|
-
}
|
|
562
|
-
export const inlineMessageActions = {
|
|
563
|
-
listActions: ({ cfg }) => {
|
|
564
|
-
const account = resolveInlineAccount({ cfg, accountId: null });
|
|
565
|
-
if (!account.enabled || !account.configured)
|
|
566
|
-
return [];
|
|
567
|
-
const gate = createActionGate((account.config.actions ?? {}));
|
|
568
|
-
const actions = new Set();
|
|
569
|
-
for (const group of ACTION_GROUPS) {
|
|
570
|
-
if (!gate(group.key, group.defaultEnabled))
|
|
571
|
-
continue;
|
|
572
|
-
for (const action of group.actions) {
|
|
573
|
-
actions.add(action);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return Array.from(actions);
|
|
577
|
-
},
|
|
578
|
-
supportsAction: ({ action }) => SUPPORTED_ACTIONS.includes(action),
|
|
579
|
-
extractToolSend: ({ args }) => {
|
|
580
|
-
const action = typeof args.action === "string" ? args.action.trim() : "";
|
|
581
|
-
if (action !== "sendMessage")
|
|
582
|
-
return null;
|
|
583
|
-
const to = typeof args.to === "string" ? args.to.trim() : "";
|
|
584
|
-
if (!to)
|
|
585
|
-
return null;
|
|
586
|
-
const normalized = normalizeInlineTarget(to) ?? to;
|
|
587
|
-
if (!/^(user:)?[0-9]+$/i.test(normalized))
|
|
588
|
-
return null;
|
|
589
|
-
return { to: normalized };
|
|
590
|
-
},
|
|
591
|
-
handleAction: async ({ action, params, cfg, accountId }) => {
|
|
592
|
-
if (!SUPPORTED_ACTIONS.includes(action)) {
|
|
593
|
-
throw new Error(`Action ${action} is not supported for provider inline.`);
|
|
594
|
-
}
|
|
595
|
-
if (!isActionEnabled({ cfg, accountId: accountId ?? null, action })) {
|
|
596
|
-
throw new Error(`inline action: ${action} is disabled by channels.inline.actions`);
|
|
597
|
-
}
|
|
598
|
-
const normalizedAction = action;
|
|
599
|
-
if (normalizedAction === "send" || normalizedAction === "sendAttachment") {
|
|
600
|
-
const parseMarkdown = resolveInlineAccount({ cfg, accountId: accountId ?? null }).config.parseMarkdown ?? true;
|
|
601
|
-
return await withInlineClient({
|
|
602
|
-
cfg,
|
|
603
|
-
accountId,
|
|
604
|
-
fn: async (client) => {
|
|
605
|
-
const target = resolveMessageSendTargetFromParams(params);
|
|
606
|
-
const sendTarget = target.chatId != null ? { chatId: target.chatId } : target.userId != null ? { userId: target.userId } : null;
|
|
607
|
-
if (!sendTarget) {
|
|
608
|
-
throw new Error("inline action: missing message target");
|
|
609
|
-
}
|
|
610
|
-
const mediaSources = resolveInlineOutboundMediaInputs(params);
|
|
611
|
-
const text = readStringParam(params, "message") ??
|
|
612
|
-
readStringParam(params, "text") ??
|
|
613
|
-
readStringParam(params, "caption") ??
|
|
614
|
-
"";
|
|
615
|
-
const replyToMsgId = parseOptionalInlineId(readFlexibleId(params, "messageId") ??
|
|
616
|
-
readFlexibleId(params, "replyTo") ??
|
|
617
|
-
readFlexibleId(params, "replyToId") ??
|
|
618
|
-
readStringParam(params, "messageId") ??
|
|
619
|
-
readStringParam(params, "replyTo") ??
|
|
620
|
-
readStringParam(params, "replyToId"), "messageId");
|
|
621
|
-
if (normalizedAction === "sendAttachment" && mediaSources.length === 0) {
|
|
622
|
-
throw new Error("inline action: sendAttachment requires media/file input");
|
|
623
|
-
}
|
|
624
|
-
if (mediaSources.length === 0) {
|
|
625
|
-
const message = readStringParam(params, "message") ??
|
|
626
|
-
readStringParam(params, "text", { required: true, allowEmpty: true });
|
|
627
|
-
const sent = await client.sendMessage({
|
|
628
|
-
...sendTarget,
|
|
629
|
-
text: message,
|
|
630
|
-
...(replyToMsgId != null ? { replyToMsgId } : {}),
|
|
631
|
-
parseMarkdown,
|
|
632
|
-
});
|
|
633
|
-
return jsonResult({
|
|
634
|
-
ok: true,
|
|
635
|
-
target: target.target,
|
|
636
|
-
messageId: sent.messageId != null ? String(sent.messageId) : null,
|
|
637
|
-
replyToId: replyToMsgId != null ? String(replyToMsgId) : null,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
let lastSent = null;
|
|
641
|
-
for (let index = 0; index < mediaSources.length; index += 1) {
|
|
642
|
-
const mediaUrl = mediaSources[index];
|
|
643
|
-
if (!mediaUrl)
|
|
644
|
-
continue;
|
|
645
|
-
const media = await uploadInlineMediaFromUrl({
|
|
646
|
-
client,
|
|
647
|
-
cfg,
|
|
648
|
-
accountId: accountId ?? null,
|
|
649
|
-
mediaUrl,
|
|
650
|
-
});
|
|
651
|
-
lastSent = await client.sendMessage({
|
|
652
|
-
...sendTarget,
|
|
653
|
-
...(index === 0 && text ? { text } : {}),
|
|
654
|
-
media,
|
|
655
|
-
...(index === 0 && replyToMsgId != null ? { replyToMsgId } : {}),
|
|
656
|
-
...(index === 0 && text ? { parseMarkdown } : {}),
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
return jsonResult({
|
|
660
|
-
ok: true,
|
|
661
|
-
target: target.target,
|
|
662
|
-
messageId: lastSent?.messageId != null ? String(lastSent.messageId) : null,
|
|
663
|
-
...(mediaSources.length === 1 ? { mediaUrl: mediaSources[0] } : { mediaUrls: mediaSources }),
|
|
664
|
-
replyToId: replyToMsgId != null ? String(replyToMsgId) : null,
|
|
665
|
-
});
|
|
666
|
-
},
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
if (normalizedAction === "reply" || normalizedAction === "thread-reply") {
|
|
670
|
-
const parseMarkdown = resolveInlineAccount({ cfg, accountId: accountId ?? null }).config.parseMarkdown ?? true;
|
|
671
|
-
return await withInlineClient({
|
|
672
|
-
cfg,
|
|
673
|
-
accountId,
|
|
674
|
-
fn: async (client) => {
|
|
675
|
-
const replyParams = normalizedAction === "thread-reply" &&
|
|
676
|
-
params.threadId != null &&
|
|
677
|
-
params.to == null &&
|
|
678
|
-
params.chatId == null &&
|
|
679
|
-
params.channelId == null
|
|
680
|
-
? { ...params, to: params.threadId }
|
|
681
|
-
: params;
|
|
682
|
-
const chatId = resolveChatIdFromParams(replyParams);
|
|
683
|
-
const replyToMsgId = parseInlineId(readFlexibleId(replyParams, "messageId") ??
|
|
684
|
-
readFlexibleId(replyParams, "replyTo") ??
|
|
685
|
-
readFlexibleId(replyParams, "replyToId") ??
|
|
686
|
-
readStringParam(replyParams, "messageId") ??
|
|
687
|
-
readStringParam(replyParams, "replyTo") ??
|
|
688
|
-
readStringParam(replyParams, "replyToId", { required: true }), "messageId");
|
|
689
|
-
const text = readStringParam(replyParams, "message") ??
|
|
690
|
-
readStringParam(replyParams, "text", { required: true, allowEmpty: true });
|
|
691
|
-
const sent = await client.sendMessage({
|
|
692
|
-
chatId,
|
|
693
|
-
text,
|
|
694
|
-
replyToMsgId,
|
|
695
|
-
parseMarkdown,
|
|
696
|
-
});
|
|
697
|
-
return jsonResult({
|
|
698
|
-
ok: true,
|
|
699
|
-
chatId: String(chatId),
|
|
700
|
-
messageId: sent.messageId != null ? String(sent.messageId) : null,
|
|
701
|
-
replyToId: String(replyToMsgId),
|
|
702
|
-
});
|
|
703
|
-
},
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
if (normalizedAction === "react") {
|
|
707
|
-
return await withInlineClient({
|
|
708
|
-
cfg,
|
|
709
|
-
accountId,
|
|
710
|
-
fn: async (client) => {
|
|
711
|
-
const chatId = resolveChatIdFromParams(params);
|
|
712
|
-
const messageId = parseInlineId(readFlexibleId(params, "messageId") ??
|
|
713
|
-
readStringParam(params, "messageId", { required: true }), "messageId");
|
|
714
|
-
const { emoji, remove, isEmpty } = readReactionParams(params, {
|
|
715
|
-
removeErrorMessage: "Emoji is required to remove an Inline reaction.",
|
|
716
|
-
});
|
|
717
|
-
if (isEmpty) {
|
|
718
|
-
throw new Error("inline action: react requires emoji");
|
|
719
|
-
}
|
|
720
|
-
if (remove) {
|
|
721
|
-
const result = await client.invokeRaw(Method.DELETE_REACTION, {
|
|
722
|
-
oneofKind: "deleteReaction",
|
|
723
|
-
deleteReaction: {
|
|
724
|
-
emoji,
|
|
725
|
-
peerId: buildChatPeer(chatId),
|
|
726
|
-
messageId,
|
|
727
|
-
},
|
|
728
|
-
});
|
|
729
|
-
if (result.oneofKind !== "deleteReaction") {
|
|
730
|
-
throw new Error(`inline action: expected deleteReaction result, got ${String(result.oneofKind)}`);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
const result = await client.invokeRaw(Method.ADD_REACTION, {
|
|
735
|
-
oneofKind: "addReaction",
|
|
736
|
-
addReaction: {
|
|
737
|
-
emoji,
|
|
738
|
-
messageId,
|
|
739
|
-
peerId: buildChatPeer(chatId),
|
|
740
|
-
},
|
|
741
|
-
});
|
|
742
|
-
if (result.oneofKind !== "addReaction") {
|
|
743
|
-
throw new Error(`inline action: expected addReaction result, got ${String(result.oneofKind)}`);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
return jsonResult({
|
|
747
|
-
ok: true,
|
|
748
|
-
chatId: String(chatId),
|
|
749
|
-
messageId: String(messageId),
|
|
750
|
-
emoji,
|
|
751
|
-
remove,
|
|
752
|
-
});
|
|
753
|
-
},
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
if (normalizedAction === "reactions") {
|
|
757
|
-
return await withInlineClient({
|
|
758
|
-
cfg,
|
|
759
|
-
accountId,
|
|
760
|
-
fn: async (client) => {
|
|
761
|
-
const chatId = resolveChatIdFromParams(params);
|
|
762
|
-
const messageId = parseInlineId(readFlexibleId(params, "messageId") ??
|
|
763
|
-
readStringParam(params, "messageId", { required: true }), "messageId");
|
|
764
|
-
const reactions = await loadMessageReactions({
|
|
765
|
-
client,
|
|
766
|
-
chatId,
|
|
767
|
-
messageId,
|
|
768
|
-
});
|
|
769
|
-
return jsonResult({
|
|
770
|
-
ok: true,
|
|
771
|
-
chatId: String(chatId),
|
|
772
|
-
messageId: String(messageId),
|
|
773
|
-
reactions,
|
|
774
|
-
});
|
|
775
|
-
},
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
if (normalizedAction === "read") {
|
|
779
|
-
return await withInlineClient({
|
|
780
|
-
cfg,
|
|
781
|
-
accountId,
|
|
782
|
-
fn: async (client) => {
|
|
783
|
-
const chatId = resolveChatIdFromParams(params);
|
|
784
|
-
const limit = Math.max(1, Math.min(100, readNumberParam(params, "limit", { integer: true }) ?? 20));
|
|
785
|
-
const offsetId = parseOptionalInlineId(readFlexibleId(params, "offsetId") ?? readFlexibleId(params, "before"), "offsetId");
|
|
786
|
-
const result = await client.invokeRaw(Method.GET_CHAT_HISTORY, {
|
|
787
|
-
oneofKind: "getChatHistory",
|
|
788
|
-
getChatHistory: {
|
|
789
|
-
peerId: buildChatPeer(chatId),
|
|
790
|
-
...(offsetId != null ? { offsetId } : {}),
|
|
791
|
-
limit,
|
|
792
|
-
},
|
|
793
|
-
});
|
|
794
|
-
if (result.oneofKind !== "getChatHistory") {
|
|
795
|
-
throw new Error(`inline action: expected getChatHistory result, got ${String(result.oneofKind)}`);
|
|
796
|
-
}
|
|
797
|
-
return jsonResult(toJsonSafe({
|
|
798
|
-
ok: true,
|
|
799
|
-
chatId: String(chatId),
|
|
800
|
-
messages: (result.getChatHistory.messages ?? []).map((message) => mapMessage(message)),
|
|
801
|
-
}));
|
|
802
|
-
},
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
if (normalizedAction === "search") {
|
|
806
|
-
return await withInlineClient({
|
|
807
|
-
cfg,
|
|
808
|
-
accountId,
|
|
809
|
-
fn: async (client) => {
|
|
810
|
-
const chatId = resolveChatIdFromParams(params);
|
|
811
|
-
const query = readStringParam(params, "query") ??
|
|
812
|
-
readStringParam(params, "q") ??
|
|
813
|
-
readStringParam(params, "message", { required: true });
|
|
814
|
-
const limit = Math.max(1, Math.min(100, readNumberParam(params, "limit", { integer: true }) ?? 20));
|
|
815
|
-
const offsetId = parseOptionalInlineId(readFlexibleId(params, "offsetId"), "offsetId");
|
|
816
|
-
const result = await client.invokeRaw(Method.SEARCH_MESSAGES, {
|
|
817
|
-
oneofKind: "searchMessages",
|
|
818
|
-
searchMessages: {
|
|
819
|
-
peerId: buildChatPeer(chatId),
|
|
820
|
-
queries: [query],
|
|
821
|
-
limit,
|
|
822
|
-
...(offsetId != null ? { offsetId } : {}),
|
|
823
|
-
},
|
|
824
|
-
});
|
|
825
|
-
if (result.oneofKind !== "searchMessages") {
|
|
826
|
-
throw new Error(`inline action: expected searchMessages result, got ${String(result.oneofKind)}`);
|
|
827
|
-
}
|
|
828
|
-
return jsonResult(toJsonSafe({
|
|
829
|
-
ok: true,
|
|
830
|
-
chatId: String(chatId),
|
|
831
|
-
query,
|
|
832
|
-
messages: (result.searchMessages.messages ?? []).map((message) => mapMessage(message)),
|
|
833
|
-
}));
|
|
834
|
-
},
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
if (normalizedAction === "edit") {
|
|
838
|
-
const parseMarkdown = resolveInlineAccount({ cfg, accountId: accountId ?? null }).config.parseMarkdown ?? true;
|
|
839
|
-
return await withInlineClient({
|
|
840
|
-
cfg,
|
|
841
|
-
accountId,
|
|
842
|
-
fn: async (client) => {
|
|
843
|
-
const chatId = resolveChatIdFromParams(params);
|
|
844
|
-
const messageId = parseInlineId(readFlexibleId(params, "messageId") ??
|
|
845
|
-
readStringParam(params, "messageId", { required: true }), "messageId");
|
|
846
|
-
const text = readStringParam(params, "message", { required: true, allowEmpty: true });
|
|
847
|
-
const result = await client.invokeRaw(Method.EDIT_MESSAGE, {
|
|
848
|
-
oneofKind: "editMessage",
|
|
849
|
-
editMessage: {
|
|
850
|
-
messageId,
|
|
851
|
-
peerId: buildChatPeer(chatId),
|
|
852
|
-
text,
|
|
853
|
-
parseMarkdown,
|
|
854
|
-
},
|
|
855
|
-
});
|
|
856
|
-
if (result.oneofKind !== "editMessage") {
|
|
857
|
-
throw new Error(`inline action: expected editMessage result, got ${String(result.oneofKind)}`);
|
|
858
|
-
}
|
|
859
|
-
return jsonResult(toJsonSafe({ ok: true, chatId: String(chatId), messageId: String(messageId), text, parseMarkdown }));
|
|
860
|
-
},
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
if (normalizedAction === "channel-info") {
|
|
864
|
-
return await withInlineClient({
|
|
865
|
-
cfg,
|
|
866
|
-
accountId,
|
|
867
|
-
fn: async (client) => {
|
|
868
|
-
const chatId = resolveChatIdFromParams(params);
|
|
869
|
-
const result = await client.invokeRaw(Method.GET_CHAT, {
|
|
870
|
-
oneofKind: "getChat",
|
|
871
|
-
getChat: { peerId: buildChatPeer(chatId) },
|
|
872
|
-
});
|
|
873
|
-
if (result.oneofKind !== "getChat") {
|
|
874
|
-
throw new Error(`inline action: expected getChat result, got ${String(result.oneofKind)}`);
|
|
875
|
-
}
|
|
876
|
-
return jsonResult(toJsonSafe({
|
|
877
|
-
ok: true,
|
|
878
|
-
chatId: String(chatId),
|
|
879
|
-
chat: result.getChat.chat ?? null,
|
|
880
|
-
dialog: result.getChat.dialog ?? null,
|
|
881
|
-
pinnedMessageIds: (result.getChat.pinnedMessageIds ?? []).map((id) => String(id)),
|
|
882
|
-
}));
|
|
883
|
-
},
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
if (normalizedAction === "channel-edit" || normalizedAction === "renameGroup") {
|
|
887
|
-
return await withInlineClient({
|
|
888
|
-
cfg,
|
|
889
|
-
accountId,
|
|
890
|
-
fn: async (client) => {
|
|
891
|
-
const chatId = resolveChatIdFromParams(params);
|
|
892
|
-
const title = readStringParam(params, "title") ??
|
|
893
|
-
readStringParam(params, "name") ??
|
|
894
|
-
readStringParam(params, "threadName") ??
|
|
895
|
-
readStringParam(params, "message", { required: true });
|
|
896
|
-
const result = await client.invokeRaw(Method.UPDATE_CHAT_INFO, {
|
|
897
|
-
oneofKind: "updateChatInfo",
|
|
898
|
-
updateChatInfo: {
|
|
899
|
-
chatId,
|
|
900
|
-
title,
|
|
901
|
-
},
|
|
902
|
-
});
|
|
903
|
-
if (result.oneofKind !== "updateChatInfo") {
|
|
904
|
-
throw new Error(`inline action: expected updateChatInfo result, got ${String(result.oneofKind)}`);
|
|
905
|
-
}
|
|
906
|
-
return jsonResult(toJsonSafe({
|
|
907
|
-
ok: true,
|
|
908
|
-
chatId: String(chatId),
|
|
909
|
-
title,
|
|
910
|
-
chat: result.updateChatInfo.chat ?? null,
|
|
911
|
-
}));
|
|
912
|
-
},
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
if (normalizedAction === "channel-list" || normalizedAction === "thread-list") {
|
|
916
|
-
return await withInlineClient({
|
|
917
|
-
cfg,
|
|
918
|
-
accountId,
|
|
919
|
-
fn: async (client) => {
|
|
920
|
-
const query = readStringParam(params, "query") ??
|
|
921
|
-
readStringParam(params, "q") ??
|
|
922
|
-
undefined;
|
|
923
|
-
const limit = Math.max(1, Math.min(200, readNumberParam(params, "limit", { integer: true }) ?? 50));
|
|
924
|
-
const result = await client.invokeRaw(Method.GET_CHATS, {
|
|
925
|
-
oneofKind: "getChats",
|
|
926
|
-
getChats: {},
|
|
927
|
-
});
|
|
928
|
-
if (result.oneofKind !== "getChats") {
|
|
929
|
-
throw new Error(`inline action: expected getChats result, got ${String(result.oneofKind)}`);
|
|
930
|
-
}
|
|
931
|
-
const dialogByChatId = buildDialogMap(result.getChats.dialogs ?? []);
|
|
932
|
-
const usersById = buildUserMap(result.getChats.users ?? []);
|
|
933
|
-
const entries = (result.getChats.chats ?? []).map((chat) => mapChatEntry({ chat, dialogByChatId, usersById }));
|
|
934
|
-
const normalizedQuery = query?.trim().toLowerCase() ?? "";
|
|
935
|
-
const filtered = normalizedQuery
|
|
936
|
-
? entries.filter((entry) => {
|
|
937
|
-
const haystack = [
|
|
938
|
-
entry.id,
|
|
939
|
-
entry.title,
|
|
940
|
-
entry.peer?.kind === "user" ? entry.peer.username ?? "" : "",
|
|
941
|
-
entry.peer?.kind === "user" ? entry.peer.name ?? "" : "",
|
|
942
|
-
]
|
|
943
|
-
.join("\n")
|
|
944
|
-
.toLowerCase();
|
|
945
|
-
return haystack.includes(normalizedQuery);
|
|
946
|
-
})
|
|
947
|
-
: entries;
|
|
948
|
-
return jsonResult(toJsonSafe({
|
|
949
|
-
ok: true,
|
|
950
|
-
query: query ?? null,
|
|
951
|
-
count: filtered.length,
|
|
952
|
-
chats: filtered.slice(0, limit),
|
|
953
|
-
}));
|
|
954
|
-
},
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
if (normalizedAction === "channel-create" || normalizedAction === "thread-create") {
|
|
958
|
-
return await withInlineClient({
|
|
959
|
-
cfg,
|
|
960
|
-
accountId,
|
|
961
|
-
fn: async (client) => {
|
|
962
|
-
const title = readStringParam(params, "title") ??
|
|
963
|
-
readStringParam(params, "name") ??
|
|
964
|
-
readStringParam(params, "threadName") ??
|
|
965
|
-
readStringParam(params, "message", { required: true });
|
|
966
|
-
const description = readStringParam(params, "description");
|
|
967
|
-
const emoji = readStringParam(params, "emoji");
|
|
968
|
-
const spaceId = parseOptionalInlineId(readFlexibleId(params, "spaceId") ?? readFlexibleId(params, "space"), "spaceId");
|
|
969
|
-
const isPublic = readBooleanParam(params, "isPublic") ?? false;
|
|
970
|
-
const participantRefs = parseInlineListValuesFromParams(params, [
|
|
971
|
-
"participants",
|
|
972
|
-
"participantIds",
|
|
973
|
-
"participantId",
|
|
974
|
-
"participant",
|
|
975
|
-
"userIds",
|
|
976
|
-
"userId",
|
|
977
|
-
]);
|
|
978
|
-
const dedupedParticipants = await resolveInlineUserIdsFromParams({
|
|
979
|
-
client,
|
|
980
|
-
values: participantRefs,
|
|
981
|
-
label: "participant",
|
|
982
|
-
});
|
|
983
|
-
const result = await client.invokeRaw(Method.CREATE_CHAT, {
|
|
984
|
-
oneofKind: "createChat",
|
|
985
|
-
createChat: {
|
|
986
|
-
title,
|
|
987
|
-
...(spaceId != null ? { spaceId } : {}),
|
|
988
|
-
...(description ? { description } : {}),
|
|
989
|
-
...(emoji ? { emoji } : {}),
|
|
990
|
-
isPublic,
|
|
991
|
-
participants: isPublic ? [] : dedupedParticipants.map((userId) => ({ userId })),
|
|
992
|
-
},
|
|
993
|
-
});
|
|
994
|
-
if (result.oneofKind !== "createChat") {
|
|
995
|
-
throw new Error(`inline action: expected createChat result, got ${String(result.oneofKind)}`);
|
|
996
|
-
}
|
|
997
|
-
return jsonResult(toJsonSafe({
|
|
998
|
-
ok: true,
|
|
999
|
-
title,
|
|
1000
|
-
spaceId: spaceId != null ? String(spaceId) : null,
|
|
1001
|
-
isPublic,
|
|
1002
|
-
participants: dedupedParticipants.map((id) => String(id)),
|
|
1003
|
-
chat: result.createChat.chat ?? null,
|
|
1004
|
-
dialog: result.createChat.dialog ?? null,
|
|
1005
|
-
}));
|
|
1006
|
-
},
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
if (normalizedAction === "channel-delete") {
|
|
1010
|
-
return await withInlineClient({
|
|
1011
|
-
cfg,
|
|
1012
|
-
accountId,
|
|
1013
|
-
fn: async (client) => {
|
|
1014
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1015
|
-
const result = await client.invokeRaw(Method.DELETE_CHAT, {
|
|
1016
|
-
oneofKind: "deleteChat",
|
|
1017
|
-
deleteChat: {
|
|
1018
|
-
peerId: buildChatPeer(chatId),
|
|
1019
|
-
},
|
|
1020
|
-
});
|
|
1021
|
-
if (result.oneofKind !== "deleteChat") {
|
|
1022
|
-
throw new Error(`inline action: expected deleteChat result, got ${String(result.oneofKind)}`);
|
|
1023
|
-
}
|
|
1024
|
-
return jsonResult({
|
|
1025
|
-
ok: true,
|
|
1026
|
-
chatId: String(chatId),
|
|
1027
|
-
});
|
|
1028
|
-
},
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
if (normalizedAction === "channel-move") {
|
|
1032
|
-
return await withInlineClient({
|
|
1033
|
-
cfg,
|
|
1034
|
-
accountId,
|
|
1035
|
-
fn: async (client) => {
|
|
1036
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1037
|
-
const rawSpace = readStringParam(params, "spaceId") ?? readStringParam(params, "toSpaceId");
|
|
1038
|
-
const normalizedSpace = rawSpace?.trim().toLowerCase();
|
|
1039
|
-
const moveToHome = normalizedSpace === "" ||
|
|
1040
|
-
normalizedSpace === "home" ||
|
|
1041
|
-
normalizedSpace === "none" ||
|
|
1042
|
-
normalizedSpace === "null";
|
|
1043
|
-
const parsedSpace = moveToHome
|
|
1044
|
-
? undefined
|
|
1045
|
-
: parseOptionalInlineId(readFlexibleId(params, "spaceId") ?? readFlexibleId(params, "toSpaceId"), "spaceId");
|
|
1046
|
-
const result = await client.invokeRaw(Method.MOVE_THREAD, {
|
|
1047
|
-
oneofKind: "moveThread",
|
|
1048
|
-
moveThread: {
|
|
1049
|
-
chatId,
|
|
1050
|
-
...(parsedSpace != null ? { spaceId: parsedSpace } : {}),
|
|
1051
|
-
},
|
|
1052
|
-
});
|
|
1053
|
-
if (result.oneofKind !== "moveThread") {
|
|
1054
|
-
throw new Error(`inline action: expected moveThread result, got ${String(result.oneofKind)}`);
|
|
1055
|
-
}
|
|
1056
|
-
return jsonResult(toJsonSafe({
|
|
1057
|
-
ok: true,
|
|
1058
|
-
chatId: String(chatId),
|
|
1059
|
-
spaceId: parsedSpace != null ? String(parsedSpace) : null,
|
|
1060
|
-
chat: result.moveThread.chat ?? null,
|
|
1061
|
-
}));
|
|
1062
|
-
},
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
if (normalizedAction === "addParticipant") {
|
|
1066
|
-
return await withInlineClient({
|
|
1067
|
-
cfg,
|
|
1068
|
-
accountId,
|
|
1069
|
-
fn: async (client) => {
|
|
1070
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1071
|
-
const participantRefs = parseInlineListValuesFromParams(params, [
|
|
1072
|
-
"userId",
|
|
1073
|
-
"participant",
|
|
1074
|
-
"participantId",
|
|
1075
|
-
"memberId",
|
|
1076
|
-
]);
|
|
1077
|
-
if (participantRefs.length === 0) {
|
|
1078
|
-
readStringParam(params, "userId", { required: true });
|
|
1079
|
-
}
|
|
1080
|
-
const participantIds = await resolveInlineUserIdsFromParams({
|
|
1081
|
-
client,
|
|
1082
|
-
values: participantRefs,
|
|
1083
|
-
label: "user",
|
|
1084
|
-
});
|
|
1085
|
-
if (participantIds.length === 0) {
|
|
1086
|
-
throw new Error("inline action: missing user");
|
|
1087
|
-
}
|
|
1088
|
-
if (participantIds.length > 1) {
|
|
1089
|
-
throw new Error("inline action: addParticipant accepts exactly one user");
|
|
1090
|
-
}
|
|
1091
|
-
const userId = participantIds[0];
|
|
1092
|
-
if (!userId) {
|
|
1093
|
-
throw new Error("inline action: missing user");
|
|
1094
|
-
}
|
|
1095
|
-
const result = await client.invokeRaw(Method.ADD_CHAT_PARTICIPANT, {
|
|
1096
|
-
oneofKind: "addChatParticipant",
|
|
1097
|
-
addChatParticipant: {
|
|
1098
|
-
chatId,
|
|
1099
|
-
userId,
|
|
1100
|
-
},
|
|
1101
|
-
});
|
|
1102
|
-
if (result.oneofKind !== "addChatParticipant") {
|
|
1103
|
-
throw new Error(`inline action: expected addChatParticipant result, got ${String(result.oneofKind)}`);
|
|
1104
|
-
}
|
|
1105
|
-
return jsonResult(toJsonSafe({
|
|
1106
|
-
ok: true,
|
|
1107
|
-
chatId: String(chatId),
|
|
1108
|
-
userId: String(userId),
|
|
1109
|
-
participant: result.addChatParticipant.participant ?? null,
|
|
1110
|
-
}));
|
|
1111
|
-
},
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
if (normalizedAction === "removeParticipant" || normalizedAction === "kick") {
|
|
1115
|
-
return await withInlineClient({
|
|
1116
|
-
cfg,
|
|
1117
|
-
accountId,
|
|
1118
|
-
fn: async (client) => {
|
|
1119
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1120
|
-
const participantRefs = parseInlineListValuesFromParams(params, [
|
|
1121
|
-
"userId",
|
|
1122
|
-
"participant",
|
|
1123
|
-
"participantId",
|
|
1124
|
-
"memberId",
|
|
1125
|
-
]);
|
|
1126
|
-
if (participantRefs.length === 0) {
|
|
1127
|
-
readStringParam(params, "userId", { required: true });
|
|
1128
|
-
}
|
|
1129
|
-
const participantIds = await resolveInlineUserIdsFromParams({
|
|
1130
|
-
client,
|
|
1131
|
-
values: participantRefs,
|
|
1132
|
-
label: "user",
|
|
1133
|
-
});
|
|
1134
|
-
if (participantIds.length === 0) {
|
|
1135
|
-
throw new Error("inline action: missing user");
|
|
1136
|
-
}
|
|
1137
|
-
if (participantIds.length > 1) {
|
|
1138
|
-
throw new Error("inline action: removeParticipant accepts exactly one user");
|
|
1139
|
-
}
|
|
1140
|
-
const userId = participantIds[0];
|
|
1141
|
-
if (!userId) {
|
|
1142
|
-
throw new Error("inline action: missing user");
|
|
1143
|
-
}
|
|
1144
|
-
const result = await client.invokeRaw(Method.REMOVE_CHAT_PARTICIPANT, {
|
|
1145
|
-
oneofKind: "removeChatParticipant",
|
|
1146
|
-
removeChatParticipant: {
|
|
1147
|
-
chatId,
|
|
1148
|
-
userId,
|
|
1149
|
-
},
|
|
1150
|
-
});
|
|
1151
|
-
if (result.oneofKind !== "removeChatParticipant") {
|
|
1152
|
-
throw new Error(`inline action: expected removeChatParticipant result, got ${String(result.oneofKind)}`);
|
|
1153
|
-
}
|
|
1154
|
-
return jsonResult({
|
|
1155
|
-
ok: true,
|
|
1156
|
-
chatId: String(chatId),
|
|
1157
|
-
userId: String(userId),
|
|
1158
|
-
});
|
|
1159
|
-
},
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
if (normalizedAction === "leaveGroup") {
|
|
1163
|
-
return await withInlineClient({
|
|
1164
|
-
cfg,
|
|
1165
|
-
accountId,
|
|
1166
|
-
fn: async (client) => {
|
|
1167
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1168
|
-
const me = await client.getMe();
|
|
1169
|
-
const userId = me.userId;
|
|
1170
|
-
const result = await client.invokeRaw(Method.REMOVE_CHAT_PARTICIPANT, {
|
|
1171
|
-
oneofKind: "removeChatParticipant",
|
|
1172
|
-
removeChatParticipant: {
|
|
1173
|
-
chatId,
|
|
1174
|
-
userId,
|
|
1175
|
-
},
|
|
1176
|
-
});
|
|
1177
|
-
if (result.oneofKind !== "removeChatParticipant") {
|
|
1178
|
-
throw new Error(`inline action: expected removeChatParticipant result, got ${String(result.oneofKind)}`);
|
|
1179
|
-
}
|
|
1180
|
-
return jsonResult({
|
|
1181
|
-
ok: true,
|
|
1182
|
-
chatId: String(chatId),
|
|
1183
|
-
userId: String(userId),
|
|
1184
|
-
left: true,
|
|
1185
|
-
});
|
|
1186
|
-
},
|
|
1187
|
-
});
|
|
1188
|
-
}
|
|
1189
|
-
if (normalizedAction === "member-info") {
|
|
1190
|
-
return await withInlineClient({
|
|
1191
|
-
cfg,
|
|
1192
|
-
accountId,
|
|
1193
|
-
fn: async (client) => {
|
|
1194
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1195
|
-
const userId = parseInlineId(readFlexibleId(params, "userId") ??
|
|
1196
|
-
readStringParam(params, "userId", { required: true }), "userId");
|
|
1197
|
-
const result = await client.invokeRaw(Method.GET_CHAT_PARTICIPANTS, {
|
|
1198
|
-
oneofKind: "getChatParticipants",
|
|
1199
|
-
getChatParticipants: { chatId },
|
|
1200
|
-
});
|
|
1201
|
-
if (result.oneofKind !== "getChatParticipants") {
|
|
1202
|
-
throw new Error(`inline action: expected getChatParticipants result, got ${String(result.oneofKind)}`);
|
|
1203
|
-
}
|
|
1204
|
-
const user = (result.getChatParticipants.users ?? []).find((candidate) => candidate.id === userId) ?? null;
|
|
1205
|
-
const participant = (result.getChatParticipants.participants ?? []).find((candidate) => candidate.userId === userId) ?? null;
|
|
1206
|
-
return jsonResult(toJsonSafe({
|
|
1207
|
-
ok: true,
|
|
1208
|
-
chatId: String(chatId),
|
|
1209
|
-
userId: String(userId),
|
|
1210
|
-
user,
|
|
1211
|
-
participant,
|
|
1212
|
-
}));
|
|
1213
|
-
},
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
if (normalizedAction === "delete" || normalizedAction === "unsend") {
|
|
1217
|
-
return await withInlineClient({
|
|
1218
|
-
cfg,
|
|
1219
|
-
accountId,
|
|
1220
|
-
fn: async (client) => {
|
|
1221
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1222
|
-
const messageIds = [
|
|
1223
|
-
...parseInlineIdListFromParams(params, "messageIds"),
|
|
1224
|
-
...parseInlineIdListFromParams(params, "messages"),
|
|
1225
|
-
...parseInlineIdListFromParams(params, "ids"),
|
|
1226
|
-
];
|
|
1227
|
-
if (messageIds.length === 0) {
|
|
1228
|
-
messageIds.push(parseInlineId(readFlexibleId(params, "messageId") ??
|
|
1229
|
-
readStringParam(params, "messageId", { required: true }), "messageId"));
|
|
1230
|
-
}
|
|
1231
|
-
const deduped = Array.from(new Set(messageIds.map((id) => id.toString()))).map((id) => BigInt(id));
|
|
1232
|
-
const result = await client.invokeRaw(Method.DELETE_MESSAGES, {
|
|
1233
|
-
oneofKind: "deleteMessages",
|
|
1234
|
-
deleteMessages: {
|
|
1235
|
-
peerId: buildChatPeer(chatId),
|
|
1236
|
-
messageIds: deduped,
|
|
1237
|
-
},
|
|
1238
|
-
});
|
|
1239
|
-
if (result.oneofKind !== "deleteMessages") {
|
|
1240
|
-
throw new Error(`inline action: expected deleteMessages result, got ${String(result.oneofKind)}`);
|
|
1241
|
-
}
|
|
1242
|
-
return jsonResult({
|
|
1243
|
-
ok: true,
|
|
1244
|
-
chatId: String(chatId),
|
|
1245
|
-
messageIds: deduped.map((id) => String(id)),
|
|
1246
|
-
});
|
|
1247
|
-
},
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1250
|
-
if (normalizedAction === "pin" || normalizedAction === "unpin") {
|
|
1251
|
-
return await withInlineClient({
|
|
1252
|
-
cfg,
|
|
1253
|
-
accountId,
|
|
1254
|
-
fn: async (client) => {
|
|
1255
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1256
|
-
const messageId = parseInlineId(readFlexibleId(params, "messageId") ??
|
|
1257
|
-
readStringParam(params, "messageId", { required: true }), "messageId");
|
|
1258
|
-
const unpin = normalizedAction === "unpin" || readBooleanParam(params, "unpin") === true;
|
|
1259
|
-
const result = await client.invokeRaw(Method.PIN_MESSAGE, {
|
|
1260
|
-
oneofKind: "pinMessage",
|
|
1261
|
-
pinMessage: {
|
|
1262
|
-
peerId: buildChatPeer(chatId),
|
|
1263
|
-
messageId,
|
|
1264
|
-
unpin,
|
|
1265
|
-
},
|
|
1266
|
-
});
|
|
1267
|
-
if (result.oneofKind !== "pinMessage") {
|
|
1268
|
-
throw new Error(`inline action: expected pinMessage result, got ${String(result.oneofKind)}`);
|
|
1269
|
-
}
|
|
1270
|
-
return jsonResult({
|
|
1271
|
-
ok: true,
|
|
1272
|
-
chatId: String(chatId),
|
|
1273
|
-
messageId: String(messageId),
|
|
1274
|
-
unpin,
|
|
1275
|
-
});
|
|
1276
|
-
},
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
if (normalizedAction === "list-pins") {
|
|
1280
|
-
return await withInlineClient({
|
|
1281
|
-
cfg,
|
|
1282
|
-
accountId,
|
|
1283
|
-
fn: async (client) => {
|
|
1284
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1285
|
-
const result = await client.invokeRaw(Method.GET_CHAT, {
|
|
1286
|
-
oneofKind: "getChat",
|
|
1287
|
-
getChat: { peerId: buildChatPeer(chatId) },
|
|
1288
|
-
});
|
|
1289
|
-
if (result.oneofKind !== "getChat") {
|
|
1290
|
-
throw new Error(`inline action: expected getChat result, got ${String(result.oneofKind)}`);
|
|
1291
|
-
}
|
|
1292
|
-
const pinnedMessageIds = (result.getChat.pinnedMessageIds ?? []).map((id) => String(id));
|
|
1293
|
-
return jsonResult({
|
|
1294
|
-
ok: true,
|
|
1295
|
-
chatId: String(chatId),
|
|
1296
|
-
pinnedMessageIds,
|
|
1297
|
-
});
|
|
1298
|
-
},
|
|
1299
|
-
});
|
|
1300
|
-
}
|
|
1301
|
-
if (normalizedAction === "permissions") {
|
|
1302
|
-
return await withInlineClient({
|
|
1303
|
-
cfg,
|
|
1304
|
-
accountId,
|
|
1305
|
-
fn: async (client) => {
|
|
1306
|
-
const chatId = resolveChatIdFromParams(params);
|
|
1307
|
-
const spaceId = await resolveSpaceIdFromParams({
|
|
1308
|
-
client,
|
|
1309
|
-
action: "permissions",
|
|
1310
|
-
rawParams: params,
|
|
1311
|
-
});
|
|
1312
|
-
const userIdRaw = readFlexibleId(params, "userId") ??
|
|
1313
|
-
readFlexibleId(params, "memberId") ??
|
|
1314
|
-
readStringParam(params, "userId");
|
|
1315
|
-
const userId = userIdRaw ? parseInlineId(userIdRaw, "userId") : undefined;
|
|
1316
|
-
const roleValue = readStringParam(params, "role")?.trim().toLowerCase();
|
|
1317
|
-
const canAccessPublicChats = readBooleanParam(params, "canAccessPublicChats");
|
|
1318
|
-
if (userId != null && roleValue) {
|
|
1319
|
-
const role = roleValue === "admin"
|
|
1320
|
-
? { role: { oneofKind: "admin", admin: {} } }
|
|
1321
|
-
: roleValue === "member"
|
|
1322
|
-
? {
|
|
1323
|
-
role: {
|
|
1324
|
-
oneofKind: "member",
|
|
1325
|
-
member: {
|
|
1326
|
-
canAccessPublicChats: canAccessPublicChats ?? true,
|
|
1327
|
-
},
|
|
1328
|
-
},
|
|
1329
|
-
}
|
|
1330
|
-
: null;
|
|
1331
|
-
if (!role) {
|
|
1332
|
-
throw new Error("inline action: role must be \"admin\" or \"member\"");
|
|
1333
|
-
}
|
|
1334
|
-
const updateResult = await client.invokeRaw(Method.UPDATE_MEMBER_ACCESS, {
|
|
1335
|
-
oneofKind: "updateMemberAccess",
|
|
1336
|
-
updateMemberAccess: {
|
|
1337
|
-
spaceId,
|
|
1338
|
-
userId,
|
|
1339
|
-
role,
|
|
1340
|
-
},
|
|
1341
|
-
});
|
|
1342
|
-
if (updateResult.oneofKind !== "updateMemberAccess") {
|
|
1343
|
-
throw new Error(`inline action: expected updateMemberAccess result, got ${String(updateResult.oneofKind)}`);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
const members = await getSpaceMembersWithUsers({
|
|
1347
|
-
client,
|
|
1348
|
-
spaceId,
|
|
1349
|
-
});
|
|
1350
|
-
const filteredMembers = userId != null ? members.filter((member) => member.userId === String(userId)) : members;
|
|
1351
|
-
return jsonResult(toJsonSafe({
|
|
1352
|
-
ok: true,
|
|
1353
|
-
chatId: String(chatId),
|
|
1354
|
-
spaceId: String(spaceId),
|
|
1355
|
-
members: filteredMembers,
|
|
1356
|
-
}));
|
|
1357
|
-
},
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
throw new Error(`Action ${action} is not supported for provider inline.`);
|
|
1361
|
-
},
|
|
1362
|
-
};
|
|
1363
|
-
export const inlineSupportedActions = listAllActions();
|
|
1364
|
-
//# sourceMappingURL=actions.js.map
|