diff --git a/README.md b/README.md index 8aad3da43..7b5ac5f0a 100644 --- a/README.md +++ b/README.md @@ -320,22 +320,38 @@ app = Flask(__name__) def do_interactive_card(data: lark.Card) -> Any: print(lark.JSON.marshal(data)) content = { - "header": { - "title": { - "tag": "plain_text", - "content": "更新卡片成功" - }, - "template": "green" + "toast":{ + "type":"info", + "content":"卡片交互成功", + "i18n":{ + "zh_cn":"卡片交互成功", + "en_us":"card action success" + } }, - "elements": [ - { - "tag": "div", - "text": { - "tag": "lark_md", - "content": "**Success!\n成功啦😄**" + "card":{ + "type":"raw", + "data":{ + "config":{ + "enable_forward":True + }, + "elements":[ + { + "tag":"div", + "text":{ + "content":"This is the plain text", + "tag":"plain_text" + } + } + ], + "header":{ + "template":"blue", + "title":{ + "content":"This is the title", + "tag":"plain_text" + } } - }, - ] + } + } } return content diff --git a/lark_oapi/card/action_handler.py b/lark_oapi/card/action_handler.py index 460f87587..930f02443 100644 --- a/lark_oapi/card/action_handler.py +++ b/lark_oapi/card/action_handler.py @@ -100,8 +100,8 @@ def _verify_sign(self, request: RawRequest) -> None: timestamp = request.headers.get(LARK_REQUEST_TIMESTAMP) nonce = request.headers.get(LARK_REQUEST_NONCE) signature = request.headers.get(LARK_REQUEST_SIGNATURE) - bs = (timestamp + nonce + self._verification_token).encode(UTF_8) + request.body - h = hashlib.sha1(bs) + bs = (timestamp + nonce + self._encrypt_key).encode(UTF_8) + request.body + h = hashlib.sha256(bs) if signature != h.hexdigest(): raise AccessDeniedException("signature verification failed") diff --git a/lark_oapi/card/model.py b/lark_oapi/card/model.py index b937a000f..0e7ed2531 100644 --- a/lark_oapi/card/model.py +++ b/lark_oapi/card/model.py @@ -4,31 +4,82 @@ from lark_oapi.core.model import RawRequest -class Action(object): +class EventOperator(object): + _types = {} + + def __init__(self, d=None) -> None: + self.tenant_key: Optional[str] = None + self.user_id: Optional[str] = None + self.open_id: Optional[str] = None + init(self, d, self._types) + + +class EventAction(object): _types = {} def __init__(self, d=None) -> None: self.value: Dict[str, Any] = {} - self.tag: Optional[str] = None - self.option: Optional[str] = None + self.form_value: Dict[str, Any] = {} self.timezone: Optional[str] = None + self.name: Optional[str] = None + self.tag: Optional[str] = None + self.option: Dict[str, Any] = {} + init(self, d, self._types) + + +class EventContext(object): + _types = {} + + def __init__(self, d=None) -> None: + self.url: Optional[str] = None + self.preview_token: Optional[str] = None + self.open_message_id: Optional[str] = None + self.open_chat_id: Optional[str] = None + init(self, d, self._types) + + +class Header(object): + _types = {} + + def __init__(self, d=None) -> None: + self.event_id: Optional[str] = None + self.token: Optional[str] = None + self.create_time: Optional[str] = None + self.event_type: Optional[str] = None + self.tenant_key: Optional[str] = None + self.app_id: Optional[str] = None + init(self, d, self._types) + + +class Event(object): + _types = { + "operator": EventOperator, + "action": EventAction, + "context": EventContext + } + + def __init__(self, d=None) -> None: + self.operator: Optional[EventOperator] = None + self.token: Optional[str] = None + self.action: Optional[EventAction] = None + self.host: Optional[str] = None + self.delivery_type: Optional[str] = None + self.context: Optional[EventContext] = None init(self, d, self._types) class Card(object): _types = { - "action": Action + "header": Header, + "event": Event } def __init__(self, d=None) -> None: - self.open_id: Optional[str] = None - self.user_id: Optional[str] = None - self.tenant_key: Optional[str] = None - self.open_message_id: Optional[str] = None - self.open_chat_id: Optional[str] = None + self.schema: Optional[str] = None + self.header: Optional[Header] = None + self.event: Optional[Event] = None self.token: Optional[str] = None self.challenge: Optional[str] = None self.type: Optional[str] = None - self.action: Optional[Action] = None self.raw: Optional[RawRequest] = None init(self, d, self._types) diff --git a/samples/card/flask_sample.py b/samples/card/flask_sample.py index 2266486d8..6a56d5a31 100644 --- a/samples/card/flask_sample.py +++ b/samples/card/flask_sample.py @@ -11,22 +11,38 @@ def do_interactive_card(data: lark.Card) -> Any: print(lark.JSON.marshal(data)) content = { - "header": { - "title": { - "tag": "plain_text", - "content": "更新卡片成功" - }, - "template": "green" + "toast":{ + "type":"info", + "content":"卡片交互成功", + "i18n":{ + "zh_cn":"卡片交互成功", + "en_us":"card action success" + } }, - "elements": [ - { - "tag": "div", - "text": { - "tag": "lark_md", - "content": "**Success!\n成功啦😄**" + "card":{ + "type":"raw", + "data":{ + "config":{ + "enable_forward":True + }, + "elements":[ + { + "tag":"div", + "text":{ + "content":"This is the plain text", + "tag":"plain_text" + } + } + ], + "header":{ + "template":"blue", + "title":{ + "content":"This is the title", + "tag":"plain_text" + } } - }, - ] + } + } } return content