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

[Feature] Ad hoc email command #12325

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

[Feature] Ad hoc email command #12325

wants to merge 8 commits into from

Conversation

petertgiles
Copy link
Contributor

@petertgiles petertgiles commented Dec 17, 2024

🤖 Resolves #11542

👋 Introduction

Adds an Artisan command and Laravel notification for sending ad hoc emails with just the first name and last name.

🕵️ Details

The command will select users to notify by one of three criteria:

  • specific email addresses
  • specific notification families
  • all users

🧪 Testing

  1. Update your api/.env file with the "team" api key
  2. Rerun ./artisan optimize:clear
  3. Start a queue worker
  4. Update one user to have your GCNotify registered email address
  5. Test various forms of the Artisan command
  • Can use email criteria
    ./artisan send-notifications:ad-hoc-email cdaa82f1-7f76-4d9e-a82e-328c41a6ab62 0831e036-8dfb-4f5e-8b31-867b2c526d77 --emailAddress=email1@example.org --emailAddress=email2@example.org
  • Can use notification family criteria
    ./artisan send-notifications:ad-hoc-email cdaa82f1-7f76-4d9e-a82e-328c41a6ab62 0831e036-8dfb-4f5e-8b31-867b2c526d77 --notificationFamily=JOB_ALERT --notificationFamily=APPLICATION_UPDATE
  • Can use notify all criteria (OR logic)
    ./artisan send-notifications:ad-hoc-email cdaa82f1-7f76-4d9e-a82e-328c41a6ab62 0831e036-8dfb-4f5e-8b31-867b2c526d77 --notifyAllUsers
  • Respects language preferences
  • Can not use 0 or 2 or 3 criteria types
  • Warns of missing email addresses
  • Errors on invalid notification families
  • first and last name passed to GC Notify

📸 Screenshot

image

@brindasasi brindasasi self-requested a review December 18, 2024 15:58
Copy link
Contributor

@brindasasi brindasasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good so far. Will verify in dev

return $builder;
}

private function builderFromNotifictionFamilies(array $notificationFamilies): Builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor typo - builderFromNotificationFamilies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

($notifyAllUsers ? 1 : 0);

if ($optionTypesCount != 1) {
throw new \Error('Must filter users using exactly one of the option types');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can simply use InvalidArgumentException .. but your choice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - that's more descriptive.
switch to InvalidArgumentException

$userCount = $users->count();

if ($this->confirm('Do you wish to send notifications to '.$userCount.' users?')) {
$progressBar = $this->output->createProgressBar($userCount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oo.. progressbar!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying out some of the new Laravel 11 features. 😉

@brindasasi
Copy link
Contributor

Sorry for delaying on this what I noticed so far

  • If I gave wrong template ID but valid email addresses , it gives me success message even though email doesn't get sent out
  • separtating the email id params indivdiaully like. this are not very practical when we have to send bulk emails.
    --emailAddress=email1@example.org --emailAddress=email2@example.org
    It would be better to have an array with comma separated

testing few more things

Copy link
Contributor

@brindasasi brindasasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, when the template is mistakenly given it is failing silently
image

when there is multiple critieras given , I got different exception rather than the invalidargument .. but I'm not too worried about this .. as long as it breaks we know
But if the above one is fixed , would be great.
image

Also if we can have comma separated emails for bulk email would be great.
Other than that this looks awesome!

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.

✨ Improved laravel Command for sending arbitrary email notifications
2 participants