diff --git a/.env.example b/.env.example index 2c5baa8..6f8ebe9 100644 --- a/.env.example +++ b/.env.example @@ -37,6 +37,17 @@ FEEDBACK_DEFAULT_COLOR=black # FEEDBACK_LIMIT_PER_PROJECT_PER_MINUTE=60 # FEEDBACK_MIN_ELAPSED_MS=2000 +# Mail for every new feedback with a link to it, comma separated. Default info@codebar.ch: +# set your own addresses, or leave it empty for no mail. +# Needs a real mailer (MAIL_MAILER, MAIL_FROM_ADDRESS) and a queue worker unless QUEUE_CONNECTION=sync. +FEEDBACK_NOTIFY_MAIL= + +# Mailer for the notification: log (default, sends nothing), smtp or postmark. +# MAIL_MAILER=postmark +# POSTMARK_TOKEN= +# MAIL_FROM_ADDRESS=feedback@example.com +# MAIL_FROM_NAME="${APP_NAME}" + # Oh Dear application health monitoring (spatie/laravel-health) OH_DEAR_HEALTH_CHECK_ENABLED=true OH_DEAR_HEALTH_CHECK_SECRET= diff --git a/CHANGELOG.md b/CHANGELOG.md index df3cd12..3643b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ All notable changes to the API and the widget are documented here. The format fo - The API returns a read-only share link after sending (`FEEDBACK_SHARE_LINK_MINUTES`, `0` turns it off); the widget shows it on the thank you screen with a copy button, `after_send` receives it as `url`. - Launcher position per project: `feedback:project:create|update --position=bottom-left` (or `bottom-right`), returned by `/v1/projects/{key}/config` as `position` and applied by the widget without a change on the website. `position` in `init()` still wins. - Close button in marking mode (top right, bottom right on phones), same as Esc. +- Mail for every new feedback: `FEEDBACK_NOTIFY_MAIL` (comma separated addresses) gets project, message, sender, page and a team link that is valid for 30 days and can complete the entry. Sent through the queue, reply-to is the sender. Default `info@codebar.ch`, empty sends nothing. +- Postmark mail transport (`MAIL_MAILER=postmark`, `POSTMARK_TOKEN`): new dependencies symfony/postmark-mailer 8.2 and symfony/http-client 8.2. ### Changed diff --git a/README.md b/README.md index e828f26..635cf35 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ - **Diagnostics**: console errors, failed requests, browser, OS, viewport, page size and your own `customData` - **Feedback page per entry**: a signed, expiring link shows every detail and the screenshot, with download and buttons to complete or reopen. No login, no admin panel to run - **Artisan workflow**: list, filter by project, show, export, link, complete and reopen, all with `--json` for scripts -- **Hooks**: widget events in the browser, a Laravel event on the server for Slack, mail or your ticket system +- **Notifications**: a mail with a link for every new feedback, plus widget events in the browser and a Laravel event on the server for Slack or your ticket system - **Activity log**: who completed or reopened what, from the CLI or from a link **For your stack** @@ -343,7 +343,13 @@ Paste the link into a ticket, a chat or an email. The developer opens it, downlo **Share links for the sender** are returned by the API after sending and shown on the thank you screen with a copy button, so the visitor can attach the report to an email or a support ticket. They are always read-only and valid for `FEEDBACK_SHARE_LINK_MINUTES` (default 7 days, `0` turns them off). -**Notifications.** Every stored feedback dispatches `App\Events\FeedbackReceived`. A listener can post a team link to Slack, Teams or your ticket system: +**Notifications.** Every new feedback is mailed to the addresses in `FEEDBACK_NOTIFY_MAIL` (comma separated, default `info@codebar.ch`; set your own, or leave it empty for no mail): project, message, sender, page and an **Open feedback** button. The button is a team link, valid for 30 days, that shows the page above and can mark the feedback as completed; replying to the mail answers the sender. The mail goes through the queue, so it needs a real mailer (`MAIL_MAILER`, `MAIL_FROM_ADDRESS`) and a queue worker (`php artisan queue:work`) unless `QUEUE_CONNECTION=sync`. A notification that fails is reported and never fails the widget's request. + +```dotenv +FEEDBACK_NOTIFY_MAIL=team@example.com,support@example.com +``` + +For Slack, Teams or a ticket system, listen to `App\Events\FeedbackReceived`, which every stored feedback dispatches: ```php use App\Events\FeedbackReceived; @@ -374,6 +380,7 @@ Set in `.env`, see [`config/feedback.php`](config/feedback.php): | `FEEDBACK_LIMIT_PER_PROJECT_PER_MINUTE` | `60` | `0` disables the limit | | `FEEDBACK_MIN_ELAPSED_MS` | `2000` | Faster submissions are dropped silently | | `FEEDBACK_SHARE_LINK_MINUTES` | `10080` | Validity of the share link shown after sending, max. 43200, `0` turns it off | +| `FEEDBACK_NOTIFY_MAIL` | `info@codebar.ch` | Addresses (comma separated) that get a mail with a team link for every new feedback, empty turns it off, see [Notifications](#feedback-pages-and-share-links) | | `APP_URL` | | Public URL of the API, used for links created with `feedback:link` | | `TRUSTED_PROXIES` | | Load balancer or CDN addresses | | `CACHE_STORE` | `file` | Use `database` or `redis` with several instances | diff --git a/app/Listeners/SendFeedbackNotification.php b/app/Listeners/SendFeedbackNotification.php new file mode 100644 index 0000000..d315575 --- /dev/null +++ b/app/Listeners/SendFeedbackNotification.php @@ -0,0 +1,39 @@ + $recipients */ + $recipients = config('feedback.notify.mail'); + + if ($recipients === []) { + return; + } + + try { + $expires = now()->addMinutes(FeedbackLink::MAX_MINUTES); + $link = FeedbackLink::page($event->entry, $expires, manage: true, by: 'Mail'); + + Mail::to($recipients)->queue(new FeedbackReceivedMail($event->entry, $link, $expires->toImmutable())); + } catch (Throwable $e) { + // The feedback is stored; a failing notification must not turn the widget's request into an error. + report($e); + } + } +} diff --git a/app/Mail/FeedbackReceivedMail.php b/app/Mail/FeedbackReceivedMail.php new file mode 100644 index 0000000..1786305 --- /dev/null +++ b/app/Mail/FeedbackReceivedMail.php @@ -0,0 +1,62 @@ +entry->message), 60); + + return new Envelope( + subject: "New feedback for {$this->entry->project->name}: {$excerpt}", + replyTo: $this->senderAddress(), + ); + } + + public function content(): Content + { + return new Content( + view: 'mail.feedback-received', + text: 'mail.feedback-received-text', + with: ['project' => $this->entry->project->name], + ); + } + + /** + * Replying to the mail answers the sender. + * + * @return list
+ */ + private function senderAddress(): array + { + if (filter_var($this->entry->email, FILTER_VALIDATE_EMAIL) === false) { + return []; + } + + return [new Address($this->entry->email, (string) $this->entry->name)]; + } +} diff --git a/composer.json b/composer.json index 2e4df00..a14472e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "matomo/device-detector": "^6.4", "spatie/laravel-activitylog": "^5.0", "spatie/laravel-health": "^1.40", - "spatie/security-advisories-health-check": "^1.3" + "spatie/security-advisories-health-check": "^1.3", + "symfony/http-client": "^8.2", + "symfony/postmark-mailer": "^8.2" }, "require-dev": { "fakerphp/faker": "^1.24", diff --git a/composer.lock b/composer.lock index f8f63b4..8405519 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "4b0b4798f0005b25acc667f4cd5a716f", + "content-hash": "36b5097b098b6e86b5ccf113352a87d5", "packages": [ { "name": "aws/aws-crt-php", @@ -4926,6 +4926,194 @@ "time": "2026-11-27T14:09:33+00:00", "published-time": "2026-11-28T12:12:27+00:00" }, + { + "name": "symfony/http-client", + "version": "v8.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "88dbd3f478bd5ceca3d177e53a428eb80f3f612f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/88dbd3f478bd5ceca3d177e53a428eb80f3f612f", + "reference": "88dbd3f478bd5ceca3d177e53a428eb80f3f612f", + "shasum": "" + }, + "require": { + "php": ">=8.4.1", + "psr/log": "^1|^2|^3", + "symfony/deprecation-contracts": "^2.5|^3.0", + "symfony/http-client-contracts": "^3.7", + "symfony/service-contracts": "^3.8.1" + }, + "conflict": { + "amphp/amp": "<3.0.1", + "php-http/discovery": "<1.15", + "symfony/config": "<8.2", + "symfony/dependency-injection": "<8.2" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "3.0" + }, + "require-dev": { + "amphp/dns": "^2.1.2", + "amphp/http-client": "^5.3.2", + "amphp/http-tunnel": "^2.0", + "amphp/socket": "^2.3.1", + "guzzlehttp/guzzle": "^7.10|^8.0", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/cache": "^7.4|^8.0", + "symfony/clock": "^7.4|^8.0", + "symfony/config": "^8.2", + "symfony/dependency-injection": "^8.2", + "symfony/http-foundation": "^7.4.23|^8.1.11", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/messenger": "^7.4|^8.0", + "symfony/process": "^7.4|^8.0", + "symfony/rate-limiter": "^7.4|^8.0", + "symfony/stopwatch": "^7.4|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "keywords": [ + "http" + ], + "support": { + "source": "https://github.com/symfony/http-client/tree/v8.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-11-28T11:47:39+00:00", + "published-time": "2026-11-28T12:12:56+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v3.8.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "f9f94260f787446c6fd430b2ae1969fe41ae1ba8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/f9f94260f787446c6fd430b2ae1969fe41ae1ba8", + "reference": "f9f94260f787446c6fd430b2ae1969fe41ae1ba8", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, + "branch-alias": { + "dev-main": "3.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/http-client-contracts/tree/v3.8.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-10-04T15:04:25+00:00", + "published-time": "2026-11-04T11:25:37+00:00" + }, { "name": "symfony/http-foundation", "version": "v8.2.0", @@ -6323,6 +6511,78 @@ "time": "2026-08-07T13:08:13+00:00", "published-time": "2026-08-24T11:45:15+00:00" }, + { + "name": "symfony/postmark-mailer", + "version": "v8.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/postmark-mailer.git", + "reference": "a39d815f48e87ee122e27ad5dc8a28b82f3eeaf7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/postmark-mailer/zipball/a39d815f48e87ee122e27ad5dc8a28b82f3eeaf7", + "reference": "a39d815f48e87ee122e27ad5dc8a28b82f3eeaf7", + "shasum": "" + }, + "require": { + "php": ">=8.4.1", + "psr/event-dispatcher": "^1", + "symfony/mailer": "^8.2" + }, + "require-dev": { + "symfony/http-client": "^7.4|^8.0", + "symfony/webhook": "^7.4|^8.0" + }, + "type": "symfony-mailer-bridge", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mailer\\Bridge\\Postmark\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Postmark Mailer Bridge", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/postmark-mailer/tree/v8.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-11-12T10:33:36+00:00", + "published-time": "2026-11-28T12:11:11+00:00" + }, { "name": "symfony/process", "version": "v8.2.0", diff --git a/config/feedback.php b/config/feedback.php index aa2e507..5549528 100644 --- a/config/feedback.php +++ b/config/feedback.php @@ -85,6 +85,22 @@ 'share_link_minutes' => ($minutes = $limit('FEEDBACK_SHARE_LINK_MINUTES', 7 * 24 * 60)) === null ? null : min($minutes, 30 * 24 * 60), + /* + |-------------------------------------------------------------------------- + | Notifications + |-------------------------------------------------------------------------- + | + | Addresses (comma separated) that get a mail for every new feedback, with + | a team link to its page that is valid for 30 days. Unset uses the default, + | empty sends nothing. + | Needs a real mailer (MAIL_MAILER) and a running queue worker. + | + */ + + 'notify' => [ + 'mail' => array_values(array_filter(array_map(trim(...), explode(',', is_string($notify = env('FEEDBACK_NOTIFY_MAIL', 'info@codebar.ch')) ? $notify : '')), static fn (string $address): bool => $address !== '')), + ], + /* |-------------------------------------------------------------------------- | Screenshot limits diff --git a/resources/views/mail/feedback-received-text.blade.php b/resources/views/mail/feedback-received-text.blade.php new file mode 100644 index 0000000..22003e6 --- /dev/null +++ b/resources/views/mail/feedback-received-text.blade.php @@ -0,0 +1,13 @@ +New feedback for {!! $project !!} + +{!! $entry->message !!} + +Open feedback: {!! $link !!} + +From: {!! $entry->name !== null ? $entry->name.', ' : '' !!}{!! $entry->email !!} +Page: {!! $entry->page_url !!} +Sent: {{ $entry->created_at->utc()->format('Y-m-d H:i') }} UTC + +The link shows the screenshot and the technical details and can mark the feedback as completed. +It works without a login until {{ $linkExpiresAt->utc()->format('Y-m-d') }}, so forward it only to people who should see the feedback. +Reply to this mail to answer the sender. diff --git a/resources/views/mail/feedback-received.blade.php b/resources/views/mail/feedback-received.blade.php new file mode 100644 index 0000000..2b646fc --- /dev/null +++ b/resources/views/mail/feedback-received.blade.php @@ -0,0 +1,45 @@ + + + + + +|
+ New feedback for +{{ $project }}+ +{{ $entry->message }} + ++ Open feedback + + +
+ The link shows the screenshot and the technical details and can mark the feedback as completed. + It works without a login until {{ $linkExpiresAt->utc()->format('Y-m-d') }}, so forward it only to people who should see the feedback. + Reply to this mail to answer the sender. + + |
+