Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d849bbe
feat(slack): Enhance DM and file handling with new upload functionali…
yuriassuncx Sep 13, 2025
7610493
refactor(slack): Remove unused file download and info actions
yuriassuncx Sep 13, 2025
9648018
refactor(slack): Reorder and optimize SCOPES in constants.ts
yuriassuncx Sep 13, 2025
9479dcb
fix: improve openDmChannel function suggested by coderabbitai
yuriassuncx Sep 13, 2025
eb6f357
feat(slack): add pagination support to channel and DM history retrieval
yuriassuncx Sep 13, 2025
9b7395b
feat(slack): enhance file upload and message posting with improved re…
yuriassuncx Sep 13, 2025
92b49f1
feat(slack): add titles to various actions for improved clarity and d…
yuriassuncx Sep 13, 2025
f52a5c4
fix: improvements suggested by coderabbitai
yuriassuncx Sep 13, 2025
433be8f
feat(slack): enhance Slack API response handling with improved data s…
yuriassuncx Sep 14, 2025
8d9e729
feat: new improvements suggested by coderabbit
yuriassuncx Sep 14, 2025
5d770cd
feat(slack): implement new file upload V2 API and update documentatio…
yuriassuncx Sep 14, 2025
c3b02d6
Merge branch 'feat/slack-improvements' of https://github.com/yuriassu…
yuriassuncx Sep 14, 2025
e33e51a
refactor(slack): update response handling to use new data structure i…
yuriassuncx Sep 14, 2025
fa3635c
feat: new improvements added by coderabbit
yuriassuncx Sep 15, 2025
c4d719f
refactor(slack): update UploadFileResponse to expose a safe subset of…
yuriassuncx Sep 15, 2025
6dd38c4
feat: new improvements to upload action
yuriassuncx Sep 15, 2025
e7d4e16
fix: new improvements added to file action by coderrabit
yuriassuncx Sep 15, 2025
3f5072d
fix: remove unnecessary closing braces in uploadFile function
yuriassuncx Sep 15, 2025
85f7de7
fix: adjust default channel limit to 100 for consistency in Slack API…
yuriassuncx Sep 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions slack/actions/dms/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export interface SendDmProps {
blocks?: unknown[];
}

export interface SendDmResponse {
success: boolean;
message: string;
channelId?: string;
ts?: string;
messageData?: {
ok: boolean;
channel: string;
ts: string;
warning?: string;
response_metadata?: {
warnings?: string[];
};
};
}

/**
* @description Sends a direct message to a user
* @action send-dm
Expand All @@ -25,41 +41,32 @@ export default async function sendDm(
props: SendDmProps,
_req: Request,
ctx: AppContext,
): Promise<
{ success: boolean; message: string; channelId?: string; ts?: string }
> {
): Promise<SendDmResponse> {
try {
// Open a DM channel with the user
const channelResponse = await ctx.slack.openDmChannel(props.userId);

if (!channelResponse.ok) {
return {
success: false,
message: `Failed to open DM channel: ${
channelResponse.error || "Unknown error"
}`,
};
}

const channelId = channelResponse.data.channel.id;

// Send the message to the DM channel
const messageResponse = await ctx.slack.postMessage(channelId, props.text, {
// Send message directly to the user ID (Slack automatically opens DM channel)
const messageResponse = await ctx.slack.postMessage(props.userId, props.text, {
blocks: props.blocks,
});

if (!messageResponse.ok) {
return {
success: false,
message: "Failed to send DM: Unknown error",
message: `Failed to send DM: ${messageResponse.error || "Unknown error"}`,
};
}

return {
success: true,
message: "DM sent successfully",
channelId,
channelId: messageResponse.channel,
ts: messageResponse.ts,
messageData: {
ok: messageResponse.ok,
channel: messageResponse.channel,
ts: messageResponse.ts,
warning: messageResponse.warning,
response_metadata: messageResponse.response_metadata,
},
};
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
Expand Down
112 changes: 112 additions & 0 deletions slack/actions/files/upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import type { AppContext } from "../../mod.ts";

export interface UploadFileProps {
/**
* @description Channel ID or DM ID to send the file to (e.g., C123... or D123...)
*/
channels: string;

/**
* @description File content as base64 string or File object
*/
file: string | File;

/**
* @description Name of the file
*/
filename: string;

/**
* @description Title of the file
*/
title?: string;

/**
* @description Initial comment/message that accompanies the file
*/
initial_comment?: string;

/**
* @description File type (optional, usually auto-detected)
*/
filetype?: string;
}

export interface UploadFileResponse {
ok: boolean;
file?: {
id: string;
created: number;
timestamp: number;
name: string;
title: string;
mimetype: string;
filetype: string;
pretty_type: string;
user: string;
editable: boolean;
size: number;
mode: string;
is_external: boolean;
external_type: string;
is_public: boolean;
public_url_shared: boolean;
display_as_bot: boolean;
username: string;
url_private: string;
url_private_download: string;
permalink: string;
permalink_public?: string;
channels: string[];
groups: string[];
ims: string[];
comments_count: number;
is_starred?: boolean;
};
error?: string;
warning?: string;
response_metadata?: {
warnings?: string[];
};
}

/**
* @description Uploads a file to Slack
* @action upload-file
*/
export default async function uploadFile(
props: UploadFileProps,
_req: Request,
ctx: AppContext,
): Promise<UploadFileResponse> {
try {
const response = await ctx.slack.uploadFile({
channels: props.channels,
file: props.file,
filename: props.filename,
title: props.title,
initial_comment: props.initial_comment,
filetype: props.filetype,
});

if (!response.ok) {
return {
ok: false,
error: response.error || "Failed to upload file",
};
}

return {
ok: response.ok,
file: response.file,
warning: response.warning,
response_metadata: response.response_metadata,
};
} catch (error) {
console.error("Error uploading file:", error);
return {
ok: false,
error: error instanceof Error ? error.message : "Unknown error",
};
}
}
Loading
Loading