From 60481a4237f3b2091d260c186c11dad5f8061674 Mon Sep 17 00:00:00 2001 From: ppinkypeach Date: Mon, 12 Feb 2024 14:57:19 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20submitNotionCommandHandler=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/submitNotionCommandHandler.ts | 73 ++++++++++++++++++- .../notion/blog/notionPage/openSlackModal.ts | 64 ---------------- 2 files changed, 69 insertions(+), 68 deletions(-) delete mode 100644 server/notion/blog/notionPage/openSlackModal.ts diff --git a/server/notion/blog/handler/submitNotionCommandHandler.ts b/server/notion/blog/handler/submitNotionCommandHandler.ts index 85ab041..7bbd2e5 100644 --- a/server/notion/blog/handler/submitNotionCommandHandler.ts +++ b/server/notion/blog/handler/submitNotionCommandHandler.ts @@ -1,11 +1,76 @@ import { App } from '@slack/bolt'; -import { openSlackModal } from '../notionPage/openSlackModal'; + +const techBlogChannelId = [process.env.TEAM_JOON_CHANNEL, process.env.DEBUG_CHANNEL]; +if(!techBlogChannelId.every((channelId) => channelId )){ + console.error('채널 ID가 제대로 설정되지 않은 환경변수 문제'); +} export const submitNotionCommandHandler = (app: App) => { app.command('/제출', async ({ ack, body, client }) => { - await ack(); - openSlackModal(body, client); - + await ack(); + + const currentChannelId = body.channel_id; + + if(!techBlogChannelId.includes(currentChannelId)){ + try{ + await client.chat.postMessage({ + channel: body.user_id, + text: '해당 명령어는 테크 블로깅 챌린지 채널에서만 사용할 수 있습니다😗' + }); + } catch (error) { + console.error('다른 채널에서 slash command 실행시 에러메세지 에러:', error); + } + }else{ + try { + await client.views.open({ + trigger_id: body.trigger_id, + view: { + type: 'modal', + callback_id: 'uploadBlog', + title: { + type: 'plain_text', + text: '[테크 블로깅 챌린지] 블로그 등록 ' + }, + blocks: [ + { + type: 'input', + block_id: 'blog_name_block', + element: { + type: 'plain_text_input', + action_id: 'blog_name_action', + }, + label: { + type: 'plain_text', + text: '블로그 이름', + } + }, + { + type: 'input', + block_id: 'blog_link_block', + element: { + type: 'plain_text_input', + action_id: 'blog_link_action', + }, + label: { + type: 'plain_text', + text: '블로그 URL', + } + }, + ], + submit: { + type: 'plain_text', + text: '제출' + } + } + }); + } catch (error) { + console.error('슬랙 창 열기 실패:', error); + await client.chat.postMessage({ + channel: body.user_id, + text: '슬랙 모달창에 문제가 생겼어요😵 다시 시도해주세용!' + }); + } + } }); } \ No newline at end of file diff --git a/server/notion/blog/notionPage/openSlackModal.ts b/server/notion/blog/notionPage/openSlackModal.ts deleted file mode 100644 index 3d2433f..0000000 --- a/server/notion/blog/notionPage/openSlackModal.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { SlashCommand } from "@slack/bolt"; - -export async function openSlackModal(body:SlashCommand, client: any) { - - const techBlogChannelId = [process.env.TEAM_JOON_CHANNEL, process.env.DEBUG_CHANNEL]; - const currentChannelId = body.channel_id; - - if(!techBlogChannelId.includes(currentChannelId)){ - try{ - await client.chat.postMessage({ - channel: body.user_id, - text: '해당 명령어는 테크 블로깅 챌린지 채널에서만 사용할 수 있습니다😗' - }); - } catch (error) { - console.error('다른 채널에서 slash command 실행시 에러메세지 에러:', error); - } - }else{ - try { - await client.views.open({ - trigger_id: body.trigger_id, - view: { - type: 'modal', - callback_id: 'uploadBlog', - title: { - type: 'plain_text', - text: '[테크 블로깅 챌린지] 블로그 등록 ' - }, - blocks: [ - { - type: 'input', - block_id: 'blog_name_block', - element: { - type: 'plain_text_input', - action_id: 'blog_name_action', - }, - label: { - type: 'plain_text', - text: '블로그 이름', - } - }, - { - type: 'input', - block_id: 'blog_link_block', - element: { - type: 'plain_text_input', - action_id: 'blog_link_action', - }, - label: { - type: 'plain_text', - text: '블로그 URL', - } - }, - ], - submit: { - type: 'plain_text', - text: '제출' - } - } - }); - } catch (error) { - console.error('슬랙 창 열기 실패:', error); - } - } -} \ No newline at end of file