Skip to content

Commit

Permalink
feat: get_slack_event 메서드 코드 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
JAY-Chan9yu committed Feb 19, 2023
1 parent f1a3170 commit 59508b6
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions app/api/dependency/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@
from app.applications.services.slack_services import SLACK_EVENT_HOOKS
from app.domains.reactions.entities import SlackEventType


async def get_slack_event(request: Request) -> SLACK_EVENT_HOOKS:

request_data: dict
try:
request_data = await request.json()
request_data: dict = await request.json()
challenge_request = request_data.get('challenge')
event_request = request_data.get('event')
except JSONDecodeError:
raise HTTPException(status_code=400, detail="request body can not be none")
if request_data.get('challenge'):

if challenge_request:
return SlackChallengeHook(**request_data)
elif request_data['event'].get('bot_profile'):
return SlackBotDirectMessageHook(**request_data)
elif request_data['event']['type'] in [SlackEventType.APP_MENTION_REACTION.value, SlackEventType.APP_MESSAGE.value]:
return SlackMentionHook(**request_data)
elif event_request:
if event_request.get('bot_profile'):
return SlackBotDirectMessageHook(**request_data)
elif is_slack_mention(event_request['type']):
return SlackMentionHook(**request_data)
else:
return SlackEventHook(**request_data)
else:
return SlackEventHook(**request_data)
raise HTTPException(status_code=403, detail="please check slack event")


def is_slack_mention(event_type: str) -> bool:
return event_type in [
SlackEventType.APP_MENTION_REACTION.value,
SlackEventType.APP_MESSAGE.value
]

0 comments on commit 59508b6

Please sign in to comment.