mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 02:58:59 +08:00
UPDATE: Twilio tool crdential verification (#2741)
This commit is contained in:
parent
b75ff5fa03
commit
c0b82f8e58
@ -1,5 +1,8 @@
|
||||
from typing import Any
|
||||
|
||||
from twilio.base.exceptions import TwilioRestException
|
||||
from twilio.rest import Client
|
||||
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
|
||||
|
||||
@ -7,19 +10,20 @@ from core.tools.provider.builtin_tool_provider import BuiltinToolProviderControl
|
||||
class TwilioProvider(BuiltinToolProviderController):
|
||||
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
|
||||
try:
|
||||
"""
|
||||
SendMessageTool().fork_tool_runtime(
|
||||
meta={
|
||||
"credentials": credentials,
|
||||
}
|
||||
).invoke(
|
||||
user_id="",
|
||||
tool_parameters={
|
||||
"message": "Credential validation message",
|
||||
"to_number": "+14846624384",
|
||||
},
|
||||
)
|
||||
"""
|
||||
pass
|
||||
# Extract credentials
|
||||
account_sid = credentials["account_sid"]
|
||||
auth_token = credentials["auth_token"]
|
||||
from_number = credentials["from_number"]
|
||||
|
||||
# Initialize twilio client
|
||||
client = Client(account_sid, auth_token)
|
||||
|
||||
# fetch account
|
||||
client.api.accounts(account_sid).fetch()
|
||||
|
||||
except TwilioRestException as e:
|
||||
raise ToolProviderCredentialValidationError(f"Twilio API error: {e.msg}") from e
|
||||
except KeyError as e:
|
||||
raise ToolProviderCredentialValidationError(f"Missing required credential: {e}") from e
|
||||
except Exception as e:
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
Loading…
x
Reference in New Issue
Block a user