Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 |
Expand Down
39 changes: 39 additions & 0 deletions app/Listeners/SendFeedbackNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\FeedbackReceived;
use App\Mail\FeedbackReceivedMail;
use App\Support\FeedbackLink;
use Illuminate\Support\Facades\Mail;
use Throwable;

/**
* Mails the team (FEEDBACK_NOTIFY_MAIL) a link to every new feedback. The
* link is built here, inside the widget's request, so it carries the public
* host; the mail itself goes through the queue.
*/
final readonly class SendFeedbackNotification
{
public function handle(FeedbackReceived $event): void
{
/** @var list<string> $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);
}
}
}
62 changes: 62 additions & 0 deletions app/Mail/FeedbackReceivedMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace App\Mail;

use App\Models\FeedbackEntry;
use Carbon\CarbonImmutable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;

/** Tells the team about a new feedback, with a team link to its page. */
final class FeedbackReceivedMail extends Mailable implements ShouldQueue
{
use Queueable;
use SerializesModels;

public function __construct(
public FeedbackEntry $entry,
public string $link,
public CarbonImmutable $linkExpiresAt,
) {}

public function envelope(): Envelope
{
$excerpt = Str::limit(Str::squish($this->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<Address>
*/
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)];
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading
Loading