Description
The send_message method in lark_client.py may not correctly handle different receive_id types (chat_id vs open_id vs user_id).
Problem
In lark_client.py lines 119-139:
async def send_message(
self,
chat_id: str,
message: str,
message_type: str = "text"
) -> Dict[str, Any]:
"""Send a message to a chat or user."""
content = {"text": message} if message_type == "text" else {"content": message}
data = {
"receive_id": chat_id,
"msg_type": message_type,
"content": json.dumps(content)
}
return await self._make_request(
"POST",
"/im/v1/messages",
data=data,
params={"receive_id_type": "chat_id"} # Always hardcoded as chat_id
)
Issues:
-
The receive_id_type is hardcoded to "chat_id", but the receive_id from webhook events might be:
chat_id (group chats)
open_id (1-on-1 chats with users)
-
For 1-on-1 bot chats, the correct receive_id_type might need to be "open_id" or the method needs to auto-detect the type.
Impact
When users send messages in 1-on-1 chats, the bot may fail to respond because it's using the wrong receive_id_type.
Solution
async def send_message(
self,
receive_id: str,
message: str,
message_type: str = "text",
receive_id_type: str = "chat_id" # Allow caller to specify
) -> Dict[str, Any]:
"""Send a message to a chat or user."""
content = {"text": message} if message_type == "text" else {"content": message}
data = {
"receive_id": receive_id,
"msg_type": message_type,
"content": json.dumps(content)
}
return await self._make_request(
"POST",
"/im/v1/messages",
data=data,
params={"receive_id_type": receive_id_type}
)
Or auto-detect based on ID prefix patterns:
oc_* → chat_id
ou_* → open_id
on_* → union_id
Priority
MEDIUM - May cause message delivery failures in certain chat types
Description
The
send_messagemethod inlark_client.pymay not correctly handle different receive_id types (chat_id vs open_id vs user_id).Problem
In
lark_client.pylines 119-139:Issues:
The
receive_id_typeis hardcoded to"chat_id", but thereceive_idfrom webhook events might be:chat_id(group chats)open_id(1-on-1 chats with users)For 1-on-1 bot chats, the correct
receive_id_typemight need to be"open_id"or the method needs to auto-detect the type.Impact
When users send messages in 1-on-1 chats, the bot may fail to respond because it's using the wrong receive_id_type.
Solution
Or auto-detect based on ID prefix patterns:
oc_*→ chat_idou_*→ open_idon_*→ union_idPriority
MEDIUM - May cause message delivery failures in certain chat types