Merge pull request #1209 from wangcham/feat/wxoa-notice-msg

feat: add support for loading message in wxoa
This commit is contained in:
Junyan Qin (Chin)
2025-03-18 20:39:22 +08:00
committed by GitHub
6 changed files with 37 additions and 3 deletions

View File

@@ -176,7 +176,7 @@ class OAClient():
class OAClientForLongerResponse():
def __init__(self,token:str,EncodingAESKey:str,AppID:str,Appsecret:str):
def __init__(self,token:str,EncodingAESKey:str,AppID:str,Appsecret:str,LoadingMessage:str):
self.token = token
self.aes = EncodingAESKey
self.appid = AppID
@@ -189,6 +189,7 @@ class OAClientForLongerResponse():
"example":[],
}
self.access_token_expiry_time = None
self.loading_message = LoadingMessage
async def handle_callback_request(self):
try:
@@ -246,7 +247,7 @@ class OAClientForLongerResponse():
to_user=from_user,
from_user=to_user,
create_time=int(time.time()),
content="AI正在思考中请发送任意内容获取回答。"
content=self.loading_message
)
if user_msg_queue.get(from_user) and user_msg_queue[from_user][0]["content"]:

View File

@@ -0,0 +1,26 @@
from __future__ import annotations
from .. import migration
@migration.migration_class("wxoa-loading-message", 36)
class WxoaLoadingMessageMigration(migration.Migration):
"""迁移"""
async def need_migrate(self) -> bool:
"""判断当前环境是否需要运行此迁移"""
for adapter in self.ap.platform_cfg.data['platform-adapters']:
if adapter['adapter'] == 'officialaccount':
if 'LoadingMessage' not in adapter:
return True
return False
async def run(self):
"""执行迁移"""
for adapter in self.ap.platform_cfg.data['platform-adapters']:
if adapter['adapter'] == 'officialaccount':
if 'LoadingMessage' not in adapter:
adapter['LoadingMessage'] = 'AI正在思考中请发送任意内容获取回复。'
await self.ap.platform_cfg.dump_config()

View File

@@ -11,7 +11,7 @@ from ..migrations import m015_gitee_ai_config, m016_dify_service_api, m017_dify_
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config, m024_discord_config, m025_gewechat_config
from ..migrations import m026_qqofficial_config, m027_wx_official_account_config, m028_aliyun_requester_config
from ..migrations import m029_dashscope_app_api_config, m030_lark_config_cmpl, m031_dingtalk_config, m032_volcark_config
from ..migrations import m033_dify_thinking_config, m034_gewechat_file_url_config, m035_wxoa_mode
from ..migrations import m033_dify_thinking_config, m034_gewechat_file_url_config, m035_wxoa_mode, m036_wxoa_loading_message
@stage.stage_class("MigrationStage")
class MigrationStage(stage.BootingStage):

View File

@@ -107,6 +107,7 @@ class OfficialAccountAdapter(adapter.MessagePlatformAdapter):
EncodingAESKey=config['EncodingAESKey'],
Appsecret=config['AppSecret'],
AppID=config['AppID'],
LoadingMessage=config['LoadingMessage']
)
else:
raise KeyError("请设置微信公众号通信模式")

View File

@@ -78,6 +78,7 @@
"AppID":"",
"AppSecret":"",
"Mode":"drop",
"LoadingMessage":"AI正在思考中请发送任意内容获取回复。",
"host": "0.0.0.0",
"port": 2287
},

View File

@@ -391,6 +391,11 @@
"description": "对于超过15s的响应的处理模式",
"enum": ["drop", "passive"]
},
"LoadingMessage": {
"type": "string",
"default": "AI正在思考中请发送任意内容获取回复。",
"description": "当使用被动模式时,显示给用户的提示信息"
},
"host": {
"type": "string",
"default": "0.0.0.0",