Send 6 emails, check flag twice
This commit is contained in:
parent
5c0c013d70
commit
5efe5e56f5
|
@ -392,16 +392,22 @@ export const sendNewAnswerEmail = async (
|
|||
)
|
||||
}
|
||||
|
||||
export const sendThreeContractsEmail = async (
|
||||
export const sendSixContractsEmail = async (
|
||||
privateUser: PrivateUser,
|
||||
contractsToSend: Contract[]
|
||||
) => {
|
||||
const emailType = 'weekly-trending'
|
||||
const unsubscribeUrl = `${UNSUBSCRIBE_ENDPOINT}?id=${privateUser.id}&type=${emailType}`
|
||||
if (!privateUser || !privateUser.email) return
|
||||
if (
|
||||
!privateUser ||
|
||||
!privateUser.email ||
|
||||
privateUser?.unsubscribedFromWeeklyTrendingEmails
|
||||
)
|
||||
return
|
||||
await sendTemplateEmail(
|
||||
privateUser.email,
|
||||
contractsToSend[0].question + ' and 2 more questions for you.',
|
||||
contractsToSend[0].question + ' and 5 more questions for you.',
|
||||
// used to be 3 and I can't change the template name!
|
||||
'3-trending-markets',
|
||||
{
|
||||
question1Title: contractsToSend[0].question,
|
||||
|
@ -416,7 +422,18 @@ export const sendThreeContractsEmail = async (
|
|||
question3Description: getTextDescription(contractsToSend[2]),
|
||||
question3Link: contractUrl(contractsToSend[2]),
|
||||
question3ImgSrc: imageSourceUrl(contractsToSend[2]),
|
||||
|
||||
question4Title: contractsToSend[3].question,
|
||||
question4Description: getTextDescription(contractsToSend[3]),
|
||||
question4Link: contractUrl(contractsToSend[3]),
|
||||
question4ImgSrc: imageSourceUrl(contractsToSend[3]),
|
||||
question5Title: contractsToSend[4].question,
|
||||
question5Description: getTextDescription(contractsToSend[4]),
|
||||
question5Link: contractUrl(contractsToSend[4]),
|
||||
question5ImgSrc: imageSourceUrl(contractsToSend[4]),
|
||||
question6Title: contractsToSend[5].question,
|
||||
question6Description: getTextDescription(contractsToSend[5]),
|
||||
question6Link: contractUrl(contractsToSend[5]),
|
||||
question6ImgSrc: imageSourceUrl(contractsToSend[5]),
|
||||
unsubscribeLink: unsubscribeUrl,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as admin from 'firebase-admin'
|
|||
import { Contract } from '../../common/contract'
|
||||
import { getPrivateUser, getValues, isProd, log } from './utils'
|
||||
import { filterDefined } from '../../common/util/array'
|
||||
import { sendThreeContractsEmail } from './emails'
|
||||
import { sendSixContractsEmail } from './emails'
|
||||
import { createRNG, shuffle } from '../../common/util/random'
|
||||
import { DAY_MS } from '../../common/util/time'
|
||||
|
||||
|
@ -31,6 +31,7 @@ async function getTrendingContracts() {
|
|||
}
|
||||
|
||||
async function sendTrendingMarketsEmailsToAllUsers() {
|
||||
const numEmailsToSend = 6
|
||||
// const privateUsers = await getAllPrivateUsers()
|
||||
// uses dev ian's private user for testing
|
||||
const privateUser = await getPrivateUser(
|
||||
|
@ -50,14 +51,17 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
|||
const contractsAvailableToSend = trendingContracts.filter((contract) => {
|
||||
return !contract.uniqueBettorIds?.includes(privateUser.id)
|
||||
})
|
||||
if (contractsAvailableToSend.length < 3) {
|
||||
if (contractsAvailableToSend.length < numEmailsToSend) {
|
||||
log('not enough new, unbet-on contracts to send to user', privateUser.id)
|
||||
continue
|
||||
}
|
||||
// choose random subset of contracts to send to user
|
||||
const contractsToSend = chooseRandomSubset(contractsAvailableToSend, 3)
|
||||
const contractsToSend = chooseRandomSubset(
|
||||
contractsAvailableToSend,
|
||||
numEmailsToSend
|
||||
)
|
||||
|
||||
await sendThreeContractsEmail(privateUser, contractsToSend)
|
||||
await sendSixContractsEmail(privateUser, contractsToSend)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user