Skip to content

Commit

Permalink
refactor: 슬랙 알림 메시지 처리를 위한 메시지 포맷 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
tlarbals824 committed Aug 24, 2024
1 parent 0e01704 commit 401d9a7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions slack_notification/recommend/recommend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def find_by_id(self, record_id):
class RecommendMessageHandler:
def __init__(self):
self.__slack_url = os.environ['RECOMMEND_SLACK_URL']
self.__db_properties = secret_manager.get_secret_properties("chiksnap/db")
self.__connector = mysql_connector.MysqlConnector(self.__db_properties)

self.__message_format = """
새로운 추천 요청이 들어왔어요! 🎉
- 전화번호: {phone_number}
- 선호 스타일: {prefer_style}
""".strip()

def __call__(self, message):
self.handle(message)
Expand All @@ -34,21 +42,14 @@ def __call__(self, message):
def handle(self, message):
record_id = message['record_id']

db_properties = secret_manager.get_secret_properties("chiksnap/db")
connector = mysql_connector.MysqlConnector(db_properties)

recommend_repository = RecommendRepository(connector)
recommend_repository = RecommendRepository(self.__connector)

result = recommend_repository.find_by_id(record_id)
phone_number = result.phone_number
prefer_style = result.prefer_style

data = {
'text': f"""
새로운 추천 요청이 들어왔어요! 🎉
- 전화번호: {phone_number}
- 선호 스타일: {prefer_style}
""".strip()
'text': self.__message_format.format(phone_number = phone_number, prefer_style = prefer_style)
}

requests.post(self.__slack_url, data=json.dumps(data), headers={'Content-Type': 'application/json'})

0 comments on commit 401d9a7

Please sign in to comment.