H Vs pirms 2 mēnešiem
vecāks
revīzija
dec0f82419
1 mainītis faili ar 23 papildinājumiem un 1 dzēšanām
  1. +23
    -1
      resources/config_reources.py

+ 23
- 1
resources/config_reources.py Parādīt failu

@@ -1,7 +1,11 @@
from flask_restful import Resource, reqparse from flask_restful import Resource, reqparse
from pydantic import BaseModel, ValidationError
from flask import jsonify,request,json from flask import jsonify,request,json
from common import redis_helper,utils from common import redis_helper,utils
from wechat import gewe_chat 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) config=self.wxchat.get_wxchat_config_from_cache(wxid)
return jsonify(config) return jsonify(config)

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


class SaveWxchatConfigResource(Resource): class SaveWxchatConfigResource(Resource):
def __init__(self): def __init__(self):
@@ -29,5 +39,17 @@ class SaveWxchatConfigResource(Resource):
data = req.get("data") data = req.get("data")
# hash_key="__AI_OPS_WX__:WXCHAT_CONFIG" # hash_key="__AI_OPS_WX__:WXCHAT_CONFIG"
# redis_helper.redis_helper.update_hash_field(hash_key, wxid, json.dumps(data,ensure_ascii=False)) # 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) self.wxchat.save_wxchat_config(wxid, data)
return jsonify({'wxid': wxid, 'config': data}) return jsonify({'wxid': wxid, 'config': data})

Notiek ielāde…
Atcelt
Saglabāt