Skip to content

Commit

Permalink
refactor: 모달창 비동기로 띄우도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ppinkypeach committed Feb 11, 2024
1 parent e80564d commit ec64bcc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 63 deletions.
63 changes: 2 additions & 61 deletions server/notion/blog/handler/submitNotionCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,9 @@
import { App } from '@slack/bolt';
import { openSlackModal } from '../notionPage/openSlackModal';

export const submitNotionCommandHandler = (app: App) => {
app.command('/제출', async ({ ack, body, client }) => {

await ack();

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);
}
}
await openSlackModal(body, client);
});
}
2 changes: 0 additions & 2 deletions server/notion/blog/handler/uploadNotionBlogViewHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { handlerBlogUploadSubmission } from '../notionPage/handleBlogUploadSubmi

export const uploadNotionBlogViewHandler = (app: App, notion: Client) => {
app.view('uploadBlog', async({ack, body, view, client}) => {

await ack();

await handlerBlogUploadSubmission(body, view, client);
});
}
64 changes: 64 additions & 0 deletions server/notion/blog/notionPage/openSlackModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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);
}
}
}

0 comments on commit ec64bcc

Please sign in to comment.