def get_branch(self, branch_name: str, context: typing.Union[str, dict]) -> Branch: branch = self.names[branch_name]() if isinstance(context, str): context = json.loads(context) branch.context = context branch.key = branch_name return branch
def get_payload_json( self, throw_error: bool = False, unpack_failure: typing.Callable[[str], dict] = lambda payload: payload, ) -> typing.Union[dict, None]: try: return json.loads(self.payload) except (json.decoder.JSONDecodeError, TypeError) as e: if throw_error: raise e return unpack_failure(self.payload)
def __init__( self, title: str = None, description: str = None, photo_id: str = None, buttons: typing.List[dict] = None, action: dict = None, ): if not buttons: raise TemplateError("Buttons are required") if not photo_id and not (title or description): raise TemplateError("photo_id or title is required") if isinstance(buttons, str): buttons = json.loads(buttons) if isinstance(buttons, dict): buttons = buttons.get("buttons")[0] # taking only first row self.raw: typing.Dict = { k: v for k, v in locals().items() if v is not None and k != "self" }