forked from mozilla/blurts-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to send email to pre-fxa subscribers
- Loading branch information
1 parent
3ff522f
commit 71bc0bb
Showing
5 changed files
with
63 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use strict"; | ||
|
||
const { negotiateLanguages, acceptedLanguages } = require("fluent-langneg"); | ||
|
||
const AppConstants = require("../app-constants"); | ||
const DB = require("../db/DB"); | ||
const EmailHelpers = require("../template-helpers/emails.js"); | ||
const EmailUtils = require("../email-utils"); | ||
const { LocaleUtils } = require ("../locale-utils"); | ||
|
||
|
||
(async (req) => { | ||
const localeUtils = LocaleUtils.init(); | ||
EmailUtils.init(); | ||
|
||
const subscribers = await DB.getPreFxaSubscribers(); | ||
console.log(`Found ${subscribers.length} pre-FxA subscribers whose email hasn't been added to an FxA subscription.`); | ||
const notifiedSubscribers = []; | ||
const utmID = "pre-fxa"; | ||
for (const subscriber of subscribers) { | ||
const signupLanguage = subscriber.signup_language; | ||
const subscriberEmail = subscriber.primary_email; | ||
const requestedLanguage = signupLanguage ? acceptedLanguages(signupLanguage) : ""; | ||
const supportedLocales = negotiateLanguages( | ||
requestedLanguage, | ||
localeUtils.availableLanguages, | ||
{defaultLocale: "en"} | ||
); | ||
|
||
if (!notifiedSubscribers.includes(subscriberEmail)) { | ||
await EmailUtils.sendEmail( | ||
subscriberEmail, | ||
LocaleUtils.fluentFormat(supportedLocales, "pre-fxa-subject"), // email subject | ||
"default_email", // email template | ||
{ | ||
supportedLocales, | ||
SERVER_URL: AppConstants.SERVER_URL, | ||
unsubscribeUrl: EmailUtils.getUnsubscribeUrl(subscriber, utmID), // need to test the flow for legacy users who want to unsubscribe | ||
ctaHref: EmailHelpers.getPreFxaUtmParams(AppConstants.SERVER_URL, "create-account-button", subscriberEmail), | ||
whichPartial: "email_partials/pre-fxa", | ||
preFxaEmail: true, | ||
email: subscriberEmail, | ||
}, | ||
); | ||
notifiedSubscribers.push(subscriberEmail); | ||
} | ||
} | ||
console.log(`Notified subscribers: ${JSON.stringify(notifiedSubscribers)}`); | ||
})(); |