dgtlmoon / changedetection.io

The best and simplest free open source web page change detection, website watcher, restock monitor and notification service. Restock Monitor, change detection. Designed for simplicity - Simply monitor which websites had a text change for free. Free Open source web page change detection, Website defacement monitoring, Price change notification
https://changedetection.io
Apache License 2.0
19.27k stars 1.05k forks source link

[feature] Add an option to send embed messages to Discord webhooks #907

Open XXCoreRangerX opened 2 years ago

XXCoreRangerX commented 2 years ago

Version and OS 0.39.18 on linux/docker

Is your feature request related to a problem? Please describe. My monitored URL's {diff} often exceeds the 1700 characters limit. Using embeds could increase the limit up to 4096 characters by using the description field for diffs.

Describe the solution you'd like Add an embed message type for Discord notifications with a customizable structure consisting of embedded fields. I'm pretty sure Apprise, the dependency used for notifications, already has support for embeds, so adding it here shouldn't be much of an issue.

Describe the use-case and give concrete real-world examples The limit of diffs would be increased from 1700 to 4096 characters. Additionally, embedded Discord notifications would simply look better than pure text.

dgtlmoon commented 2 years ago

Thanks for that info!

Also looking interesting is the 'attachment object' too

Repooc commented 2 years ago

please please, i would love it if you were to add this functionality as that is prob the only thing keeping me from using this as I would like.

dhanadhan commented 1 year ago

I would love to have the embed option as well. Currently, the web url is embedded when sent through Discord webhook and it looks pretty ugly lol. There is no way to post a plain web link though webhook. If the Embed Message feature described in this post is added, it would solve this issue as well.

Thanks

jpdsc commented 1 year ago

You can use the apprise embeded option by adding ?format=markdown. Example: discord://webhook_id/webhook_token?format=markdown

Doing, apprise will embed the message. image

You can also add additional parameters: https://github.com/caronc/apprise/wiki/Notify_discord#parameter-breakdown

I checked footer, avatar_url and these are working. However, the footer cannot be changed and shows changedetection.io information.

dhanadhan commented 1 year ago

You can use the apprise embeded option by adding ?format=markdown. Example: discord://webhook_id/webhook_token?format=markdown

Doing, apprise will embed the message. image

You can also add additional parameters: https://github.com/caronc/apprise/wiki/Notify_discord#parameter-breakdown

I checked footer, avatar_url and these are working. However, the footer cannot be changed and shows changedetection.io information.

Awesome, that worked. Thank you.

Do you know how to get rid of that "changedetection.io" link on every embed?

jpdsc commented 1 year ago

That is the author field, not sure how apprise embeds this one as there is no reference to it in the apprise documentation.

Same for footer text and footer image.

naviem commented 1 year ago

Anyone ever figure out how to remove the author field? I don't like it showing it. Trying to keep the notification simple and clean as possible

dhanadhan commented 1 year ago

Anyone ever figure out how to remove the author field? I don't like it showing it. Trying to keep the notification simple and clean as possible

Nope, still can't figure out a way to remove author. It does look annoying so I don't use embed anymore. I wish dev can add it eventually 🤞

BlackWolfWoof commented 3 months ago

@XXCoreRangerX Hehe hello, 2 years later you have your answer :) It is still not natively supported BUUUT... posts://discord.com/api/webhooks/IDHERE/TOKENHERE?+Content-Type=application/json

{% set title = watch_title if watch_title else "N/A" %}
{% set title = title | replace("\n", "") %}
{% set restock_info = restock if restock else {} %}

{% set description = "" %}
{% if restock_info %}
{% set description = "**In Stock:** " ~ restock.in_stock ~ "\\n" %}
{% set description = description ~ "**Price:** " ~ restock_info.price ~ " " ~ restock_info.currency ~ "\\n" %}
{% set description = description ~ "**Original Price:** " ~ restock_info.original_price ~ " " ~ restock_info.currency ~ "\\n" %}
{% endif %}
{% set diffContent = diff | replace("\n", "\\n") %}

{
    "username": "Changedetection.io",
    "avatar_url": "https://cdn.discordapp.com/avatars/1269225949942124594/7cd30e60dd046655c0f02071c70122d2.webp",
    "embeds": [
        {
            "title": "{{ title }}",
            "url": "{{ watch_url }}",
            "color": 4372701,
            "description": "{% if description %}{{ description }}{% else %}{% endif %}**Difference:** [Link]({{diff_url}})\n{{diffContent}}"
        }
    ]
}

as example. Note: use a service like https://webhook.site/ to see what info gets sent and make sure newlines are escaped and you don't forget a , in the json like i did which added an additional 3h of troubleshooting 💀💀 1920-1078-max

dhanadhan commented 1 month ago

@BlackWolfWoof Thank you sir! That worked great 👍

dreww commented 1 month ago

@BlackWolfWoof thanks!! was wondering if you have any advice - I can't get the webhook to show up successfully straight from changedetector.io (hosted), but if I copy and paste the json out of webhook.site and send it via postman, it works just fine. is there any way to easily tell why a discord webhook attempt is failing?

dhanadhan commented 1 month ago

@BlackWolfWoof thanks!! was wondering if you have any advice - I can't get the webhook to show up successfully straight from changedetector.io (hosted), but if I copy and paste the json out of webhook.site and send it via postman, it works just fine. is there any way to easily tell why a discord webhook attempt is failing?

There is no easy way to tell why it's failing. I removed some stuff from the JSON code and made sure I am using the mentioned post discord webhook with text output format.

{ "username": "Change", "avatar_url": "https://cdn.discordapp.com/avatars/1269225949942124594/7cd30e60dd046655c0f02071c70122d2.webp", "embeds": [ { "title": "**{{watch_title}}**", "url": "{{watch_url}}", "color": 2895667, "description": "{{current_snapshot}}" } ] }

dreww commented 1 month ago

i had a typo in the url... carry on. 😭

Reginald-Gillespie commented 1 month ago

A file upload as I suggested here https://github.com/dgtlmoon/changedetection.io/issues/2723 would be simpler than embeds, allow direct formatting, and increase the limit to theoretically >10 million chars (upload max is 10MB, right?).