def func(body: Dict[str, Any]) -> bool: if is_event(body): event = body["event"] if not _matches(constraints["type"], event["type"]): return False if "subtype" in constraints: expected_subtype: Union[str, Sequence[Optional[Union[ str, Pattern]]]] = constraints["subtype"] if expected_subtype is None: # "subtype" in constraints is intentionally None for this pattern return "subtype" not in event elif isinstance(expected_subtype, (str, Pattern)): return "subtype" in event and _matches( expected_subtype, event["subtype"]) elif isinstance(expected_subtype, Sequence): subtypes: Sequence[Optional[Union[ str, Pattern]]] = expected_subtype for expected in subtypes: actual: Optional[str] = event.get("subtype") if expected is None: if actual is None: return True elif actual is not None and _matches( expected, actual): return True return False else: return "subtype" in event and _matches( expected_subtype, event["subtype"]) return True return False
def func(body: Dict[str, Any]) -> bool: return ( is_event(body) and _matches("workflow_step_execute", body["event"]["type"]) and "workflow_step" in body["event"] and _matches(callback_id, body["event"]["callback_id"]) )
def func(body: Dict[str, Any]) -> bool: if is_event(body): event = body["event"] if not _matches(constraints["type"], event["type"]): return False if "subtype" in constraints: expected_subtype = constraints["subtype"] if expected_subtype is None: # "subtype" in constraints is intentionally None for this pattern return "subtype" not in event else: return "subtype" in event and _matches( expected_subtype, event["subtype"]) return True return False
def warning_unhandled_request( # type: ignore req: Union[BoltRequest, "AsyncBoltRequest"], # type: ignore ) -> str: # type: ignore filtered_body = _build_filtered_body(req.body) default_message = f"Unhandled request ({filtered_body})" if (is_workflow_step_edit(req.body) or is_workflow_step_save(req.body) or is_workflow_step_execute(req.body)): # @app.step callback_id = ( filtered_body.get("callback_id") or filtered_body.get("view", {}).get("callback_id") # type: ignore or "your-callback-id") return _build_unhandled_request_suggestion( default_message, f""" from slack_bolt.workflows.step import WorkflowStep ws = WorkflowStep( callback_id="{callback_id}", edit=edit, save=save, execute=execute, ) # Pass Step to set up listeners app.step(ws) """, ) if is_action(req.body): # @app.action action_id_or_callback_id = req.body.get("callback_id") if req.body.get("type") == "block_actions": action_id_or_callback_id = req.body.get("actions")[0].get( "action_id") return _build_unhandled_request_suggestion( default_message, f""" @app.action("{action_id_or_callback_id}") def handle_some_action(ack, body, logger): ack() logger.info(body) """, ) if is_options(req.body): # @app.options constraints = '"action-id"' if req.body.get("action_id") is not None: constraints = '"' + req.body.get("action_id") + '"' elif req.body.get("type") == "dialog_suggestion": constraints = f"""{{"type": "dialog_suggestion", "callback_id": "{req.body.get('callback_id')}"}}""" return _build_unhandled_request_suggestion( default_message, f""" @app.options({constraints}) def handle_some_options(ack): ack(options=[ ... ]) """, ) if is_shortcut(req.body): # @app.shortcut id = req.body.get("action_id") or req.body.get("callback_id") return _build_unhandled_request_suggestion( default_message, f""" @app.shortcut("{id}") def handle_shortcuts(ack, body, logger): ack() logger.info(body) """, ) if is_view(req.body): # @app.view return _build_unhandled_request_suggestion( default_message, f""" @app.view("{req.body.get('view', {}).get('callback_id', 'modal-view-id')}") def handle_view_events(ack, body, logger): ack() logger.info(body) """, ) if is_event(req.body): # @app.event event_type = req.body.get("event", {}).get("type") return _build_unhandled_request_suggestion( default_message, f""" @app.event("{event_type}") def handle_{event_type}_events(body, logger): logger.info(body) """, ) if is_slash_command(req.body): # @app.command command = req.body.get("command", "/your-command") return _build_unhandled_request_suggestion( default_message, f""" @app.command("{command}") def handle_some_command(ack, body, logger): ack() logger.info(body) """, ) return default_message
def func(body: Dict[str, Any]) -> bool: return is_event(body) and _matches(event_type, body["event"]["type"])