diff --git a/libs/official_account_api/api.py b/libs/official_account_api/api.py index b777d626..58c9d067 100644 --- a/libs/official_account_api/api.py +++ b/libs/official_account_api/api.py @@ -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"]: diff --git a/pkg/core/migrations/m036_wxoa_loading_message.py b/pkg/core/migrations/m036_wxoa_loading_message.py new file mode 100644 index 00000000..682be435 --- /dev/null +++ b/pkg/core/migrations/m036_wxoa_loading_message.py @@ -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() diff --git a/pkg/core/stages/migrate.py b/pkg/core/stages/migrate.py index 2b09b87e..e528e164 100644 --- a/pkg/core/stages/migrate.py +++ b/pkg/core/stages/migrate.py @@ -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): diff --git a/pkg/platform/sources/officialaccount.py b/pkg/platform/sources/officialaccount.py index 13a53038..518794a6 100644 --- a/pkg/platform/sources/officialaccount.py +++ b/pkg/platform/sources/officialaccount.py @@ -107,6 +107,7 @@ class OfficialAccountAdapter(adapter.MessagePlatformAdapter): EncodingAESKey=config['EncodingAESKey'], Appsecret=config['AppSecret'], AppID=config['AppID'], + LoadingMessage=config['LoadingMessage'] ) else: raise KeyError("请设置微信公众号通信模式") diff --git a/templates/platform.json b/templates/platform.json index da233a53..fe39947c 100644 --- a/templates/platform.json +++ b/templates/platform.json @@ -78,6 +78,7 @@ "AppID":"", "AppSecret":"", "Mode":"drop", + "LoadingMessage":"AI正在思考中,请发送任意内容获取回复。", "host": "0.0.0.0", "port": 2287 }, diff --git a/templates/schema/platform.json b/templates/schema/platform.json index 8ecb20c1..4bc6f111 100644 --- a/templates/schema/platform.json +++ b/templates/schema/platform.json @@ -391,6 +391,11 @@ "description": "对于超过15s的响应的处理模式", "enum": ["drop", "passive"] }, + "LoadingMessage": { + "type": "string", + "default": "AI正在思考中,请发送任意内容获取回复。", + "description": "当使用被动模式时,显示给用户的提示信息" + }, "host": { "type": "string", "default": "0.0.0.0",