@@ -179,7 +179,18 @@ def action(
179179 asyncio : bool = False ,
180180) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
181181 if isinstance (constraints , (str , Pattern )):
182- return block_action (constraints , asyncio )
182+
183+ def func (body : Dict [str , Any ]) -> bool :
184+ return (
185+ _block_action (constraints , body )
186+ or _attachment_action (constraints , body )
187+ or _dialog_submission (constraints , body )
188+ or _dialog_cancellation (constraints , body )
189+ or _workflow_step_edit (constraints , body )
190+ )
191+
192+ return build_listener_matcher (func , asyncio )
193+
183194 elif "type" in constraints :
184195 action_type = constraints ["type" ]
185196 if action_type == "block_actions" :
@@ -206,66 +217,89 @@ def action(
206217 )
207218
208219
220+ def _block_action (
221+ constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
222+ body : Dict [str , Any ],
223+ ) -> bool :
224+ if is_block_actions (body ) is False :
225+ return False
226+
227+ action = to_action (body )
228+ if isinstance (constraints , (str , Pattern )):
229+ action_id = constraints
230+ return _matches (action_id , action ["action_id" ])
231+ elif isinstance (constraints , dict ):
232+ # block_id matching is optional
233+ block_id : Optional [Union [str , Pattern ]] = constraints .get ("block_id" )
234+ block_id_matched = block_id is None or _matches (
235+ block_id , action .get ("block_id" )
236+ )
237+ action_id_matched = _matches (constraints ["action_id" ], action ["action_id" ])
238+ return block_id_matched and action_id_matched
239+
240+
209241def block_action (
210242 constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
211243 asyncio : bool = False ,
212244) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
213245 def func (body : Dict [str , Any ]) -> bool :
214- if is_block_actions (body ) is False :
215- return False
216-
217- action = to_action (body )
218- if isinstance (constraints , (str , Pattern )):
219- action_id = constraints
220- return _matches (action_id , action ["action_id" ])
221- elif isinstance (constraints , dict ):
222- # block_id matching is optional
223- block_id : Optional [Union [str , Pattern ]] = constraints .get ("block_id" )
224- block_id_matched = block_id is None or _matches (
225- block_id , action .get ("block_id" )
226- )
227- action_id_matched = _matches (constraints ["action_id" ], action ["action_id" ])
228- return block_id_matched and action_id_matched
246+ return _block_action (constraints , body )
229247
230248 return build_listener_matcher (func , asyncio )
231249
232250
251+ def _attachment_action (callback_id : Union [str , Pattern ], body : Dict [str , Any ],) -> bool :
252+ return is_attachment_action (body ) and _matches (callback_id , body ["callback_id" ])
253+
254+
233255def attachment_action (
234256 callback_id : Union [str , Pattern ], asyncio : bool = False ,
235257) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
236258 def func (body : Dict [str , Any ]) -> bool :
237- return is_attachment_action ( body ) and _matches ( callback_id , body [ "callback_id" ] )
259+ return _attachment_action ( callback_id , body )
238260
239261 return build_listener_matcher (func , asyncio )
240262
241263
264+ def _dialog_submission (callback_id : Union [str , Pattern ], body : Dict [str , Any ],) -> bool :
265+ return is_dialog_submission (body ) and _matches (callback_id , body ["callback_id" ])
266+
267+
242268def dialog_submission (
243269 callback_id : Union [str , Pattern ], asyncio : bool = False ,
244270) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
245271 def func (body : Dict [str , Any ]) -> bool :
246- return is_dialog_submission ( body ) and _matches ( callback_id , body [ "callback_id" ] )
272+ return _dialog_submission ( callback_id , body )
247273
248274 return build_listener_matcher (func , asyncio )
249275
250276
277+ def _dialog_cancellation (
278+ callback_id : Union [str , Pattern ], body : Dict [str , Any ],
279+ ) -> bool :
280+ return is_dialog_cancellation (body ) and _matches (callback_id , body ["callback_id" ])
281+
282+
251283def dialog_cancellation (
252284 callback_id : Union [str , Pattern ], asyncio : bool = False ,
253285) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
254286 def func (body : Dict [str , Any ]) -> bool :
255- return is_dialog_cancellation (body ) and _matches (
256- callback_id , body ["callback_id" ]
257- )
287+ return _dialog_cancellation (callback_id , body )
258288
259289 return build_listener_matcher (func , asyncio )
260290
261291
292+ def _workflow_step_edit (
293+ callback_id : Union [str , Pattern ], body : Dict [str , Any ],
294+ ) -> bool :
295+ return is_workflow_step_edit (body ) and _matches (callback_id , body ["callback_id" ])
296+
297+
262298def workflow_step_edit (
263299 callback_id : Union [str , Pattern ], asyncio : bool = False ,
264300) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
265301 def func (body : Dict [str , Any ]) -> bool :
266- return is_workflow_step_edit (body ) and _matches (
267- callback_id , body ["callback_id" ]
268- )
302+ return _workflow_step_edit (callback_id , body )
269303
270304 return build_listener_matcher (func , asyncio )
271305
@@ -322,7 +356,14 @@ def options(
322356 asyncio : bool = False ,
323357) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
324358 if isinstance (constraints , (str , Pattern )):
325- return block_suggestion (constraints , asyncio )
359+
360+ def func (body : Dict [str , Any ]) -> bool :
361+ return _block_suggestion (constraints , body ) or _dialog_suggestion (
362+ constraints , body
363+ )
364+
365+ return build_listener_matcher (func , asyncio )
366+
326367 if "action_id" in constraints :
327368 return block_suggestion (constraints ["action_id" ], asyncio )
328369 if "callback_id" in constraints :
@@ -333,20 +374,28 @@ def options(
333374 )
334375
335376
377+ def _block_suggestion (action_id : Union [str , Pattern ], body : Dict [str , Any ],) -> bool :
378+ return is_block_suggestion (body ) and _matches (action_id , body ["action_id" ])
379+
380+
336381def block_suggestion (
337382 action_id : Union [str , Pattern ], asyncio : bool = False ,
338383) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
339384 def func (body : Dict [str , Any ]) -> bool :
340- return is_block_suggestion ( body ) and _matches ( action_id , body [ "action_id" ] )
385+ return _block_suggestion ( action_id , body )
341386
342387 return build_listener_matcher (func , asyncio )
343388
344389
390+ def _dialog_suggestion (callback_id : Union [str , Pattern ], body : Dict [str , Any ],) -> bool :
391+ return is_dialog_suggestion (body ) and _matches (callback_id , body ["callback_id" ])
392+
393+
345394def dialog_suggestion (
346395 callback_id : Union [str , Pattern ], asyncio : bool = False ,
347396) -> Union [ListenerMatcher , "AsyncListenerMatcher" ]:
348397 def func (body : Dict [str , Any ]) -> bool :
349- return is_dialog_suggestion ( body ) and _matches ( callback_id , body [ "callback_id" ] )
398+ return _dialog_suggestion ( callback_id , body )
350399
351400 return build_listener_matcher (func , asyncio )
352401
0 commit comments