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

[9.x] Fix empty string in backup.notifications.discord.username to fail sending a notification #1821

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

RVxLab
Copy link
Contributor

@RVxLab RVxLab commented Jul 14, 2024

Fixes #1815

This PR fixes an issue caused by using an empty string for the Discord Webhook username property.

According to Discord's documentation, the username field is optional and when set, requires it to be between 1 and 80 characters long. This lines up with the name field when creating a webhook.

The current implementation of the notification doesn't follow that. If the backup.notifications.discord.username is an empty string (which is currently the default), the notification is never sent due to a validation error. See the mentioned issue above for details.

This PR fixes these issues by only setting the username set in the config if it's not empty.

To test this, I created a server and added a webhook with the name Test McWebhook:

image

I applied the fix to a project locally and ran it with 3 usernames in order:

  • 'Laravel Backup'
  • ''
  • 'Some Other Custom Name'

image

As a final change, I removed the ?? 'Laravel Backup' expression when setting the username. Since $username is non-nullable, that expression is never run.

@freekmurze freekmurze merged commit 9f116d4 into spatie:main Jul 15, 2024
1 check passed
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discord Webhook not working if username is an empty string
2 participants