From 4bade3ba608a0a0a6aa92c356e49aeab3cecf0e3 Mon Sep 17 00:00:00 2001 From: Vincent Riva Date: Wed, 31 Jul 2024 20:31:06 +0200 Subject: [PATCH] Add URL on Discord notification content (#398) * Add URL on Discord notification content * Add an option to show or not the URL on Discord notification * Cleanup config and url formatting --------- Co-authored-by: charlocharlie --- src/common/config/classes.ts | 14 +++++++++++++- src/notifiers/discord.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/common/config/classes.ts b/src/common/config/classes.ts index 644f18e..6ea238d 100644 --- a/src/common/config/classes.ts +++ b/src/common/config/classes.ts @@ -134,6 +134,16 @@ export class DiscordConfig extends NotifierConfig { @IsString({ each: true }) mentionedRoles: string[]; + /** + * If true, the Discord message will contain the full URL in the message text. Helpful if you need to copy-paste the URL. + * @example true + * @default false + * @env DISCORD_SHOW_URL + */ + @IsBoolean() + @IsOptional() + showUrl = false; + /** * @ignore */ @@ -1024,12 +1034,14 @@ export class AppConfig { } // Use environment variables to fill discord notification config if present - const { DISCORD_WEBHOOK, DISCORD_MENTIONED_USERS, DISCORD_MENTIONED_ROLES } = process.env; + const { DISCORD_WEBHOOK, DISCORD_MENTIONED_USERS, DISCORD_MENTIONED_ROLES, DISCORD_SHOW_URL } = + process.env; if (DISCORD_WEBHOOK) { const discord = new DiscordConfig(); discord.webhookUrl = DISCORD_WEBHOOK; if (DISCORD_MENTIONED_USERS) discord.mentionedUsers = DISCORD_MENTIONED_USERS.split(','); if (DISCORD_MENTIONED_ROLES) discord.mentionedRoles = DISCORD_MENTIONED_ROLES.split(','); + discord.showUrl = DISCORD_SHOW_URL === 'true'; if (!this.notifiers) { this.notifiers = []; } diff --git a/src/notifiers/discord.ts b/src/notifiers/discord.ts index b02cb23..d21b267 100644 --- a/src/notifiers/discord.ts +++ b/src/notifiers/discord.ts @@ -28,7 +28,7 @@ export class DiscordNotifier extends NotifierService { await axios.post( this.config.webhookUrl, { - content: `${mentions}epicgames-freegames-node needs an action performed.`, + content: `${mentions}epicgames-freegames-node needs an action performed. ${this.config.showUrl && url ? `\n${url}` : ''}`, embeds: [ { fields: [