@@ -64,38 +64,64 @@ def handle_view_submission_events(ack, body, logger):
6464def handle_poll_create_submission (ack : Ack , body , client : SlackWebClientFCM , logger ):
6565 """Handle poll creation modal submission."""
6666 ack ()
67-
67+
6868 try :
6969 import datetime
70- from friendly_computing_machine .db .dal .poll_dal import insert_poll , insert_poll_options
71- from friendly_computing_machine .models .poll import PollCreate , PollOptionCreate
72- from friendly_computing_machine .temporal .poll_workflow import PollWorkflow , PollWorkflowParams
73- from friendly_computing_machine .temporal .util import execute_workflow , get_temporal_queue_name
70+
7471 from friendly_computing_machine .bot .util import slack_send_message
75- from friendly_computing_machine .db .dal .poll_dal import update_poll_message_info
76-
72+ from friendly_computing_machine .db .dal .poll_dal import (
73+ insert_poll ,
74+ insert_poll_options ,
75+ update_poll_message_info ,
76+ )
77+ from friendly_computing_machine .models .poll import PollCreate , PollOptionCreate
78+ from friendly_computing_machine .temporal .poll_workflow import (
79+ PollWorkflow ,
80+ PollWorkflowParams ,
81+ )
82+ from friendly_computing_machine .temporal .util import (
83+ execute_workflow ,
84+ get_temporal_queue_name ,
85+ )
86+
7787 # Extract form data
7888 values = body ["view" ]["state" ]["values" ]
79-
89+
8090 # Required fields
8191 title = values ["poll_title_block" ]["poll_title_input" ]["value" ]
8292 option1 = values ["poll_option_1_block" ]["poll_option_1_input" ]["value" ]
8393 option2 = values ["poll_option_2_block" ]["poll_option_2_input" ]["value" ]
84-
94+
8595 # Optional fields
86- description = values .get ("poll_description_block" , {}).get ("poll_description_input" , {}).get ("value" )
87- option3 = values .get ("poll_option_3_block" , {}).get ("poll_option_3_input" , {}).get ("value" )
88- option4 = values .get ("poll_option_4_block" , {}).get ("poll_option_4_input" , {}).get ("value" )
89- option5 = values .get ("poll_option_5_block" , {}).get ("poll_option_5_input" , {}).get ("value" )
90-
96+ description = (
97+ values .get ("poll_description_block" , {})
98+ .get ("poll_description_input" , {})
99+ .get ("value" )
100+ )
101+ option3 = (
102+ values .get ("poll_option_3_block" , {})
103+ .get ("poll_option_3_input" , {})
104+ .get ("value" )
105+ )
106+ option4 = (
107+ values .get ("poll_option_4_block" , {})
108+ .get ("poll_option_4_input" , {})
109+ .get ("value" )
110+ )
111+ option5 = (
112+ values .get ("poll_option_5_block" , {})
113+ .get ("poll_option_5_input" , {})
114+ .get ("value" )
115+ )
116+
91117 # Get user and channel info
92118 user_id = body ["user" ]["id" ]
93119 channel_id = body ["view" ]["private_metadata" ]
94-
120+
95121 if not channel_id :
96122 logger .error ("No channel ID found in private_metadata" )
97123 return
98-
124+
99125 # Create poll in database
100126 expires_at = datetime .datetime .now () + datetime .timedelta (hours = 8 )
101127 poll_create = PollCreate (
@@ -107,10 +133,10 @@ def handle_poll_create_submission(ack: Ack, body, client: SlackWebClientFCM, log
107133 expires_at = expires_at ,
108134 is_active = True ,
109135 )
110-
136+
111137 poll = insert_poll (poll_create )
112138 logger .info (f"Created poll with ID: { poll .id } " )
113-
139+
114140 # Create poll options
115141 options_data = [(option1 , 1 ), (option2 , 2 )]
116142 if option3 :
@@ -119,45 +145,48 @@ def handle_poll_create_submission(ack: Ack, body, client: SlackWebClientFCM, log
119145 options_data .append ((option4 , 4 ))
120146 if option5 :
121147 options_data .append ((option5 , 5 ))
122-
148+
123149 poll_options = [
124150 PollOptionCreate (poll_id = poll .id , text = text , display_order = order )
125151 for text , order in options_data
126152 ]
127-
153+
128154 insert_poll_options (poll_options )
129155 logger .info (f"Created { len (poll_options )} options for poll { poll .id } " )
130-
156+
131157 # Send initial poll message to channel
132158 initial_message = f"📊 **{ title } **"
133159 if description :
134160 initial_message += f"\n _{ description } _"
135161 initial_message += "\n \n _Setting up poll..._"
136-
162+
137163 slack_message = slack_send_message (
138164 channel = channel_id ,
139165 message = initial_message ,
140166 )
141-
167+
142168 # Update poll with message info
143- update_poll_message_info (poll .id , slack_message .id , slack_message .ts .isoformat ())
144-
169+ update_poll_message_info (
170+ poll .id , slack_message .id , slack_message .ts .isoformat ()
171+ )
172+
145173 # Start temporal workflow
146174 workflow_id = f"poll-workflow-{ poll .id } -{ datetime .datetime .now ().isoformat ()} "
147-
175+
148176 # Update poll with workflow ID
149177 from friendly_computing_machine .db .dal .poll_dal import update_poll_workflow_id
178+
150179 update_poll_workflow_id (poll .id , workflow_id )
151-
180+
152181 execute_workflow (
153182 PollWorkflow .run ,
154183 PollWorkflowParams (poll_id = poll .id , duration_hours = 8 ),
155184 id = workflow_id ,
156185 task_queue = get_temporal_queue_name ("main" ),
157186 )
158-
187+
159188 logger .info (f"Started poll workflow { workflow_id } for poll { poll .id } " )
160-
189+
161190 except Exception as e :
162191 logger .exception (f"Error creating poll: { e } " )
163192 # In a real app, you might want to show an error message to the user
0 commit comments