Use Markdown in discord notifications (#1743)

* Add league/html-to-markdown

* Convert HTML to Markdown in NewsAdded notification

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
This commit is contained in:
Arthur Parienté 2024-01-23 23:44:20 +01:00 committed by GitHub
parent 799850e12f
commit af80e76365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 97 additions and 4 deletions

View File

@ -6,6 +6,7 @@ use App\Contracts\Notification;
use App\Models\News;
use App\Notifications\Channels\Discord\DiscordMessage;
use Illuminate\Contracts\Queue\ShouldQueue;
use League\HTMLToMarkdown\HtmlConverter;
class NewsAdded extends Notification implements ShouldQueue
{
@ -31,6 +32,8 @@ class NewsAdded extends Notification implements ShouldQueue
public function toDiscordChannel($news): ?DiscordMessage
{
$dm = new DiscordMessage();
$markdown = (new HtmlConverter(['header_style' => 'atx']))->convert($news->body);
return $dm->webhook(setting('notifications.discord_public_webhook_url'))
->success()
->title('News: '.$news->subject)
@ -39,7 +42,7 @@ class NewsAdded extends Notification implements ShouldQueue
'url' => '',
'icon_url' => $news->user->resolveAvatarUrl(),
])
->description($news->body);
->description($markdown);
}
/**

View File

@ -85,7 +85,8 @@
"spatie/laravel-backup": "*",
"laravel/socialite": "^5.11",
"socialiteproviders/discord": "^4.2",
"symfony/postmark-mailer": "^6.0"
"symfony/postmark-mailer": "^6.0",
"league/html-to-markdown": "^5.1"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8.1",

93
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b4044ac9103746eae3b32bd6a15560ed",
"content-hash": "dfdeb674b83929dc487d333bb5856a2d",
"packages": [
{
"name": "akaunting/laravel-money",
@ -4597,6 +4597,95 @@
},
"time": "2022-10-26T19:43:53+00:00"
},
{
"name": "league/html-to-markdown",
"version": "5.1.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/html-to-markdown.git",
"reference": "0b4066eede55c48f38bcee4fb8f0aa85654390fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/0b4066eede55c48f38bcee4fb8f0aa85654390fd",
"reference": "0b4066eede55c48f38bcee4fb8f0aa85654390fd",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xml": "*",
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"mikehaertl/php-shellcommand": "^1.1.0",
"phpstan/phpstan": "^1.8.8",
"phpunit/phpunit": "^8.5 || ^9.2",
"scrutinizer/ocular": "^1.6",
"unleashedtech/php-coding-standard": "^2.7 || ^3.0",
"vimeo/psalm": "^4.22 || ^5.0"
},
"bin": [
"bin/html-to-markdown"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.2-dev"
}
},
"autoload": {
"psr-4": {
"League\\HTMLToMarkdown\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Colin O'Dell",
"email": "colinodell@gmail.com",
"homepage": "https://www.colinodell.com",
"role": "Lead Developer"
},
{
"name": "Nick Cernis",
"email": "nick@cern.is",
"homepage": "http://modernnerd.net",
"role": "Original Author"
}
],
"description": "An HTML-to-markdown conversion helper for PHP",
"homepage": "https://github.com/thephpleague/html-to-markdown",
"keywords": [
"html",
"markdown"
],
"support": {
"issues": "https://github.com/thephpleague/html-to-markdown/issues",
"source": "https://github.com/thephpleague/html-to-markdown/tree/5.1.1"
},
"funding": [
{
"url": "https://www.colinodell.com/sponsor",
"type": "custom"
},
{
"url": "https://www.paypal.me/colinpodell/10.00",
"type": "custom"
},
{
"url": "https://github.com/colinodell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/league/html-to-markdown",
"type": "tidelift"
}
],
"time": "2023-07-12T21:21:09+00:00"
},
{
"name": "league/iso3166",
"version": "4.2.1",
@ -14498,5 +14587,5 @@
"ext-zip": "*"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}