mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 02:32:56 +00:00
fix(slack): resolve user IDs to DM channels before files.uploadV2 (#23773)
When a bare Slack user ID (U-prefix) is passed as the send target
without an explicit `user:` prefix, `parseSlackTarget` classifies it as
kind="channel". `resolveChannelId` then passes it through to callers
without calling `conversations.open`.
This works for `chat.postMessage` (which tolerates user IDs), but
`files.uploadV2` delegates to `completeUploadExternal` which validates
`channel_id` against `^[CGDZ][A-Z0-9]{8,}$` — rejecting U-prefixed
IDs with `invalid_arguments`.
Fix: detect U-prefixed IDs in `resolveChannelId` regardless of the
parsed `kind`, and always resolve them via `conversations.open` to
obtain the DM channel ID (D-prefix).
Includes test coverage for bare, prefixed, and mention-style user ID
targets with file uploads, plus a channel-target negative case.
This commit is contained in:
@@ -166,7 +166,14 @@ async function resolveChannelId(
|
||||
client: WebClient,
|
||||
recipient: SlackRecipient,
|
||||
): Promise<{ channelId: string; isDm?: boolean }> {
|
||||
if (recipient.kind === "channel") {
|
||||
// Bare Slack user IDs (U-prefix) may arrive with kind="channel" when the
|
||||
// target string had no explicit prefix (parseSlackTarget defaults bare IDs
|
||||
// to "channel"). chat.postMessage tolerates user IDs directly, but
|
||||
// files.uploadV2 → completeUploadExternal validates channel_id against
|
||||
// ^[CGDZ][A-Z0-9]{8,}$ and rejects U-prefixed IDs. Always resolve user
|
||||
// IDs via conversations.open to obtain the DM channel ID.
|
||||
const isUserId = recipient.kind === "user" || /^U[A-Z0-9]+$/i.test(recipient.id);
|
||||
if (!isUserId) {
|
||||
return { channelId: recipient.id };
|
||||
}
|
||||
const response = await client.conversations.open({ users: recipient.id });
|
||||
|
||||
Reference in New Issue
Block a user