Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add custom username and avatar define in discord tool #9514

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def _invoke(
return self.create_text_message("Invalid parameter content")

webhook_url = tool_parameters.get("webhook_url", "")

if not webhook_url.startswith("https://discord.com/api/webhooks/"):
return self.create_text_message(
f"Invalid parameter webhook_url ${webhook_url}, \
Expand All @@ -31,13 +30,14 @@ def _invoke(
headers = {
"Content-Type": "application/json",
}
params = {}
payload = {
"username": tool_parameters.get("username") or user_id,
"content": content,
"avatar_url": tool_parameters.get("avatar_url") or None,
}

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:
return self.create_text_message("Text message was sent successfully")
else:
Expand Down
25 changes: 25 additions & 0 deletions api/core/tools/provider/builtin/discord/tools/discord_webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,28 @@ parameters:
pt_BR: Content to sent to the channel or person.
llm_description: Content of the message
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