|
|
@@ -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}) |