11import json
2+ import uuid
23
34import httpx
45import structlog
@@ -71,7 +72,10 @@ async def slack_interactions(request: Request):
7172 action = payload .get ("actions" , [])[0 ]
7273 action_id = action .get ("action_id" )
7374 response_url = payload .get ("response_url" )
74-
75+ action_value = action .get ("value" , "temp_id|telegram" )
76+ value_parts = action_value .split ("|" )
77+ draft_id = value_parts [0 ]
78+ platform = value_parts [1 ] if len (value_parts ) > 1 else "telegram"
7579 # --- ГРУПА 1: Дії, що відкривають модалки (response_url НЕ потрібен) ---
7680 if action_id == "action_open_upload_modal" :
7781 modal_view = build_upload_modal ()
@@ -116,7 +120,7 @@ async def slack_interactions(request: Request):
116120 async with httpx .AsyncClient () as client :
117121 if action_id == "action_publish_draft" :
118122 await publish_post_task .kiq (
119- post_id = "temp_id" , platform = "telegram" , content = draft_text
123+ post_id = draft_id , platform = platform , content = draft_text
120124 )
121125 await client .post (
122126 response_url ,
@@ -137,7 +141,10 @@ async def slack_interactions(request: Request):
137141
138142 elif action_id == "action_edit_draft" :
139143 modal_view = build_approval_modal (
140- topic = topic , draft = draft_text , platform = "telegram"
144+ topic = topic ,
145+ draft = draft_text ,
146+ platform = platform ,
147+ draft_id = draft_id ,
141148 )
142149 await client .post (
143150 "https://slack.com/api/views.open" ,
@@ -149,9 +156,10 @@ async def slack_interactions(request: Request):
149156 channel_id = str (payload .get ("channel" , {}).get ("id" , "" ))
150157 await generate_draft_task .kiq ( # type: ignore[call-overload]
151158 topic = topic ,
152- platform = "telegram" ,
159+ platform = platform ,
153160 user_id = user_id ,
154161 channel_id = channel_id ,
162+ draft_id = draft_id ,
155163 )
156164 await client .post (
157165 response_url ,
@@ -191,9 +199,13 @@ async def slack_interactions(request: Request):
191199 platform = platform ,
192200 )
193201
194- # Запускаємо генерацію
202+ new_draft_id = str ( uuid . uuid4 ()) # ГЕНЕРУЄМО УНІКАЛЬНИЙ ID
195203 await generate_draft_task .kiq ( # type: ignore[call-overload]
196- topic = topic , platform = platform , user_id = user_id , channel_id = channel_id
204+ topic = topic ,
205+ platform = platform ,
206+ user_id = user_id ,
207+ channel_id = channel_id ,
208+ draft_id = new_draft_id ,
197209 )
198210
199211 # Відправляємо підтвердження в канал
@@ -232,8 +244,13 @@ async def slack_interactions(request: Request):
232244 logger .info (
233245 "slack_edit_modal_submitted" , user_id = user_id , platform = platform
234246 )
247+ metadata_parts = view .get ("private_metadata" , "" ).split ("|" )
248+ draft_id = (
249+ metadata_parts [1 ] if len (metadata_parts ) > 1 else "temp_id"
250+ ) # ВИТЯГУЄМО З МЕТАДАНИХ
251+
235252 await publish_post_task .kiq (
236- post_id = "temp_id" , platform = platform , content = draft_content
253+ post_id = draft_id , platform = platform , content = draft_content
237254 )
238255
239256 return Response (
0 commit comments