From 185cc6223a2d53de1e2512aa1eac57bb4b9ac254 Mon Sep 17 00:00:00 2001 From: shilapi Date: Wed, 8 May 2024 18:06:12 +0800 Subject: [PATCH 1/3] :ambulance: fix the logic error during sign verifying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复验签时的逻辑错误 --- lark_oapi/card/action_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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") From e41c4b6b73af2607912077d1745a8c41e221512b Mon Sep 17 00:00:00 2001 From: shilapi Date: Wed, 8 May 2024 18:08:51 +0800 Subject: [PATCH 2/3] :clapper: update sample code for card --- README.md | 44 ++++++++++++++++++++++++------------ samples/card/flask_sample.py | 44 ++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 28 deletions(-) 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/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 From 38abd101c3156a132c21eb225feece139c5c36ba Mon Sep 17 00:00:00 2001 From: shilapi Date: Wed, 8 May 2024 19:36:09 +0800 Subject: [PATCH 3/3] :new: Update card model Update card model to v2, while remove the support for v1. --- lark_oapi/card/model.py | 71 +++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 10 deletions(-) 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)