22from mapswipe_workers .definitions import logger
33from mapswipe_workers import auth
44from mapswipe_workers .config import SLACK_CHANNEL , SLACK_TOKEN
5+ from mapswipe_workers .definitions import MessageType
56
67
7- def send_slack_message (message_type : str , project_name : str , project_id : str = None ):
8+ def send_slack_message (
9+ message_type : MessageType , project_name : str , project_id : str = None
10+ ):
811 """Initialize slack client with values provided in environment."""
912 if SLACK_TOKEN is None or SLACK_CHANNEL is None :
1013 logger .info (
@@ -15,7 +18,7 @@ def send_slack_message(message_type: str, project_name: str, project_id: str = N
1518
1619 slack_client = slack .WebClient (token = SLACK_TOKEN )
1720
18- if message_type == "success" :
21+ if message_type == MessageType . SUCCESS :
1922 message = (
2023 "### PROJECT CREATION SUCCESSFUL ###\n "
2124 + f"Project Name: { project_name } \n "
@@ -24,22 +27,22 @@ def send_slack_message(message_type: str, project_name: str, project_id: str = N
2427 + "Happy Swiping. :)"
2528 )
2629 slack_client .chat_postMessage (channel = SLACK_CHANNEL , text = message )
27- elif message_type == "fail" :
30+ elif message_type == MessageType . FAIL :
2831 message = (
2932 "### PROJECT CREATION FAILED ###\n "
3033 + f"Project Name: { project_name } \n "
3134 + "Project draft is deleted."
3235 )
3336 slack_client .chat_postMessage (channel = SLACK_CHANNEL , text = message )
34- elif message_type == "notification_90" :
37+ elif message_type == MessageType . NOTIFICATION_90 :
3538 message = (
3639 "### ALMOST THERE! PROJECT REACHED 90% ###\n "
3740 + f"Project Name: { project_name } \n "
3841 + f"Project Id: { project_id } \n \n "
3942 + "Get your next projects ready."
4043 )
4144 slack_client .chat_postMessage (channel = "mapswipe_managers" , text = message )
42- elif message_type == "notification_100" :
45+ elif message_type == MessageType . NOTIFICATION_100 :
4346 message = (
4447 "### GREAT! PROJECT REACHED 100% ###\n "
4548 + f"Project Name: { project_name } \n "
@@ -73,10 +76,10 @@ def send_progress_notification(project_id: int):
7376
7477 if progress >= 90 and not notification_90_sent :
7578 # send notification and set value in firebase
76- send_slack_message ("notification_90" , project_name , project_id )
79+ send_slack_message (MessageType . NOTIFICATION_90 , project_name , project_id )
7780 fb_db .reference (f"v2/projects/{ project_id } /notification_90_sent" ).set (True )
7881
7982 if progress >= 100 and not notification_100_sent :
8083 # send notification and set value in firebase
81- send_slack_message ("notification_100" , project_name , project_id )
84+ send_slack_message (MessageType . NOTIFICATION_100 , project_name , project_id )
8285 fb_db .reference (f"v2/projects/{ project_id } /notification_100_sent" ).set (True )
0 commit comments