Skip to content

Commit

Permalink
Add URL on Discord notification content (#398)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Treast and claabs authored Jul 31, 2024
1 parent 27bd527 commit 4bade3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/common/config/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 = [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 4bade3b

Please sign in to comment.