1 parent
e3ede40368
commit
effa4168e2
1 file changed
+23
-62
+23
-62
@@ -17,54 +17,8 @@ def process_message_callback(
|
|||||||
app_id, app_secret, bitable_token, table_id, cache_dir, data
|
app_id, app_secret, bitable_token, table_id, cache_dir, data
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
{
|
记录问题到多维表格逻辑
|
||||||
"schema": "2.0",
|
|
||||||
"header": {
|
|
||||||
"event_id": "5a62a955882eb0bef60d8cd92cbd3797",
|
|
||||||
"token": "35LaoAPYTXRyBmjeaBvzRbRUsJSL1KBx",
|
|
||||||
"create_time": "1716882569266",
|
|
||||||
"event_type": "im.message.receive_v1",
|
|
||||||
"tenant_key": "11cf67642edc175f",
|
|
||||||
"app_id": "cli_a5110cd1da70900b"
|
|
||||||
},
|
|
||||||
"event": {
|
|
||||||
"sender": {
|
|
||||||
"sender_id": {
|
|
||||||
"user_id": "7g3756f4",
|
|
||||||
"open_id": "ou_d542891996bf1961f9a94563e6bd4d49",
|
|
||||||
"union_id": "on_d0b974fa569f61a46f99b6aaac856779"
|
|
||||||
},
|
|
||||||
"sender_type": "user",
|
|
||||||
"tenant_key": "11cf67642edc175f"
|
|
||||||
},
|
|
||||||
"message": {
|
|
||||||
"message_id": "om_b9fc436533bd2f9b103fb036926558be",
|
|
||||||
"root_id": "om_eb490fc20824200d204ef8091ea41442",
|
|
||||||
"parent_id": "om_eb490fc20824200d204ef8091ea41442",
|
|
||||||
"create_time": "1716882569049",
|
|
||||||
"update_time": "1716882569049",
|
|
||||||
"chat_id": "oc_078dfeaefc42b43a25c35d3de348c7fc",
|
|
||||||
"thread_id": "omt_1531b4e1939f9740",
|
|
||||||
"chat_type": "group",
|
|
||||||
"message_type": "text",
|
|
||||||
"content": "{\"text\":\"@_user_1 1\"}",
|
|
||||||
"mentions": [
|
|
||||||
{
|
|
||||||
"key": "@_user_1",
|
|
||||||
"id": {
|
|
||||||
"user_id": "",
|
|
||||||
"open_id": "ou_76322e169bb6bb8f6e1c8b6631b54d72",
|
|
||||||
"union_id": "on_fef0f7ff1f1a29a806df7fe0625d40e5"
|
|
||||||
},
|
|
||||||
"name": "官方应用指令",
|
|
||||||
"tenant_key": "11cf67642edc175f"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
# 记录问题到多维表格逻辑
|
|
||||||
|
|
||||||
# 如果 @机器人 等于"记录问题", 获取当前的话题
|
# 如果 @机器人 等于"记录问题", 获取当前的话题
|
||||||
event_message = data.get("event")
|
event_message = data.get("event")
|
||||||
@@ -88,26 +42,33 @@ def process_message_callback(
|
|||||||
lark.logger.info("忽略非@官方应用的消息")
|
lark.logger.info("忽略非@官方应用的消息")
|
||||||
return
|
return
|
||||||
|
|
||||||
message_content = ""
|
if message_type != "text":
|
||||||
|
# 忽略非文本消息
|
||||||
|
lark.logger.info("忽略非文本消息")
|
||||||
|
return
|
||||||
|
|
||||||
|
content = json.loads(message_data.get("content"))
|
||||||
|
content_text = content.get("text")
|
||||||
|
|
||||||
|
if "记录问题" not in content_text:
|
||||||
|
# 忽略非记录问题的消息
|
||||||
|
lark.logger.info("忽略非记录问题的消息")
|
||||||
|
return
|
||||||
|
|
||||||
record = {}
|
record = {}
|
||||||
images = []
|
images = []
|
||||||
images_token = []
|
images_token = []
|
||||||
|
|
||||||
if message_type == "post":
|
# if message_type == "post":
|
||||||
content = content["content"]
|
# content = content["content"]
|
||||||
for item in chain.from_iterable(content):
|
# for item in chain.from_iterable(content):
|
||||||
if item.get("tag") == "text":
|
# if item.get("tag") == "text":
|
||||||
message_content += item["text"]
|
# message_content += item["text"]
|
||||||
|
|
||||||
if item.get("tag") == "img":
|
# if item.get("tag") == "img":
|
||||||
images.append(item["image_key"])
|
# images.append(item["image_key"])
|
||||||
|
|
||||||
if message_type != "text" or message_content != "记录问题":
|
lark.logger.info(f"message_content: {content_text}")
|
||||||
return
|
|
||||||
|
|
||||||
message_content = content["text"].replace("@_user_1", "").strip()
|
|
||||||
|
|
||||||
lark.logger.info(f"message_content: {message_content}")
|
|
||||||
|
|
||||||
# 从话题中提取问题发起人的所有消息和图片, 记录到多维表格中, 记录发消息人 openid 并将处理人设置为@机器人的人
|
# 从话题中提取问题发起人的所有消息和图片, 记录到多维表格中, 记录发消息人 openid 并将处理人设置为@机器人的人
|
||||||
client = (
|
client = (
|
||||||
@@ -118,7 +79,7 @@ def process_message_callback(
|
|||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
|
||||||
record["问题概述"] = message_content
|
record["问题概述"] = content_text
|
||||||
record["创建人"] = [{"id": sender_id}]
|
record["创建人"] = [{"id": sender_id}]
|
||||||
|
|
||||||
# 对 image_key 处理并并上传至多维表格
|
# 对 image_key 处理并并上传至多维表格
|
||||||
|
|||||||
Reference in new issue
Block a user