Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion packages/slack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"typecheck": "tsc --noEmit"
},
"exports": {
".": "./src/index.ts"
".": "./src/index.ts",
"./client": "./src/client.ts",
"./thread": "./src/thread.ts"
},
"dependencies": {
"@makers-devops/redis": "workspace:*",
Expand Down
57 changes: 0 additions & 57 deletions packages/slack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,2 @@
import type { ChatPostMessageArguments } from "@slack/web-api";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 베럴파일의 존재이유가 뭔가요? client.ts도 따로 export하고, thread.ts도 따로 export해주는거 같아서요!
여기서 types랑 redis만 관리하는 이유가 있을까요?

import type { SlackThreadData, SlackThreadMessage } from "./types";
import { slackClient } from "./client";
import { getSlackThreadData, setSlackThreadData } from "./redis";

export * from "./client";
export * from "./types";
export * from "./redis";

function toChatPostMessageArgs({ channel, message }: SlackThreadMessage): ChatPostMessageArguments {
if (message.blocks !== undefined) {
return {
channel,
text: message.text,
blocks: message.blocks,
};
}

return {
channel,
text: message.text,
};
}

export const createSlackThread = async (id: string, _message: SlackThreadMessage) => {
try {
const response = await slackClient.chat.postMessage(toChatPostMessageArgs(_message));

if (response.ok) {
const data: SlackThreadData = {
id,
version: 1,
channel: response.channel ?? _message.channel,
thread_ts: response.ts ?? "",
};
await setSlackThreadData(id, data, _message.ex ? { ex: _message.ex } : undefined);

return data;
}

return null;
} catch (error) {
console.error(error);
return null;
}
};

export const findSlackThread = async (id: string) => {
try {
const data = await getSlackThreadData(id);

if (data) {
return data;
}
} catch (error) {
console.error(error);
}
return null;
};
55 changes: 55 additions & 0 deletions packages/slack/src/thread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { SlackThreadMessage } from "./types";
import { slackClient } from "./client";
import { setSlackThreadData, getSlackThreadData } from "./redis";
import type { SlackThreadData } from "./types";

function toChatPostMessageArgs({ channel, message }: SlackThreadMessage) {
if (message.blocks !== undefined) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 머리가 나빠서 그런가... message의 blocks 값이 undefined가 아니라는건 어떤 의미인가요?
blocks가 의미하는게 뭔지 주석으로 써놓는건 어떨까싶네요

return {
channel,
text: message.text,
blocks: message.blocks,
};
}

return {
channel,
text: message.text,
};
}

export const createSlackThread = async (id: string, _message: SlackThreadMessage) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 언더바는 안쓰는 값이라는 암묵적인 뜻이 있는 걸로 아는데, _message에 언더바가 붙은 이유는 뭔가여?

try {
const response = await slackClient.chat.postMessage(toChatPostMessageArgs(_message));

if (response.ok) {
const data: SlackThreadData = {
id,
version: 1,
channel: response.channel ?? _message.channel,
thread_ts: response.ts ?? "",
};
await setSlackThreadData(id, data, _message.ex ? { ex: _message.ex } : undefined);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis instance에 저장하고 끝인가요?
그 후에 redis에서 캐싱해오기 위한 로직인지 궁금합니다. just wonder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 리뷰하면서 이해완료했슴니다 ㅎㅎ


return data;
}

return null;
} catch (error) {
console.error(error);
return null;
}
};

export const findSlackThread = async (id: string) => {
try {
const data = await getSlackThreadData(id);

if (data) {
return data;
}
} catch (error) {
console.error(error);
}
return null;
};
Loading