Skip to content

Commit

Permalink
feat: #137, #161 ask mid and end -trial feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Sep 16, 2024
1 parent a461ecc commit c2f0482
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Listeners;

use App\Notifications\TrialEndsSoonNotification;
use App\Notifications\AskFinalTrialFeedback;
use App\Notifications\AskMidTrialFeedback;
use Carbon\CarbonInterval;
use Illuminate\Auth\Events\Verified;
use Illuminate\Events\Dispatcher;

class ScheduleTrialEndNotifications
class StartTrialFeedbackFlow
{
/**
* Create the event listener.
Expand Down Expand Up @@ -39,10 +40,10 @@ public function scheduleNotifications(Verified $event): void
return;
}

$days3 = $team->trialEndsAt()->sub(CarbonInterval::days(3))->diffAsDateInterval(now(), absolute: true);
$team->notify((new TrialEndsSoonNotification($team))->delay($days3));
$days7 = $team->trialEndsAt()->sub(CarbonInterval::days(7))->diffAsDateInterval(now(), absolute: true);
$team->notify((new AskMidTrialFeedback($team))->delay($days7));

$days1 = $team->trialEndsAt()->sub(CarbonInterval::day())->diffAsDateInterval(now(), absolute: true);
$team->notify((new TrialEndsSoonNotification($team))->delay($days1));
$team->notify((new AskFinalTrialFeedback($team))->delay($days1));
}
}
1 change: 0 additions & 1 deletion app/Models/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ public function asNodeTasks(): array
'payload' => [
'caddy' => $caddy,
],

];
}

Expand Down
56 changes: 56 additions & 0 deletions app/Notifications/AskFinalTrialFeedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Notifications;

use App\Models\Team;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class AskFinalTrialFeedback extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(
protected Team $team
) {
$this->afterCommit();
}

public function shouldSend(object $notifiable, string $channel): bool
{
return $this->team->onTrial();
}

public function via(object $notifiable): array
{
return ['mail'];
}

public function toMail(object $notifiable): MailMessage
{
$trialEndsAt = $this->team->trialEndsAt();
$dateDiff = $trialEndsAt->longRelativeToNowDiffForHumans();

return (new MailMessage)
->subject("Your Ptah.sh trial ends soon - We'd love your final feedback")
->greeting("Hello {$this->team->owner->name}!")
->line("Your Ptah.sh trial for team {$this->team->name} is ending soon.")
->line("You will not be able to use Ptah.sh after {$trialEndsAt->toDateTimeString()} ({$dateDiff}).")
->line('Before your trial ends, we\'d greatly appreciate your final thoughts.')
->line('Your feedback is crucial in helping us improve Ptah.sh for you and future users.')
->line('Please reply to this email with your experience and any suggestions you might have.')
->line('Thank you for trying Ptah.sh. We hope you\'ve found it valuable!')
->line('If you\'re interested in continuing with Ptah.sh, please visit our pricing page to choose a plan that suits your needs.')
->action('Choose a Plan', route('teams.billing.show', $this->team))
->line('If you have any questions or need assistance, don\'t hesitate to reach out at '.config('app.email').'.');
}

public function toArray(object $notifiable): array
{
return [
//
];
}
}
77 changes: 77 additions & 0 deletions app/Notifications/AskMidTrialFeedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Notifications;

use App\Models\Team;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class AskMidTrialFeedback extends Notification implements ShouldQueue
{
use Queueable;

/**
* Create a new notification instance.
*/
public function __construct(
protected Team $team
) {
$this->afterCommit();
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail'];
}

/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$nodeCount = $this->team->nodes()->count();
$serviceCount = $this->team->services()->count();

$message = (new MailMessage)
->subject('We\'d love your feedback on Ptah.sh')
->greeting("Hello {$this->team->owner->name}!")
->line('We hope you\'re enjoying your experience with Ptah.sh so far.')
->line('We\'d love to hear your thoughts and improve our service based on your feedback.')
->line('Simply reply to this email with your feedback - we\'re eager to hear from you!');

if ($nodeCount === 0) {
$message->line('We noticed you don\'t have any active nodes at the moment. We\'d love to know if there\'s anything holding you back or if you need any assistance getting started or restarting with nodes.');
} elseif ($serviceCount === 1) {
$message->line('We see you haven\'t created any custom services yet. How has your experience been so far? Is there anything we can do to make it easier for you to create and manage services?');
} elseif ($serviceCount === 2) {
$message->line('We see you\'ve created your first custom service. How was your experience? Is there anything we can do to make it easier for you to manage or create more services?');
} else {
$message->line('It looks like you\'re actively using Ptah.sh with multiple custom services. We\'d love to hear about your experience and any suggestions you might have for improvements.');
}

return $message
->line('Your feedback is invaluable to us and will help shape the future of Ptah.sh.')
->line('Also, we invite you to join our Discord community to connect with other users and our team.')
->action('Join Our Discord', 'https://r.ptah.sh/chat')
->line('Thank you for being a part of Ptah.sh!');
}

/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
}
67 changes: 0 additions & 67 deletions app/Notifications/TrialEndsSoonNotification.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Providers;

use App\Listeners\ScheduleTrialEndNotifications;
use App\Listeners\StartTrialFeedbackFlow;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Lorisleiva\Actions\Facades\Actions;
Expand All @@ -22,6 +22,6 @@ public function register(): void
*/
public function boot(): void
{
Event::subscribe(ScheduleTrialEndNotifications::class);
Event::subscribe(StartTrialFeedbackFlow::class);
}
}

0 comments on commit c2f0482

Please sign in to comment.