Skip to content

Add teacher to MailJet contact list on course assignment#72076

Merged
bethanyaconnor merged 5 commits intostagingfrom
bethany/intro-to-weblab-contact-list
Apr 15, 2026
Merged

Add teacher to MailJet contact list on course assignment#72076
bethanyaconnor merged 5 commits intostagingfrom
bethany/intro-to-weblab-contact-list

Conversation

@bethanyaconnor
Copy link
Copy Markdown
Contributor

@bethanyaconnor bethanyaconnor commented Apr 10, 2026

When a teacher assigns the new HoAI tutorial, Intro to Web Lab, to a section, they are added to a MailJet contact list via an after_save callback on the Section model.

We will use this contact list to automate a follow-up email a week or so after they assign it. Dani will be responsible for setting that up in MailJet.

I tested this locally by setting up a contact list in the development subaccount of MailJet and confirming that assigning a test course (as the real one isn't ready yet) successfully put the user in the contact list. There is a bit more abstraction here than I'd like, so I'll confirm this change when this PR and the tutorial are both live.

bethanyaconnor and others added 4 commits April 10, 2026 14:15
When a teacher assigns hoai-web-design-pilot-v2 to a section, add them
to the corresponding MailJet contact list via an after_save callback on
the Section model. The mapping from UnitGroup name to contact list is
defined in MAILJET_COURSE_ASSIGNMENT_CONTACT_LISTS for easy extension.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- In Section callback, use the existing `unit_group` method instead of
  calling UnitGroup.get_from_cache directly.
- In MailJet.create_contact_and_add_to_course_list, check that the
  contact_list_id exists before creating the contact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bethanyaconnor bethanyaconnor marked this pull request as ready for review April 14, 2026 17:19
Comment thread lib/cdo/mailjet.rb

configure_api_v3

# This will raise an exception if the contact is already on the list
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This exception will propagate back up to the new after_save action on sections, and will then be logged to Honeybadger. Might create some new Honeybadger noise if someone modifies a section to assign a course they were already on the mailing list for (maybe they're teaching that course to two separate sections, or they switch the course assignment from A->B and then back from B->A again).

Also do we want to remove the teacher from the list for course A if they switch their section from A to B?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If a teacher is already in a contact list, nothing will happen here. From the documentation, "If a contact has already been added to your contacts or a list, duplicate entries or subscriptions will NOT be created." (I also tested this.)

Also do we want to remove the teacher from the list for course A if they switch their section from A to B?

I don't think so but that's a question for @dmcavoy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We would still want them on the list because they still likely did the tutorial and would be a good candidate for the email

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this comment about throwing an exception for a contact already on the list is wrong, I guess we should remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh interesting! This is an old comment ... wonder if something changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

jk when I removed the HB handling, I do see the error 🫠 (sorry, I assumed HB code would output to logs in development) I'll fix

Copy link
Copy Markdown
Contributor

@dmcavoy dmcavoy left a comment

Choose a reason for hiding this comment

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

Thanks for setting this up!

Comment thread lib/cdo/mailjet.rb

configure_api_v3

# This will raise an exception if the contact is already on the list
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this comment about throwing an exception for a contact already on the list is wrong, I guess we should remove it.

@dmcavoy
Copy link
Copy Markdown
Contributor

dmcavoy commented Apr 15, 2026

@bethanyaconnor what will the set up of name be? Looks like its sending one "user.name" and not first/last name. Is that right?

Copy link
Copy Markdown
Contributor

@etaderhold etaderhold left a comment

Choose a reason for hiding this comment

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

An API with an error system where you have to inspect the text of the error message to figure out what kind of error it is (and hope they don't change it!) makes me sad, but so be it.

@bethanyaconnor
Copy link
Copy Markdown
Contributor Author

lol I feel you. But I do want other API errors to get surfaced in Honeybadger.

There might be a larger refactor we can do here to avoid this. But I wanted to keep this PR scoped and timely.

@bethanyaconnor
Copy link
Copy Markdown
Contributor Author

what will the set up of name be? Looks like its sending one "user.name" and not first/last name. Is that right?

@dmcavoy that's right. We could probably add first name/last name as a follow-up both here and when teachers sign up. MailJet was set up before we started collecting full names for teachers. I can do that as a follow-up.

@bethanyaconnor bethanyaconnor merged commit 683a814 into staging Apr 15, 2026
8 checks passed
@bethanyaconnor bethanyaconnor deleted the bethany/intro-to-weblab-contact-list branch April 15, 2026 18:13
bethanyaconnor added a commit that referenced this pull request Apr 17, 2026
The course-list contact flow added in #72076 added users to a MailJet
list but did not populate their name fields, so downstream templates
lacked first/given/family/display names. Push those plus sign_up_date
alongside the list membership, mirroring the welcome-series path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

3 participants