Skip to content

Commit

Permalink
fix: 사서회의 메세지는 예약전송으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
not-using committed Dec 28, 2023
1 parent 501d569 commit 705f8da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/constants/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const ATTENDED = 'attended';
export const MEETING = '정기사서회의';
export const MEETING_MESSAGE_DELAY = 5;
export const MEETING_FALLBACK_MESSAGE =
'이 메세지를 보신다면 @sujikim DM 부탁드려요';
export const SHIFT = '사서근무';
export const SHIFT_WEEKEND = '주말사서근무';
17 changes: 14 additions & 3 deletions src/services/meeting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { MEETING } from '../constants/events.js';
import {
MEETING,
MEETING_FALLBACK_MESSAGE,
MEETING_MESSAGE_DELAY,
} from '../constants/events.js';
import { SLACK_ID_RANGE } from '../constants/sheet.js';
import { confirmMessage } from '../messages/confirmMessage.js';
import { sendBlocks } from '../utils/slackChat.js';
import { scheduleBlocks } from '../utils/slackChat.js';
import { httpClientForSheet } from '../utils/httpClient.js';

export const sendMeetingConfirmation = async () => {
Expand All @@ -10,7 +14,14 @@ export const sendMeetingConfirmation = async () => {
const librarians = await getLibrariansFromSheet();

await Promise.all(
librarians.map((librarian) => sendBlocks(librarian, message))
librarians.map((librarian) =>
scheduleBlocks(
librarian,
message,
MEETING_FALLBACK_MESSAGE,
MEETING_MESSAGE_DELAY
)
)
);
console.log('meeting', librarians);
};
Expand Down
11 changes: 11 additions & 0 deletions src/utils/slackChat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WebClient } from '@slack/web-api';
import { getFutureUnixTimestamp } from './unixTimeStamp.js';

const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
Expand All @@ -18,3 +19,13 @@ export const sendBlocks = async (to, blocks) => {
blocks,
});
};

export const scheduleBlocks = async (to, blocks, fallbackMessage, minutes) => {
await web.chat.scheduleMessage({
token,
channel: to,
blocks,
text: fallbackMessage,
post_at: getFutureUnixTimestamp(minutes),
});
};
6 changes: 6 additions & 0 deletions src/utils/unixTimeStamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const getFutureUnixTimestamp = (minutes) => {
const seconds = typeof minutes !== 'number' ? 0 : minutes * 60;
const currentTimestamp = Math.floor(Date.now().getTime() / 1000); // 초 단위로 변환

return currentTimestamp + seconds * 60;
};

0 comments on commit 705f8da

Please sign in to comment.