mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 19:45:58 +08:00
fix: check webhook key of Wecom tool in valid UUID form and fix typo (#2719)
This commit is contained in:
parent
405a00bb2c
commit
0ac250a035
@ -4,9 +4,10 @@ import httpx
|
||||
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.utils.uuid_utils import is_valid_uuid
|
||||
|
||||
|
||||
class WecomRepositoriesTool(BuiltinTool):
|
||||
class WecomGroupBotTool(BuiltinTool):
|
||||
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]
|
||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||
"""
|
||||
@ -17,8 +18,9 @@ class WecomRepositoriesTool(BuiltinTool):
|
||||
return self.create_text_message('Invalid parameter content')
|
||||
|
||||
hook_key = tool_parameters.get('hook_key', '')
|
||||
if not hook_key:
|
||||
return self.create_text_message('Invalid parameter hook_key')
|
||||
if not is_valid_uuid(hook_key):
|
||||
return self.create_text_message(
|
||||
f'Invalid parameter hook_key ${hook_key}, not a valid UUID')
|
||||
|
||||
msgtype = 'text'
|
||||
api_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send'
|
||||
|
@ -1,8 +1,8 @@
|
||||
from core.tools.provider.builtin.wecom.tools.wecom_group_bot import WecomRepositoriesTool
|
||||
from core.tools.provider.builtin.wecom.tools.wecom_group_bot import WecomGroupBotTool
|
||||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
|
||||
|
||||
|
||||
class WecomProvider(BuiltinToolProviderController):
|
||||
def _validate_credentials(self, credentials: dict) -> None:
|
||||
WecomRepositoriesTool()
|
||||
WecomGroupBotTool()
|
||||
pass
|
||||
|
9
api/core/tools/utils/uuid_utils.py
Normal file
9
api/core/tools/utils/uuid_utils.py
Normal file
@ -0,0 +1,9 @@
|
||||
import uuid
|
||||
|
||||
|
||||
def is_valid_uuid(uuid_str: str) -> bool:
|
||||
try:
|
||||
uuid.UUID(uuid_str)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
Loading…
x
Reference in New Issue
Block a user