@zhin.js/adapter-slack 4.0.0 → 4.1.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +207 -98
  3. package/{skills/slack → agent}/PERMITS.md +1 -1
  4. package/{skills/slack/SKILL.md → agent/skills/slack.md} +2 -0
  5. package/agent/tools/add_reaction.ts +26 -0
  6. package/agent/tools/archive_channel.ts +24 -0
  7. package/agent/tools/edit_message.ts +27 -0
  8. package/agent/tools/invite_to_channel.ts +26 -0
  9. package/agent/tools/pin_message.ts +26 -0
  10. package/agent/tools/remove_reaction.ts +26 -0
  11. package/agent/tools/set_purpose.ts +26 -0
  12. package/agent/tools/set_topic.ts +26 -0
  13. package/agent/tools/unarchive.ts +24 -0
  14. package/agent/tools/unpin_message.ts +26 -0
  15. package/agent/tools/user_info.ts +31 -0
  16. package/lib/agent/tools/add_reaction.js +21 -0
  17. package/lib/agent/tools/add_reaction.js.map +1 -0
  18. package/lib/agent/tools/archive_channel.js +21 -0
  19. package/lib/agent/tools/archive_channel.js.map +1 -0
  20. package/lib/agent/tools/edit_message.js +22 -0
  21. package/lib/agent/tools/edit_message.js.map +1 -0
  22. package/lib/agent/tools/invite_to_channel.js +22 -0
  23. package/lib/agent/tools/invite_to_channel.js.map +1 -0
  24. package/lib/agent/tools/pin_message.js +22 -0
  25. package/lib/agent/tools/pin_message.js.map +1 -0
  26. package/lib/agent/tools/remove_reaction.js +21 -0
  27. package/lib/agent/tools/remove_reaction.js.map +1 -0
  28. package/lib/agent/tools/set_purpose.js +22 -0
  29. package/lib/agent/tools/set_purpose.js.map +1 -0
  30. package/lib/agent/tools/set_topic.js +22 -0
  31. package/lib/agent/tools/set_topic.js.map +1 -0
  32. package/lib/agent/tools/unarchive.js +21 -0
  33. package/lib/agent/tools/unarchive.js.map +1 -0
  34. package/lib/agent/tools/unpin_message.js +22 -0
  35. package/lib/agent/tools/unpin_message.js.map +1 -0
  36. package/lib/agent/tools/user_info.js +28 -0
  37. package/lib/agent/tools/user_info.js.map +1 -0
  38. package/lib/{adapter.js → src/adapter.js} +23 -6
  39. package/lib/src/adapter.js.map +1 -0
  40. package/lib/src/endpoint.js +312 -0
  41. package/lib/src/endpoint.js.map +1 -0
  42. package/lib/src/event-dispatcher.js +233 -0
  43. package/lib/src/event-dispatcher.js.map +1 -0
  44. package/lib/src/index.js +51 -0
  45. package/lib/src/index.js.map +1 -0
  46. package/lib/src/markdown-to-mrkdwn.js +61 -0
  47. package/lib/src/markdown-to-mrkdwn.js.map +1 -0
  48. package/lib/src/mrkdwn-to-markdown.js +31 -0
  49. package/lib/src/mrkdwn-to-markdown.js.map +1 -0
  50. package/lib/{platform-permit.js → src/platform-permit.js} +5 -2
  51. package/lib/src/platform-permit.js.map +1 -0
  52. package/lib/src/segment-mapper.js +2 -0
  53. package/lib/src/segment-mapper.js.map +1 -0
  54. package/lib/src/signing.js +21 -0
  55. package/lib/src/signing.js.map +1 -0
  56. package/lib/src/slack-agent-deps.js +10 -0
  57. package/lib/src/slack-agent-deps.js.map +1 -0
  58. package/lib/src/slack-inbound-filter.js +47 -0
  59. package/lib/src/slack-inbound-filter.js.map +1 -0
  60. package/lib/src/slack-inbound.js +127 -0
  61. package/lib/src/slack-inbound.js.map +1 -0
  62. package/lib/src/slack-message-ref.js +18 -0
  63. package/lib/src/slack-message-ref.js.map +1 -0
  64. package/lib/src/slack-outbound.js +223 -0
  65. package/lib/src/slack-outbound.js.map +1 -0
  66. package/lib/src/slack-reaction.js +27 -0
  67. package/lib/src/slack-reaction.js.map +1 -0
  68. package/lib/src/slack-response-url.js +17 -0
  69. package/lib/src/slack-response-url.js.map +1 -0
  70. package/lib/src/slack-side-events.js +64 -0
  71. package/lib/src/slack-side-events.js.map +1 -0
  72. package/lib/src/transport-http.js +83 -0
  73. package/lib/src/transport-http.js.map +1 -0
  74. package/lib/src/transport-socket.js +68 -0
  75. package/lib/src/transport-socket.js.map +1 -0
  76. package/lib/src/types.js +5 -0
  77. package/lib/src/types.js.map +1 -0
  78. package/package.json +25 -7
  79. package/src/adapter.ts +32 -10
  80. package/src/endpoint.ts +209 -603
  81. package/src/event-dispatcher.ts +255 -0
  82. package/src/index.ts +31 -239
  83. package/src/markdown-to-mrkdwn.ts +58 -0
  84. package/src/mrkdwn-to-markdown.ts +29 -0
  85. package/src/platform-permit.ts +3 -4
  86. package/src/segment-mapper.ts +1 -0
  87. package/src/signing.ts +28 -0
  88. package/src/slack-agent-deps.ts +22 -0
  89. package/src/slack-inbound-filter.ts +60 -0
  90. package/src/slack-inbound.ts +140 -0
  91. package/src/slack-message-ref.ts +18 -0
  92. package/src/slack-outbound.ts +269 -0
  93. package/src/slack-reaction.ts +23 -0
  94. package/src/slack-response-url.ts +26 -0
  95. package/src/slack-side-events.ts +74 -0
  96. package/src/transport-http.ts +95 -0
  97. package/src/transport-socket.ts +77 -0
  98. package/src/types.ts +99 -4
  99. package/lib/adapter.d.ts +0 -18
  100. package/lib/adapter.d.ts.map +0 -1
  101. package/lib/adapter.js.map +0 -1
  102. package/lib/endpoint.d.ts +0 -108
  103. package/lib/endpoint.d.ts.map +0 -1
  104. package/lib/endpoint.js +0 -673
  105. package/lib/endpoint.js.map +0 -1
  106. package/lib/index.d.ts +0 -10
  107. package/lib/index.d.ts.map +0 -1
  108. package/lib/index.js +0 -252
  109. package/lib/index.js.map +0 -1
  110. package/lib/platform-permit.d.ts +0 -17
  111. package/lib/platform-permit.d.ts.map +0 -1
  112. package/lib/platform-permit.js.map +0 -1
  113. package/lib/types.d.ts +0 -17
  114. package/lib/types.d.ts.map +0 -1
  115. package/lib/types.js +0 -2
  116. package/lib/types.js.map +0 -1
package/lib/endpoint.js DELETED
@@ -1,673 +0,0 @@
1
- /**
2
- * Slack Endpoint 实现
3
- */
4
- import { App as SlackApp, LogLevel } from "@slack/bolt";
5
- import { WebClient } from "@slack/web-api";
6
- import { formatCompact, Message, segment, } from 'zhin.js';
7
- import { normalizeSlackSenderForPermit } from "./platform-permit.js";
8
- export class SlackEndpoint {
9
- adapter;
10
- $config;
11
- $connected;
12
- /** 延迟到 `$connect`,避免子类 mock `$connect` 时仍在构造函数里创建 Bolt/WebClient(会在后台触发 Slack API) */
13
- app;
14
- client;
15
- get logger() {
16
- return this.adapter.plugin.logger;
17
- }
18
- get $id() {
19
- return this.$config.name;
20
- }
21
- constructor(adapter, $config) {
22
- this.adapter = adapter;
23
- this.$config = $config;
24
- this.$connected = false;
25
- }
26
- #ensureSlackRuntime() {
27
- if (this.app && this.client)
28
- return;
29
- const $config = this.$config;
30
- if ($config.socketMode && $config.appToken) {
31
- this.app = new SlackApp({
32
- token: $config.token,
33
- signingSecret: $config.signingSecret,
34
- appToken: $config.appToken,
35
- socketMode: true,
36
- logLevel: $config.logLevel || LogLevel.INFO,
37
- });
38
- }
39
- else {
40
- this.app = new SlackApp({
41
- token: $config.token,
42
- signingSecret: $config.signingSecret,
43
- socketMode: false,
44
- logLevel: $config.logLevel || LogLevel.INFO,
45
- });
46
- }
47
- this.client = new WebClient($config.token);
48
- }
49
- async $connect() {
50
- this.#ensureSlackRuntime();
51
- try {
52
- // Set up message event handler
53
- this.app.message(async ({ message, say }) => {
54
- await this.handleSlackMessage(message);
55
- });
56
- // Set up app mention handler
57
- this.app.event("app_mention", async ({ event, say }) => {
58
- await this.handleSlackMessage(event);
59
- });
60
- // Start the app
61
- const port = this.$config.port || 3000;
62
- if (this.$config.socketMode) {
63
- await this.app.start();
64
- }
65
- else {
66
- await this.app.start(port);
67
- }
68
- this.$connected = true;
69
- // Get bot info
70
- const authTest = await this.client.auth.test();
71
- this.logger.info(formatCompact({ endpoint: this.$config.name, user: authTest.user }));
72
- if (!this.$config.socketMode) {
73
- this.logger.info(formatCompact({ op: "listen", port }));
74
- }
75
- }
76
- catch (error) {
77
- this.logger.error("Failed to connect Slack bot:", error);
78
- this.$connected = false;
79
- throw error;
80
- }
81
- }
82
- async $disconnect() {
83
- if (!this.app) {
84
- this.$connected = false;
85
- return;
86
- }
87
- try {
88
- await this.app.stop();
89
- this.$connected = false;
90
- this.logger.info(formatCompact({ op: "disconnect", endpoint: this.$config.name }));
91
- }
92
- catch (error) {
93
- this.logger.error("Error disconnecting Slack bot:", error);
94
- throw error;
95
- }
96
- }
97
- senderPermitCache = new Map();
98
- async enrichChannelSender(message, msg) {
99
- if (message.$channel.type !== "group" || !("user" in msg) || !msg.user)
100
- return;
101
- const channelId = msg.channel;
102
- const userId = msg.user;
103
- const key = `${channelId}:${userId}`;
104
- const now = Date.now();
105
- const cached = this.senderPermitCache.get(key);
106
- if (cached && now - cached.at < 60_000) {
107
- message.$sender.role = cached.role;
108
- message.$sender.permissions = cached.permissions;
109
- return;
110
- }
111
- try {
112
- const user = await this.getUserInfo(userId);
113
- let isChannelManager = false;
114
- try {
115
- const channel = await this.getChannelInfo(channelId);
116
- if (channel?.creator === userId)
117
- isChannelManager = true;
118
- }
119
- catch {
120
- // ignore
121
- }
122
- const normalized = normalizeSlackSenderForPermit({
123
- isWorkspaceOwner: user.is_owner === true,
124
- isWorkspaceAdmin: user.is_admin === true,
125
- isChannelManager,
126
- });
127
- const entry = {
128
- at: now,
129
- role: normalized.role,
130
- permissions: normalized.permissions ?? [],
131
- };
132
- this.senderPermitCache.set(key, entry);
133
- message.$sender.role = entry.role;
134
- message.$sender.permissions = entry.permissions;
135
- }
136
- catch {
137
- // 保守拒绝
138
- }
139
- }
140
- async handleSlackMessage(msg) {
141
- // Ignore bot messages and message changes
142
- if ("subtype" in msg && (msg.subtype === "bot_message" || msg.subtype === "message_changed")) {
143
- return;
144
- }
145
- const message = this.$formatMessage(msg);
146
- await this.enrichChannelSender(message, msg);
147
- this.adapter.emit("message.receive", message);
148
- this.logger.debug(`${this.$config.name} recv ${message.$channel.type}(${message.$channel.id}): ${segment.raw(message.$content)}`);
149
- }
150
- $formatMessage(msg) {
151
- // Determine channel type based on channel ID
152
- const channelType = "channel_type" in msg && msg.channel_type === "im" ? "private" : "group";
153
- const channelId = msg.channel;
154
- // Parse message content
155
- const content = this.parseMessageContent(msg);
156
- // Extract user info safely
157
- const userId = ("user" in msg ? msg.user : "") || "";
158
- const userName = ("username" in msg ? msg.username : null) || userId || "Unknown";
159
- const messageText = ("text" in msg ? msg.text : "") || "";
160
- const result = Message.from(msg, {
161
- $id: msg.ts,
162
- $adapter: "slack",
163
- $endpoint: this.$config.name,
164
- $sender: {
165
- id: userId,
166
- name: userName,
167
- },
168
- $channel: {
169
- id: channelId,
170
- type: channelType,
171
- },
172
- $content: content,
173
- $raw: messageText,
174
- $timestamp: parseFloat(msg.ts) * 1000,
175
- $recall: async () => {
176
- try {
177
- await this.client.chat.delete({
178
- channel: channelId,
179
- ts: result.$id,
180
- });
181
- }
182
- catch (error) {
183
- this.logger.error("Error recalling Slack message:", error);
184
- throw error;
185
- }
186
- },
187
- $reply: async (content, quote) => {
188
- if (!Array.isArray(content))
189
- content = [content];
190
- const sendOptions = {
191
- channel: channelId,
192
- };
193
- // Handle thread reply
194
- if (quote) {
195
- const threadTs = typeof quote === "boolean" ? result.$id : quote;
196
- sendOptions.thread_ts = threadTs;
197
- }
198
- return await this.adapter.sendMessage({
199
- context: "slack",
200
- endpoint: this.$config.name,
201
- id: channelId,
202
- type: "channel",
203
- content: content,
204
- });
205
- },
206
- });
207
- return result;
208
- }
209
- parseMessageContent(msg) {
210
- const segments = [];
211
- // Handle text
212
- if ("text" in msg && msg.text) {
213
- // Parse Slack formatting
214
- segments.push(...this.parseSlackText(msg.text));
215
- }
216
- // Handle files
217
- if ("files" in msg && msg.files) {
218
- for (const file of msg.files) {
219
- if (file.mimetype?.startsWith("image/")) {
220
- segments.push({
221
- type: "image",
222
- data: {
223
- id: file.id,
224
- name: file.name,
225
- url: file.url_private || file.permalink,
226
- size: file.size,
227
- mimetype: file.mimetype,
228
- },
229
- });
230
- }
231
- else if (file.mimetype?.startsWith("video/")) {
232
- segments.push({
233
- type: "video",
234
- data: {
235
- id: file.id,
236
- name: file.name,
237
- url: file.url_private || file.permalink,
238
- size: file.size,
239
- mimetype: file.mimetype,
240
- },
241
- });
242
- }
243
- else if (file.mimetype?.startsWith("audio/")) {
244
- segments.push({
245
- type: "audio",
246
- data: {
247
- id: file.id,
248
- name: file.name,
249
- url: file.url_private || file.permalink,
250
- size: file.size,
251
- mimetype: file.mimetype,
252
- },
253
- });
254
- }
255
- else {
256
- segments.push({
257
- type: "file",
258
- data: {
259
- id: file.id,
260
- name: file.name,
261
- url: file.url_private || file.permalink,
262
- size: file.size,
263
- mimetype: file.mimetype,
264
- },
265
- });
266
- }
267
- }
268
- }
269
- // Handle attachments
270
- if ("attachments" in msg && msg.attachments) {
271
- for (const attachment of msg.attachments) {
272
- if (attachment.image_url) {
273
- segments.push({
274
- type: "image",
275
- data: {
276
- url: attachment.image_url,
277
- title: attachment.title,
278
- text: attachment.text,
279
- },
280
- });
281
- }
282
- }
283
- }
284
- return segments.length > 0
285
- ? segments
286
- : [{ type: "text", data: { text: "" } }];
287
- }
288
- parseSlackText(text) {
289
- const segments = [];
290
- let lastIndex = 0;
291
- // Match user mentions <@U12345678>
292
- const userMentionRegex = /<@([UW][A-Z0-9]+)(?:\|([^>]+))?>/g;
293
- // Match channel mentions <#C12345678|general>
294
- const channelMentionRegex = /<#([C][A-Z0-9]+)(?:\|([^>]+))?>/g;
295
- // Match links <http://example.com|Example>
296
- const linkRegex = /<(https?:\/\/[^|>]+)(?:\|([^>]+))?>/g;
297
- const allMatches = [];
298
- // Collect all matches
299
- let match;
300
- while ((match = userMentionRegex.exec(text)) !== null) {
301
- allMatches.push({ match, type: "user" });
302
- }
303
- while ((match = channelMentionRegex.exec(text)) !== null) {
304
- allMatches.push({ match, type: "channel" });
305
- }
306
- while ((match = linkRegex.exec(text)) !== null) {
307
- allMatches.push({ match, type: "link" });
308
- }
309
- // Sort by position
310
- allMatches.sort((a, b) => a.match.index - b.match.index);
311
- // Process matches
312
- for (const { match, type } of allMatches) {
313
- const matchStart = match.index;
314
- const matchEnd = matchStart + match[0].length;
315
- // Add text before match
316
- if (matchStart > lastIndex) {
317
- const beforeText = text.slice(lastIndex, matchStart);
318
- if (beforeText.trim()) {
319
- segments.push({ type: "text", data: { text: beforeText } });
320
- }
321
- }
322
- // Add special segment
323
- switch (type) {
324
- case "user":
325
- segments.push({
326
- type: "at",
327
- data: {
328
- id: match[1],
329
- name: match[2] || match[1],
330
- text: match[0],
331
- },
332
- });
333
- break;
334
- case "channel":
335
- segments.push({
336
- type: "channel_mention",
337
- data: {
338
- id: match[1],
339
- name: match[2] || match[1],
340
- text: match[0],
341
- },
342
- });
343
- break;
344
- case "link":
345
- segments.push({
346
- type: "link",
347
- data: {
348
- url: match[1],
349
- text: match[2] || match[1],
350
- },
351
- });
352
- break;
353
- }
354
- lastIndex = matchEnd;
355
- }
356
- // Add remaining text
357
- if (lastIndex < text.length) {
358
- const remainingText = text.slice(lastIndex);
359
- if (remainingText.trim()) {
360
- segments.push({ type: "text", data: { text: remainingText } });
361
- }
362
- }
363
- return segments.length > 0
364
- ? segments
365
- : [{ type: "text", data: { text } }];
366
- }
367
- async $sendMessage(options) {
368
- try {
369
- const result = await this.sendContentToChannel(options.id, options.content);
370
- this.logger.debug(`${this.$config.name} send ${options.type}(${options.id}): ${segment.raw(options.content)}`);
371
- return result.ts || "";
372
- }
373
- catch (error) {
374
- this.logger.error("Failed to send Slack message:", error);
375
- throw error;
376
- }
377
- }
378
- async sendContentToChannel(channel, content, extraOptions = {}) {
379
- if (!Array.isArray(content))
380
- content = [content];
381
- let textContent = "";
382
- const attachments = [];
383
- for (const segment of content) {
384
- if (typeof segment === "string") {
385
- textContent += segment;
386
- continue;
387
- }
388
- const { type, data } = segment;
389
- switch (type) {
390
- case "text":
391
- textContent += data.text || "";
392
- break;
393
- case "at":
394
- textContent += `<@${data.id}>`;
395
- break;
396
- case "channel_mention":
397
- textContent += `<#${data.id}>`;
398
- break;
399
- case "link":
400
- if (data.text && data.text !== data.url) {
401
- textContent += `<${data.url}|${data.text}>`;
402
- }
403
- else {
404
- textContent += `<${data.url}>`;
405
- }
406
- break;
407
- case "image":
408
- if (data.url) {
409
- attachments.push({
410
- image_url: data.url,
411
- title: data.name || data.title,
412
- });
413
- }
414
- break;
415
- case "file":
416
- // Files need to be uploaded separately
417
- if (data.file) {
418
- try {
419
- await this.client.files.upload({
420
- channels: channel,
421
- file: data.file,
422
- filename: data.name,
423
- });
424
- }
425
- catch (error) {
426
- this.logger.error("Failed to upload file:", error);
427
- }
428
- }
429
- break;
430
- default:
431
- textContent += data.text || `[${type}]`;
432
- }
433
- }
434
- // Send message
435
- const messageOptions = {
436
- channel,
437
- text: textContent.trim() || "Message",
438
- ...extraOptions,
439
- };
440
- if (attachments.length > 0) {
441
- messageOptions.attachments = attachments;
442
- }
443
- const result = await this.client.chat.postMessage(messageOptions);
444
- return result.message || {};
445
- }
446
- async $recallMessage(id) {
447
- // Slack requires both channel and ts (timestamp) to delete a message
448
- // The Endpoint interface only provides message ID (ts), making recall impossible
449
- // Users should use message.$recall() instead, which has the full context
450
- throw new Error("SlackEndpoint.$recallMessage: Message recall not supported without channel information. " +
451
- "Use message.$recall() method instead, which contains the required context.");
452
- }
453
- // ==================== 工作区管理 API ====================
454
- /**
455
- * 邀请用户到频道
456
- * @param channel 频道 ID
457
- * @param users 用户 ID 列表
458
- */
459
- async inviteToChannel(channel, users) {
460
- try {
461
- await this.client.conversations.invite({ channel, users: users.join(',') });
462
- this.logger.debug(formatCompact({ op: "invite", endpoint: this.$id, channel, users: users.join(",") }));
463
- return true;
464
- }
465
- catch (error) {
466
- this.logger.error(`Slack Endpoint ${this.$id} 邀请用户失败:`, error);
467
- throw error;
468
- }
469
- }
470
- /**
471
- * 从频道踢出用户
472
- * @param channel 频道 ID
473
- * @param user 用户 ID
474
- */
475
- async kickFromChannel(channel, user) {
476
- try {
477
- await this.client.conversations.kick({ channel, user });
478
- this.logger.debug(formatCompact({ op: "kick", endpoint: this.$id, channel, user }));
479
- return true;
480
- }
481
- catch (error) {
482
- this.logger.error(`Slack Endpoint ${this.$id} 踢出用户失败:`, error);
483
- throw error;
484
- }
485
- }
486
- /**
487
- * 设置频道话题
488
- * @param channel 频道 ID
489
- * @param topic 话题
490
- */
491
- async setChannelTopic(channel, topic) {
492
- try {
493
- await this.client.conversations.setTopic({ channel, topic });
494
- this.logger.debug(formatCompact({ op: "set_topic", endpoint: this.$id, channel }));
495
- return true;
496
- }
497
- catch (error) {
498
- this.logger.error(`Slack Endpoint ${this.$id} 设置话题失败:`, error);
499
- throw error;
500
- }
501
- }
502
- /**
503
- * 设置频道目的
504
- * @param channel 频道 ID
505
- * @param purpose 目的
506
- */
507
- async setChannelPurpose(channel, purpose) {
508
- try {
509
- await this.client.conversations.setPurpose({ channel, purpose });
510
- this.logger.debug(formatCompact({ op: "set_purpose", endpoint: this.$id, channel }));
511
- return true;
512
- }
513
- catch (error) {
514
- this.logger.error(`Slack Endpoint ${this.$id} 设置目的失败:`, error);
515
- throw error;
516
- }
517
- }
518
- /**
519
- * 归档频道
520
- * @param channel 频道 ID
521
- */
522
- async archiveChannel(channel) {
523
- try {
524
- await this.client.conversations.archive({ channel });
525
- this.logger.debug(formatCompact({ op: "archive", endpoint: this.$id, channel }));
526
- return true;
527
- }
528
- catch (error) {
529
- this.logger.error(`Slack Endpoint ${this.$id} 归档频道失败:`, error);
530
- throw error;
531
- }
532
- }
533
- /**
534
- * 取消归档频道
535
- * @param channel 频道 ID
536
- */
537
- async unarchiveChannel(channel) {
538
- try {
539
- await this.client.conversations.unarchive({ channel });
540
- this.logger.debug(formatCompact({ op: "unarchive", endpoint: this.$id, channel }));
541
- return true;
542
- }
543
- catch (error) {
544
- this.logger.error(`Slack Endpoint ${this.$id} 取消归档失败:`, error);
545
- throw error;
546
- }
547
- }
548
- /**
549
- * 重命名频道
550
- * @param channel 频道 ID
551
- * @param name 新名称
552
- */
553
- async renameChannel(channel, name) {
554
- try {
555
- await this.client.conversations.rename({ channel, name });
556
- this.logger.debug(formatCompact({ op: "rename", endpoint: this.$id, channel, name }));
557
- return true;
558
- }
559
- catch (error) {
560
- this.logger.error(`Slack Endpoint ${this.$id} 重命名频道失败:`, error);
561
- throw error;
562
- }
563
- }
564
- /**
565
- * 获取频道成员列表
566
- * @param channel 频道 ID
567
- */
568
- async getChannelMembers(channel) {
569
- try {
570
- const result = await this.client.conversations.members({ channel });
571
- return result.members || [];
572
- }
573
- catch (error) {
574
- this.logger.error(`Slack Endpoint ${this.$id} 获取成员列表失败:`, error);
575
- throw error;
576
- }
577
- }
578
- /**
579
- * 获取频道信息
580
- * @param channel 频道 ID
581
- */
582
- async getChannelInfo(channel) {
583
- try {
584
- const result = await this.client.conversations.info({ channel });
585
- return result.channel;
586
- }
587
- catch (error) {
588
- this.logger.error(`Slack Endpoint ${this.$id} 获取频道信息失败:`, error);
589
- throw error;
590
- }
591
- }
592
- /**
593
- * 获取用户信息
594
- * @param user 用户 ID
595
- */
596
- async getUserInfo(user) {
597
- try {
598
- const result = await this.client.users.info({ user });
599
- return result.user;
600
- }
601
- catch (error) {
602
- this.logger.error(`Slack Endpoint ${this.$id} 获取用户信息失败:`, error);
603
- throw error;
604
- }
605
- }
606
- /**
607
- * 添加消息反应
608
- * @param channel 频道 ID
609
- * @param timestamp 消息时间戳
610
- * @param name 表情名称
611
- */
612
- async addReaction(channel, timestamp, name) {
613
- try {
614
- await this.client.reactions.add({ channel, timestamp, name });
615
- this.logger.debug(formatCompact({ op: "reaction_add", endpoint: this.$id, name }));
616
- return true;
617
- }
618
- catch (error) {
619
- this.logger.error(`Slack Endpoint ${this.$id} 添加反应失败:`, error);
620
- throw error;
621
- }
622
- }
623
- /**
624
- * 移除消息反应
625
- * @param channel 频道 ID
626
- * @param timestamp 消息时间戳
627
- * @param name 表情名称
628
- */
629
- async removeReaction(channel, timestamp, name) {
630
- try {
631
- await this.client.reactions.remove({ channel, timestamp, name });
632
- this.logger.debug(formatCompact({ op: "reaction_remove", endpoint: this.$id, name }));
633
- return true;
634
- }
635
- catch (error) {
636
- this.logger.error(`Slack Endpoint ${this.$id} 移除反应失败:`, error);
637
- throw error;
638
- }
639
- }
640
- /**
641
- * 置顶消息
642
- * @param channel 频道 ID
643
- * @param timestamp 消息时间戳
644
- */
645
- async pinMessage(channel, timestamp) {
646
- try {
647
- await this.client.pins.add({ channel, timestamp });
648
- this.logger.debug(formatCompact({ op: "pin", endpoint: this.$id, channel }));
649
- return true;
650
- }
651
- catch (error) {
652
- this.logger.error(`Slack Endpoint ${this.$id} 置顶消息失败:`, error);
653
- throw error;
654
- }
655
- }
656
- /**
657
- * 取消置顶消息
658
- * @param channel 频道 ID
659
- * @param timestamp 消息时间戳
660
- */
661
- async unpinMessage(channel, timestamp) {
662
- try {
663
- await this.client.pins.remove({ channel, timestamp });
664
- this.logger.debug(formatCompact({ op: "unpin", endpoint: this.$id, channel }));
665
- return true;
666
- }
667
- catch (error) {
668
- this.logger.error(`Slack Endpoint ${this.$id} 取消置顶失败:`, error);
669
- throw error;
670
- }
671
- }
672
- }
673
- //# sourceMappingURL=endpoint.js.map