11import  {  NextFunction ,  Request ,  RequestHandler ,  Response  }  from  'express' ; 
22import  {  EmptyResponseDto ,  SentryWebhookData  }  from  '@/types' ; 
33import  logger  from  '@/configs/logger.config' ; 
4- import  {  sendSlackMessage  }  from  '@/modules/slack/slack.notifier' ; 
4+ //  import { sendSlackMessage } from '@/modules/slack/slack.notifier';
55
66export  class  WebhookController  { 
77 private  readonly  STATUS_EMOJI  =  { 
@@ -11,23 +11,17 @@ export class WebhookController {
1111 'archived' : '📦' , 
1212 }  as  const ; 
1313
14-  private  readonly  ACTION_TEXT  =  { 
15-  'created' : '새로운 오류가 발생했습니다' , 
16-  'resolved' : '오류가 해결되었습니다' , 
17-  'unresolved' : '오류가 다시 발생했습니다' , 
18-  'ignored' : '오류가 무시되었습니다' , 
19-  'assigned' : '오류가 할당되었습니다' , 
20-  }  as  const ; 
21- 
2214 handleSentryWebhook : RequestHandler  =  async  ( 
2315 req : Request , 
2416 res : Response , 
2517 next : NextFunction , 
2618 ) : Promise < void >  =>  { 
2719 try  { 
2820 const  sentryData : SentryWebhookData  =  req . body ; 
21+  if ( sentryData . action  !==  "created" )  res . status ( 400 ) . json ( new  EmptyResponseDto ( true ,  'Sentry 웹훅 처리에 실패했습니다' ,  { } ,  null ) ) ; 
2922 const  slackMessage  =  this . formatSentryMessage ( sentryData ) ; 
30-  await  sendSlackMessage ( slackMessage ) ; 
23+  console . log ( slackMessage ) ; 
24+  // await sendSlackMessage(slackMessage); 
3125
3226 const  response  =  new  EmptyResponseDto ( true ,  'Sentry 웹훅 처리에 성공하였습니다.' ,  { } ,  null ) ; 
3327 res . status ( 200 ) . json ( response ) ; 
@@ -38,23 +32,17 @@ export class WebhookController {
3832 } ; 
3933
4034 private  formatSentryMessage ( sentryData : SentryWebhookData ) : string  { 
41-  const  {  action,  data }  =  sentryData  ||  { } ; 
42-  const  issue  =  data ?. issue  ||  { } ; 
35+  const  {  data : {  issue }  }  =  sentryData ; 
36+ 
37+  if ( ! issue . status  ||  ! issue . title  ||  ! issue . culprit  ||  ! issue . permalink  ||  ! issue . id )  throw  new  Error ( 'Sentry 웹훅 데이터가 올바르지 않습니다' ) ; 
4338
44-  // 알 수 없는 액션에 대한 기본값 처리 
45-  const  actionText  =  this . ACTION_TEXT [ action  as  keyof  typeof  this . ACTION_TEXT ]  ||  `오류 이벤트: ${ action }  ; 
46-  
47-  // 알 수 없는 상태에 대한 기본값 처리 
48-  const  statusEmoji  =  this . STATUS_EMOJI [ issue . status  as  keyof  typeof  this . STATUS_EMOJI ]  ||  '❓' ; 
49-  
50-  const  issueTitle  =  issue . title  ||  '제목 없음' ; 
51-  const  culprit  =  issue . culprit  ||  '위치 정보 없음' ; 
52-  const  permalink  =  issue . permalink ; 
39+  const  {  status,  title : issueTitle ,  culprit,  permalink,  id }  =  issue ; 
40+  const  statusEmoji  =  this . STATUS_EMOJI [ status  as  keyof  typeof  this . STATUS_EMOJI ] ; 
5341
5442 // URL 생성 - permalink가 있으면 사용, 없으면 실제 프로젝트 URL 패턴으로 생성 
55-  const  detailUrl  =  permalink  ||  `https://velog-dashboardv2.sentry.io/issues/${ issue . id   ||   'unknown' }  ; 
43+  const  detailUrl  =  permalink  ||  `https://velog-dashboardv2.sentry.io/issues/${ id }  ; 
5644
57-  let  message  =  `🚨 *${ actionText }  ; 
45+  let  message  =  `🚨 *새로운 오류가 발생하였습니다 *\n\n` ; 
5846 message  +=  `${ statusEmoji } ${ issueTitle }  ; 
5947 message  +=  `📍 *위치:* ${ culprit }  ; 
6048 message  +=  `🔗 *상세 보기:* ${ detailUrl }  ; 
0 commit comments