@dreki-gg/pi-slack 0.3.0 → 0.4.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/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/extensions/slack/client/messages.ts +21 -0
- package/extensions/slack/format.ts +9 -1
- package/extensions/slack/index.ts +44 -1
- package/extensions/slack/tools.ts +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @dreki-gg/pi-slack
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add a `slack_delete_message` tool that deletes a message the bot previously
|
|
8
|
+
posted via Slack's `chat.delete` API. Pass the channel ID and the message `ts`;
|
|
9
|
+
bots can only delete their own messages. No new scope is required — it uses the
|
|
10
|
+
existing `chat:write` permission.
|
|
11
|
+
|
|
3
12
|
## 0.3.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Uses [Effect](https://effect.website) for the Slack client layer (typed errors,
|
|
|
15
15
|
| `slack_download_file` | Download a shared file/image to temp directory |
|
|
16
16
|
| `slack_post_message` | Post a message to a channel or reply in a thread (requires `chat:write`) |
|
|
17
17
|
| `slack_edit_message` | Edit a message the bot previously posted (requires `chat:write`) |
|
|
18
|
+
| `slack_delete_message` | Delete a message the bot previously posted (requires `chat:write`) |
|
|
18
19
|
|
|
19
20
|
## Setup
|
|
20
21
|
|
|
@@ -19,6 +19,13 @@ export interface EditMessageResult {
|
|
|
19
19
|
channel: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export interface DeleteMessageResult {
|
|
23
|
+
/** Timestamp of the deleted message. */
|
|
24
|
+
ts: string;
|
|
25
|
+
/** Channel the message lived in. */
|
|
26
|
+
channel: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
// ---------------------------------------------------------------------------
|
|
23
30
|
// Effects
|
|
24
31
|
// ---------------------------------------------------------------------------
|
|
@@ -63,3 +70,17 @@ export function editMessage(params: { channel: string; ts: string; text: string
|
|
|
63
70
|
} satisfies EditMessageResult;
|
|
64
71
|
});
|
|
65
72
|
}
|
|
73
|
+
|
|
74
|
+
export function deleteMessage(params: { channel: string; ts: string }) {
|
|
75
|
+
return Effect.gen(function* () {
|
|
76
|
+
const resp = yield* slackPost<{ ok: true; ts: string; channel: string }>('chat.delete', {
|
|
77
|
+
channel: params.channel,
|
|
78
|
+
ts: params.ts,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
ts: resp.ts,
|
|
83
|
+
channel: resp.channel,
|
|
84
|
+
} satisfies DeleteMessageResult;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { SlackChannel, SlackMessage, ReadMessagesResult } from './client/channels.js';
|
|
2
2
|
import type { SearchResult } from './client/search.js';
|
|
3
3
|
import type { DownloadedFile, SlackFileInfo } from './client/files.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
PostMessageResult,
|
|
6
|
+
EditMessageResult,
|
|
7
|
+
DeleteMessageResult,
|
|
8
|
+
} from './client/messages.js';
|
|
5
9
|
|
|
6
10
|
// ---------------------------------------------------------------------------
|
|
7
11
|
// Channels
|
|
@@ -94,6 +98,10 @@ export function formatEditedMessage(result: EditMessageResult): string {
|
|
|
94
98
|
return `✏️ Message edited in ${result.channel} (ts: ${result.ts})`;
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
export function formatDeletedMessage(result: DeleteMessageResult): string {
|
|
102
|
+
return `🗑️ Message deleted in ${result.channel} (ts: ${result.ts})`;
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
// ---------------------------------------------------------------------------
|
|
98
106
|
// Files
|
|
99
107
|
// ---------------------------------------------------------------------------
|
|
@@ -14,7 +14,7 @@ import { listChannels } from './client/channels.js';
|
|
|
14
14
|
import { readMessages, readThread } from './client/channels.js';
|
|
15
15
|
import { searchMessages } from './client/search.js';
|
|
16
16
|
import { downloadFile } from './client/files.js';
|
|
17
|
-
import { postMessage, editMessage } from './client/messages.js';
|
|
17
|
+
import { postMessage, editMessage, deleteMessage } from './client/messages.js';
|
|
18
18
|
import {
|
|
19
19
|
formatChannelList,
|
|
20
20
|
formatMessages,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
formatDownloadedFile,
|
|
24
24
|
formatPostedMessage,
|
|
25
25
|
formatEditedMessage,
|
|
26
|
+
formatDeletedMessage,
|
|
26
27
|
} from './format.js';
|
|
27
28
|
import {
|
|
28
29
|
TOOL_GUIDELINES,
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
downloadFileParams,
|
|
34
35
|
postMessageParams,
|
|
35
36
|
editMessageParams,
|
|
37
|
+
deleteMessageParams,
|
|
36
38
|
} from './tools.js';
|
|
37
39
|
|
|
38
40
|
// ---------------------------------------------------------------------------
|
|
@@ -379,6 +381,47 @@ export default function slackExtension(pi: ExtensionAPI) {
|
|
|
379
381
|
},
|
|
380
382
|
});
|
|
381
383
|
|
|
384
|
+
// -------------------------------------------------------------------------
|
|
385
|
+
// slack_delete_message
|
|
386
|
+
// -------------------------------------------------------------------------
|
|
387
|
+
|
|
388
|
+
pi.registerTool({
|
|
389
|
+
name: 'slack_delete_message',
|
|
390
|
+
label: 'Slack Delete Message',
|
|
391
|
+
description:
|
|
392
|
+
'Delete a message the bot previously posted. Requires the bot token to have the `chat:write` scope. Bots can only delete their own messages.',
|
|
393
|
+
promptSnippet: 'Delete a message the bot previously posted',
|
|
394
|
+
promptGuidelines: TOOL_GUIDELINES,
|
|
395
|
+
parameters: deleteMessageParams,
|
|
396
|
+
|
|
397
|
+
async execute(
|
|
398
|
+
_toolCallId: string,
|
|
399
|
+
params: {
|
|
400
|
+
channel: string;
|
|
401
|
+
ts: string;
|
|
402
|
+
},
|
|
403
|
+
) {
|
|
404
|
+
const creds = getCredentials();
|
|
405
|
+
if (!creds) return missingCredentials('bot');
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
const result = await runSlack(
|
|
409
|
+
creds,
|
|
410
|
+
deleteMessage({
|
|
411
|
+
channel: params.channel,
|
|
412
|
+
ts: params.ts,
|
|
413
|
+
}),
|
|
414
|
+
);
|
|
415
|
+
return textResult(formatDeletedMessage(result), {
|
|
416
|
+
channel: result.channel,
|
|
417
|
+
ts: result.ts,
|
|
418
|
+
});
|
|
419
|
+
} catch (err) {
|
|
420
|
+
return errorResult(`❌ ${(err as Error).message}`);
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
|
|
382
425
|
// -------------------------------------------------------------------------
|
|
383
426
|
// /slack command — status check
|
|
384
427
|
// -------------------------------------------------------------------------
|
|
@@ -13,6 +13,7 @@ export const TOOL_GUIDELINES = [
|
|
|
13
13
|
'Use `slack_download_file` to download images or files shared in Slack. The tool saves files to a temp directory and returns the path — use `read` to view images.',
|
|
14
14
|
'Use `slack_post_message` to send a message to a channel or reply in a thread. The bot token must have the `chat:write` scope and the bot must be a member of the target channel.',
|
|
15
15
|
'Use `slack_edit_message` to edit a message the bot previously posted. Pass the channel ID and the message `ts` (returned by `slack_post_message`). Bots can only edit their own messages.',
|
|
16
|
+
'Use `slack_delete_message` to delete a message the bot previously posted. Pass the channel ID and the message `ts`. Bots can only delete their own messages.',
|
|
16
17
|
'When messages reference files or images (shown with 📎), download them with `slack_download_file` using the file ID to get visual context.',
|
|
17
18
|
'Channel IDs look like C0123ABC456. Thread timestamps look like 1512085950.000216.',
|
|
18
19
|
];
|
|
@@ -147,3 +148,12 @@ export const editMessageParams = Type.Object({
|
|
|
147
148
|
description: 'New message text. Supports Slack mrkdwn formatting.',
|
|
148
149
|
}),
|
|
149
150
|
});
|
|
151
|
+
|
|
152
|
+
export const deleteMessageParams = Type.Object({
|
|
153
|
+
channel: Type.String({
|
|
154
|
+
description: 'Channel ID (e.g. C0123ABC456) where the message lives.',
|
|
155
|
+
}),
|
|
156
|
+
ts: Type.String({
|
|
157
|
+
description: 'Timestamp of the message to delete (the `ts` returned by slack_post_message).',
|
|
158
|
+
}),
|
|
159
|
+
});
|
package/package.json
CHANGED