Skip to content
Open
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
21 changes: 19 additions & 2 deletions custom_components/webhook_service/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ basic_webhook:
required: false
selector:
text:

discord_webhook:
name: Discord Webhook
description: Service Provider to use Discord Webhooks
Expand All @@ -39,7 +39,24 @@ discord_webhook:
required: true
selector:
text:
type:
user_name:
name: Username
description: The name for the webhook user
required: false
selector:
template:
avatar_url:
name: Profile Picture URL
description: The URL of bot user PFP
required: false
selector:
template:
content:
name: Message Content
description: Content of the message sent
required: false
selector:
template:
title:
name: Title
description: The title of the embed
Expand Down
14 changes: 13 additions & 1 deletion custom_components/webhook_service/webhook_functions/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def run(
timestamp = data.get("timestamp")
footer = data.get("footer")
webhook_url = data.get("webhook")

username = data.get("user_name")
avatar_url = data.get("avatar_url")
content = data.get("content")

if not webhook_url:
_LOGGER.error("No webhook URL provided.")
return
Expand Down Expand Up @@ -58,7 +63,14 @@ def run(
output_data["thumbnail"] = {"url": f"attachment://{image_name}"}

embed_data = {"embeds": [output_data]}


if username:
embed_data["username"] = username
if content:
embed_data["content"] = content
if avatar_url:
embed_data["avatar_url"] = avatar_url

if not files:
result = requests.post(webhook_url, json=embed_data)
else:
Expand Down