mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-06-04 11:14:10 +08:00
feat: Add custom username and avatar define in discord tool (#9514)
This commit is contained in:
parent
660fc3bb34
commit
95ce10f23b
@ -21,7 +21,6 @@ class DiscordWebhookTool(BuiltinTool):
|
|||||||
return self.create_text_message("Invalid parameter content")
|
return self.create_text_message("Invalid parameter content")
|
||||||
|
|
||||||
webhook_url = tool_parameters.get("webhook_url", "")
|
webhook_url = tool_parameters.get("webhook_url", "")
|
||||||
|
|
||||||
if not webhook_url.startswith("https://discord.com/api/webhooks/"):
|
if not webhook_url.startswith("https://discord.com/api/webhooks/"):
|
||||||
return self.create_text_message(
|
return self.create_text_message(
|
||||||
f"Invalid parameter webhook_url ${webhook_url}, \
|
f"Invalid parameter webhook_url ${webhook_url}, \
|
||||||
@ -31,13 +30,14 @@ class DiscordWebhookTool(BuiltinTool):
|
|||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
params = {}
|
|
||||||
payload = {
|
payload = {
|
||||||
|
"username": tool_parameters.get("username") or user_id,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
"avatar_url": tool_parameters.get("avatar_url") or None,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = httpx.post(webhook_url, headers=headers, params=params, json=payload)
|
res = httpx.post(webhook_url, headers=headers, json=payload)
|
||||||
if res.is_success:
|
if res.is_success:
|
||||||
return self.create_text_message("Text message was sent successfully")
|
return self.create_text_message("Text message was sent successfully")
|
||||||
else:
|
else:
|
||||||
|
@ -38,3 +38,28 @@ parameters:
|
|||||||
pt_BR: Content to sent to the channel or person.
|
pt_BR: Content to sent to the channel or person.
|
||||||
llm_description: Content of the message
|
llm_description: Content of the message
|
||||||
form: llm
|
form: llm
|
||||||
|
- name: username
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
label:
|
||||||
|
en_US: Discord Webhook Username
|
||||||
|
zh_Hans: Discord Webhook用户名
|
||||||
|
pt_BR: Discord Webhook Username
|
||||||
|
human_description:
|
||||||
|
en_US: Discord Webhook Username
|
||||||
|
zh_Hans: Discord Webhook用户名
|
||||||
|
pt_BR: Discord Webhook Username
|
||||||
|
llm_description: Discord Webhook Username
|
||||||
|
form: llm
|
||||||
|
- name: avatar_url
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
label:
|
||||||
|
en_US: Discord Webhook Avatar
|
||||||
|
zh_Hans: Discord Webhook头像
|
||||||
|
pt_BR: Discord Webhook Avatar
|
||||||
|
human_description:
|
||||||
|
en_US: Discord Webhook Avatar URL
|
||||||
|
zh_Hans: Discord Webhook头像地址
|
||||||
|
pt_BR: Discord Webhook Avatar URL
|
||||||
|
form: form
|
||||||
|
Loading…
x
Reference in New Issue
Block a user