This commit is contained in:
1 parent
799099ff1c
commit
af3ff10ead
2 files changed
+96
-24
No files matched your search
+20
@@ -11,6 +11,9 @@ from lark_oapi.api.im.v1 import *
|
||||
from lark_oapi.api.bitable.v1 import *
|
||||
|
||||
|
||||
from .utils import get_message_resource, upload_media
|
||||
|
||||
|
||||
load_dotenv()
|
||||
|
||||
app_id = os.environ["APP_ID"]
|
||||
@@ -22,8 +25,16 @@ verification_token = os.environ["VERIFICATION_TOKEN"]
|
||||
bitable_token = os.environ["BITABLE_TOKEN"]
|
||||
table_id = os.environ["TABLE_ID"]
|
||||
|
||||
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
# 创建client
|
||||
client = lark.Client.builder().app_id(app_id).app_secret(app_secret).build()
|
||||
cache_dir = os.path.join(current_dir, "cache")
|
||||
|
||||
if not os.path.exists(cache_dir):
|
||||
os.makedirs(cache_dir)
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -58,6 +69,15 @@ def do_p2_im_message_receive_v1(data: P2ImMessageReceiveV1) -> None:
|
||||
if images:
|
||||
record["附件"] = [{"file_token": image} for image in images]
|
||||
|
||||
# 对 image_key 处理并并上传至多维表格
|
||||
images_path = []
|
||||
for image in images:
|
||||
image_path = get_message_resource(client, message_id, image, "image", cache_dir)
|
||||
print("下载文件成功:", image)
|
||||
images_path.append(image_path)
|
||||
file_token = upload_media(client, image_path, "bitable_file", bitable_token)
|
||||
print("上传文件成功:", file_token)
|
||||
|
||||
add_record(record)
|
||||
|
||||
# content = {"text": "反馈的问题已经记录到多维表格, 稍后有小伙伴跟进"}
|
||||
|
||||
Reference in new issue
Block a user