Add teacher to MailJet contact list on course assignment#72076
Add teacher to MailJet contact list on course assignment#72076bethanyaconnor merged 5 commits intostagingfrom
Conversation
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>
…aging contact lists
|
|
||
| configure_api_v3 | ||
|
|
||
| # This will raise an exception if the contact is already on the list |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
We would still want them on the list because they still likely did the tutorial and would be a good candidate for the email
There was a problem hiding this comment.
If this comment about throwing an exception for a contact already on the list is wrong, I guess we should remove it.
There was a problem hiding this comment.
oh interesting! This is an old comment ... wonder if something changed.
There was a problem hiding this comment.
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
dmcavoy
left a comment
There was a problem hiding this comment.
Thanks for setting this up!
|
|
||
| configure_api_v3 | ||
|
|
||
| # This will raise an exception if the contact is already on the list |
There was a problem hiding this comment.
If this comment about throwing an exception for a contact already on the list is wrong, I guess we should remove it.
|
@bethanyaconnor what will the set up of name be? Looks like its sending one "user.name" and not first/last name. Is that right? |
etaderhold
left a comment
There was a problem hiding this comment.
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.
|
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. |
@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. |
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>
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.