From d2a1206814384911a252ba19d6ebeee1c4705823 Mon Sep 17 00:00:00 2001 From: woni <320753691@qq.com> Date: Wed, 17 Jan 2024 15:58:26 +0800 Subject: [PATCH] app add record --- app/demo.py | 26 ++++++++++++++------------ app/utils.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/app/demo.py b/app/demo.py index c56c47d..c1c1884 100644 --- a/app/demo.py +++ b/app/demo.py @@ -38,30 +38,32 @@ def do_p2_im_message_receive_v1(data: P2ImMessageReceiveV1) -> None: content = data.event.message.content content = json.loads(content) if message_type == "post": - content = content.get("content", []) - - for item in chain.from_iterable(content): + for item in chain.from_iterable(data): if item.get("tag") == "text": message_content += item["text"] - break - elif item.get("tag") == "img": + + if item.get("tag") == "img": images.append(item["image_key"]) - break if message_type == "text": - message_content = content["text"] + message_content = content["text"].replace("@_user_1", "").strip() record["问题概述"] = message_content record["创建人"] = data.event.sender.sender_id.open_id receive_open_id = data.event.sender.sender_id.open_id message_id = data.event.message.message_id user_id = data.event.sender.sender_id.user_id - # add_record(record) - content = {"text": "反馈的问题已经记录到多维表格, 稍后有小伙伴跟进"} + + if images: + record["附件"] = [{"file_token": image} for image in images] + + add_record(record) + + # content = {"text": "反馈的问题已经记录到多维表格, 稍后有小伙伴跟进"} # send_message(receive_id, content) - content = ( - f'{{"text": "反馈的问题已经记录到多维表格, 稍后有小伙伴跟进"}}' - ) + + # 回复群组的消息 + content = f'{{"text": "反馈的问题已经记录到多维表格, 稍后有小伙伴跟进"}}' send_group_message(message_id, content) diff --git a/app/utils.py b/app/utils.py index 21b405d..3298385 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1 +1,32 @@ -import os +from itertools import chain + + +message_content = "" +images = [] +data = [ + [ + { + "height": 756, + "image_key": "img_v3_0277_2c2fbab4-8b13-4a6a-a273-e0d1d47b4ecg", + "tag": "img", + "width": 529, + } + ], + [ + {"style": [], "tag": "text", "text": "11111111"}, + {"style": [], "tag": "at", "user_id": "@_user_1", "user_name": "官方应用指令"}, + {"style": [], "tag": "text", "text": ""}, + ], +] + + +for item in chain.from_iterable(data): + if item.get("tag") == "text": + message_content += item["text"] + + if item.get("tag") == "img": + images.append(item["image_key"]) + + +print(message_content) +print(images)