소스 검색

调整

develop
H Vs 2 달 전
부모
커밋
dec0f82419
1개의 변경된 파일23개의 추가작업 그리고 1개의 파일을 삭제
  1. +23
    -1
      resources/config_reources.py

+ 23
- 1
resources/config_reources.py 파일 보기

@@ -1,7 +1,11 @@
from flask_restful import Resource, reqparse
from pydantic import BaseModel, ValidationError
from flask import jsonify,request,json
from common import redis_helper,utils
from wechat import gewe_chat
from dataclasses import dataclass, asdict
from typing import List
import json



@@ -16,7 +20,13 @@ class GetWxchatConfigResource(Resource):
config=self.wxchat.get_wxchat_config_from_cache(wxid)
return jsonify(config)

@dataclass
class AgentConfig(BaseModel):
chatroomIdWhiteList: List[str] = []
agentTokenId: str
agentEnabled: bool
addContactsFromChatroomIdWhiteList: List[str] = []
chatWaitingMsgEnabled: bool

class SaveWxchatConfigResource(Resource):
def __init__(self):
@@ -29,5 +39,17 @@ class SaveWxchatConfigResource(Resource):
data = req.get("data")
# hash_key="__AI_OPS_WX__:WXCHAT_CONFIG"
# redis_helper.redis_helper.update_hash_field(hash_key, wxid, json.dumps(data,ensure_ascii=False))


try:
# 使用 Pydantic 严格校验数据类型和结构
validated_config = AgentConfig.model_validate(data)
except ValidationError as e:

response=jsonify({'code': 407, 'message': e.errors().__str__()})
response.status_code = 407
return response


self.wxchat.save_wxchat_config(wxid, data)
return jsonify({'wxid': wxid, 'config': data})

Loading…
취소
저장