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,
|
privateUser: PrivateUser,
|
||||||
contractsToSend: Contract[]
|
contractsToSend: Contract[]
|
||||||
) => {
|
) => {
|
||||||
const emailType = 'weekly-trending'
|
const emailType = 'weekly-trending'
|
||||||
const unsubscribeUrl = `${UNSUBSCRIBE_ENDPOINT}?id=${privateUser.id}&type=${emailType}`
|
const unsubscribeUrl = `${UNSUBSCRIBE_ENDPOINT}?id=${privateUser.id}&type=${emailType}`
|
||||||
if (!privateUser || !privateUser.email) return
|
if (
|
||||||
|
!privateUser ||
|
||||||
|
!privateUser.email ||
|
||||||
|
privateUser?.unsubscribedFromWeeklyTrendingEmails
|
||||||
|
)
|
||||||
|
return
|
||||||
await sendTemplateEmail(
|
await sendTemplateEmail(
|
||||||
privateUser.email,
|
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',
|
'3-trending-markets',
|
||||||
{
|
{
|
||||||
question1Title: contractsToSend[0].question,
|
question1Title: contractsToSend[0].question,
|
||||||
|
@ -416,7 +422,18 @@ export const sendThreeContractsEmail = async (
|
||||||
question3Description: getTextDescription(contractsToSend[2]),
|
question3Description: getTextDescription(contractsToSend[2]),
|
||||||
question3Link: contractUrl(contractsToSend[2]),
|
question3Link: contractUrl(contractsToSend[2]),
|
||||||
question3ImgSrc: imageSourceUrl(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,
|
unsubscribeLink: unsubscribeUrl,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as admin from 'firebase-admin'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { getPrivateUser, getValues, isProd, log } from './utils'
|
import { getPrivateUser, getValues, isProd, log } from './utils'
|
||||||
import { filterDefined } from '../../common/util/array'
|
import { filterDefined } from '../../common/util/array'
|
||||||
import { sendThreeContractsEmail } from './emails'
|
import { sendSixContractsEmail } from './emails'
|
||||||
import { createRNG, shuffle } from '../../common/util/random'
|
import { createRNG, shuffle } from '../../common/util/random'
|
||||||
import { DAY_MS } from '../../common/util/time'
|
import { DAY_MS } from '../../common/util/time'
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ async function getTrendingContracts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendTrendingMarketsEmailsToAllUsers() {
|
async function sendTrendingMarketsEmailsToAllUsers() {
|
||||||
|
const numEmailsToSend = 6
|
||||||
// const privateUsers = await getAllPrivateUsers()
|
// const privateUsers = await getAllPrivateUsers()
|
||||||
// uses dev ian's private user for testing
|
// uses dev ian's private user for testing
|
||||||
const privateUser = await getPrivateUser(
|
const privateUser = await getPrivateUser(
|
||||||
|
@ -50,14 +51,17 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
||||||
const contractsAvailableToSend = trendingContracts.filter((contract) => {
|
const contractsAvailableToSend = trendingContracts.filter((contract) => {
|
||||||
return !contract.uniqueBettorIds?.includes(privateUser.id)
|
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)
|
log('not enough new, unbet-on contracts to send to user', privateUser.id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// choose random subset of contracts to send to user
|
// 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