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

fix: remove service name/type from discord notifier #5181

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

DeJayDev
Copy link
Contributor

@DeJayDev DeJayDev commented Oct 9, 2024

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Description

Fixes #3327, closes #4495.

To do this, I have fully removed the Service Name/Service Type field from the Discord notifier embed. As discussed in the #4495 PR, no other monitor has a distinction between Service Type and Service URL. In alignment with the same comment, I've also moved the fields to their own variable so we are not maintaining two versions of the fields array.

I'd also like to use this PR to discuss reformatting the Discord embed entirely? In my opinion, repeating the service name so close to each other makes the embed look bad. Additionally, we repeat the time of the outage in an embed field and the embed footer.

Type of change

  • Other

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas (including JSDoc for methods)
  • My changes generates no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots

Current (and the issue I aim to fix):
image

Proposed:
image

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have been more clear in my previous comment.
The extraction is what I wanted, but the URL should be added if the value for them exists. This is still a valuable context.

I have left two other comments below.

Not quite sure about ping given that this will only show on up pings..
What do you think about this?

},
{
name: "Error",
value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use this instead

Suggested change
value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"],
value: msg,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that. Looking at #5181 (comment) this looks bad (👀).

The original author had a point..

Let's do the following instead:

Suggested change
value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"],
value: heartbeatJSON["msg"] ?? msg,

server/notification-providers/discord.js Outdated Show resolved Hide resolved
@DeJayDev
Copy link
Contributor Author

DeJayDev commented Oct 10, 2024

I made a mess trying to clean up that conflict. Sort of expected it to apply easier... (and then I force pushed because it was the last thing I ran so I had to do it again :()

I think it makes sense to exclude it if extractAddress returns "" or monitorJSON["hostname"] (ping and steam can both do this). Additionally, I'm not sure if using the msg is a great idea bc it repeats a bunch of information. I think it works better if we change the heading from "Error" to "Message", but still feels sort of :/

image

myredis is redis
Discord is HTTP
localhost is a ping

@CommanderStorm CommanderStorm added area:notifications Everything related to notifications type:enhance-existing feature wants to enhance existing monitor pr:please address review comments this PR needs a bit more work to be mergable labels Oct 10, 2024
@DeJayDev
Copy link
Contributor Author

:)

image

I also added a couple translation keys for this:
image

It's a little cursed, the wayToGetDiscordURL key needs a fullstop on the end for it to flow better but I wasn't sure if I should change it because it's translated already.

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Could basically merged, except for a few nits.

Because we have had problems with this in the past and the codepath is different for that:
Could you post a screenshot of a UP notifcation to ensure that you have tested this? ^^

PSA: force pushing looses the state the reviewer was in => reviewiers cannot review "from the last review" => unless being asked to, merging is almost always better. ^^
The PR will likely be squashed at the end anyway.

Comment on lines +8 to +11
<a
href="https://discord.com/developers/docs/resources/webhook#create-webhook"
target="_blank"
>{{ $t("withADiscordBot") }}</a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be simpler for our translators

Suggested change
<a
href="https://discord.com/developers/docs/resources/webhook#create-webhook"
target="_blank"
>{{ $t("withADiscordBot") }}</a>
<template #webhookWithADiscordBotAPI>
<a
href="https://discord.com/developers/docs/resources/webhook#create-webhook"
target="_blank"
>{{ $t("webhookWithADiscordBotAPI") }}</a>
</template>

await axios.post(webhookUrl.toString(), discordupdata);
return okMsg;
}
} catch (error) {
console.log(error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is not already done so, it should be logged for all and using our log.error facities.
If this is the case, that would be for another PR.

Suggested change
console.log(error);


const baseURL = await Settings.get("primaryBaseURL");
const address = this.extractAddress(monitorJSON);
const hasAddress = address !== "" && address !== monitorJSON.hostname;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why != monitorJSON.hostname?
As far as I can remeber, none of the other monitors do that => lets also not do this, unless there is a reason for this.

If there is no particular reason, please inline hasAddress.
If there is, please add a comment why.

@@ -4,6 +4,12 @@
<input id="discord-webhook-url" v-model="$parent.notification.discordWebhookUrl" type="text" class="form-control" required autocomplete="false">
<div class="form-text">
{{ $t("wayToGetDiscordURL") }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a line break here, to prevent those lines being mushed together (think this adresses It's a little cursed from #5181 (comment))

Suggested change
{{ $t("wayToGetDiscordURL") }}
{{ $t("wayToGetDiscordURL") }}<br>

Comment on lines +544 to +545
"wayToGetDiscordURLEnhanced": "Using the Discord API, you may also create the webhook {0} for button support.",
"withADiscordBot": "with a bot",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This word order reads a bit nicer in my mind. What do you think?

Suggested change
"wayToGetDiscordURLEnhanced": "Using the Discord API, you may also create the webhook {0} for button support.",
"withADiscordBot": "with a bot",
"wayToGetDiscordURLEnhanced": "For button support, you need to create create {webhookWithADiscordBotAPI}.",
"webhookWithADiscordBotAPI": "the webhook with a bot using the Discord API",

},
{
name: "Error",
value: msg,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5181 (comment)

Suggested change
value: msg,
value: heartbeatJSON["msg"] ?? msg,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:notifications Everything related to notifications pr:please address review comments this PR needs a bit more work to be mergable type:enhance-existing feature wants to enhance existing monitor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discord] Service URL should only be included if defined
2 participants