don't use mailgun scheduling
This commit is contained in:
parent
67efb2a7ac
commit
9b40e71b55
|
@ -45,6 +45,7 @@ export const STARTING_BALANCE = ENV_CONFIG.startingBalance ?? 1000
|
||||||
// for sus users, i.e. multiple sign ups for same person
|
// for sus users, i.e. multiple sign ups for same person
|
||||||
export const SUS_STARTING_BALANCE = ENV_CONFIG.startingBalance ?? 10
|
export const SUS_STARTING_BALANCE = ENV_CONFIG.startingBalance ?? 10
|
||||||
export const REFERRAL_AMOUNT = 500
|
export const REFERRAL_AMOUNT = 500
|
||||||
|
|
||||||
export type PrivateUser = {
|
export type PrivateUser = {
|
||||||
id: string // same as User.id
|
id: string // same as User.id
|
||||||
username: string // denormalized from User
|
username: string // denormalized from User
|
||||||
|
@ -54,6 +55,7 @@ export type PrivateUser = {
|
||||||
unsubscribedFromCommentEmails?: boolean
|
unsubscribedFromCommentEmails?: boolean
|
||||||
unsubscribedFromAnswerEmails?: boolean
|
unsubscribedFromAnswerEmails?: boolean
|
||||||
unsubscribedFromGenericEmails?: boolean
|
unsubscribedFromGenericEmails?: boolean
|
||||||
|
manaBonusEmailSent?: boolean
|
||||||
initialDeviceToken?: string
|
initialDeviceToken?: string
|
||||||
initialIpAddress?: string
|
initialIpAddress?: string
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
import { uniq } from 'lodash'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MANIFOLD_AVATAR_URL,
|
MANIFOLD_AVATAR_URL,
|
||||||
MANIFOLD_USERNAME,
|
MANIFOLD_USERNAME,
|
||||||
|
@ -14,7 +16,7 @@ import {
|
||||||
cleanDisplayName,
|
cleanDisplayName,
|
||||||
cleanUsername,
|
cleanUsername,
|
||||||
} from '../../common/util/clean-username'
|
} from '../../common/util/clean-username'
|
||||||
import { sendOneWeekBonusEmail, sendWelcomeEmail } from './emails'
|
import { sendWelcomeEmail } from './emails'
|
||||||
import { isWhitelisted } from '../../common/envs/constants'
|
import { isWhitelisted } from '../../common/envs/constants'
|
||||||
import {
|
import {
|
||||||
CATEGORIES_GROUP_SLUG_POSTFIX,
|
CATEGORIES_GROUP_SLUG_POSTFIX,
|
||||||
|
@ -24,7 +26,6 @@ import {
|
||||||
import { track } from './analytics'
|
import { track } from './analytics'
|
||||||
import { APIError, newEndpoint, validate } from './api'
|
import { APIError, newEndpoint, validate } from './api'
|
||||||
import { Group, NEW_USER_GROUP_SLUGS } from '../../common/group'
|
import { Group, NEW_USER_GROUP_SLUGS } from '../../common/group'
|
||||||
import { uniq } from 'lodash'
|
|
||||||
import {
|
import {
|
||||||
DEV_HOUSE_LIQUIDITY_PROVIDER_ID,
|
DEV_HOUSE_LIQUIDITY_PROVIDER_ID,
|
||||||
HOUSE_LIQUIDITY_PROVIDER_ID,
|
HOUSE_LIQUIDITY_PROVIDER_ID,
|
||||||
|
@ -97,7 +98,6 @@ export const createuser = newEndpoint(opts, async (req, auth) => {
|
||||||
|
|
||||||
await addUserToDefaultGroups(user)
|
await addUserToDefaultGroups(user)
|
||||||
await sendWelcomeEmail(user, privateUser)
|
await sendWelcomeEmail(user, privateUser)
|
||||||
await sendOneWeekBonusEmail(user, privateUser)
|
|
||||||
await track(auth.uid, 'create user', { username }, { ip: req.ip })
|
await track(auth.uid, 'create user', { username }, { ip: req.ip })
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import * as dayjs from 'dayjs'
|
|
||||||
|
|
||||||
import { DOMAIN } from '../../common/envs/constants'
|
import { DOMAIN } from '../../common/envs/constants'
|
||||||
import { Answer } from '../../common/answer'
|
import { Answer } from '../../common/answer'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
|
@ -184,11 +182,9 @@ export const sendOneWeekBonusEmail = async (
|
||||||
const emailType = 'generic'
|
const emailType = 'generic'
|
||||||
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
||||||
|
|
||||||
const oneWeek = dayjs().add(1, 'week').toString()
|
|
||||||
|
|
||||||
await sendTemplateEmail(
|
await sendTemplateEmail(
|
||||||
privateUser.email,
|
privateUser.email,
|
||||||
'Manifold one week anniversary gift',
|
'Manifold Markets one week anniversary gift',
|
||||||
'one-week',
|
'one-week',
|
||||||
{
|
{
|
||||||
name: firstName,
|
name: firstName,
|
||||||
|
@ -197,7 +193,6 @@ export const sendOneWeekBonusEmail = async (
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: 'David from Manifold <david@manifold.markets>',
|
from: 'David from Manifold <david@manifold.markets>',
|
||||||
'o:deliverytime': oneWeek,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,3 +41,4 @@ export * from './create-group'
|
||||||
export * from './resolve-market'
|
export * from './resolve-market'
|
||||||
export * from './unsubscribe'
|
export * from './unsubscribe'
|
||||||
export * from './stripe'
|
export * from './stripe'
|
||||||
|
export * from './mana-bonus-email'
|
42
functions/src/mana-bonus-email.ts
Normal file
42
functions/src/mana-bonus-email.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import * as functions from 'firebase-functions'
|
||||||
|
import * as admin from 'firebase-admin'
|
||||||
|
import * as dayjs from 'dayjs'
|
||||||
|
|
||||||
|
import { getPrivateUser } from './utils'
|
||||||
|
import { sendOneWeekBonusEmail } from './emails'
|
||||||
|
import { User } from 'common/user'
|
||||||
|
|
||||||
|
export const manabonusemail = functions
|
||||||
|
.runWith({ secrets: ['MAILGUN_KEY'] })
|
||||||
|
.pubsub.schedule('0 9 * * 1-7')
|
||||||
|
.onRun(async () => {
|
||||||
|
await sendOneWeekEmails()
|
||||||
|
})
|
||||||
|
|
||||||
|
const firestore = admin.firestore()
|
||||||
|
|
||||||
|
async function sendOneWeekEmails() {
|
||||||
|
const oneWeekAgo = dayjs().subtract(1, 'week').valueOf()
|
||||||
|
const twoWeekAgo = dayjs().subtract(2, 'weeks').valueOf()
|
||||||
|
|
||||||
|
const userDocs = await firestore
|
||||||
|
.collection('users')
|
||||||
|
.where('createdTime', '<=', oneWeekAgo)
|
||||||
|
.get()
|
||||||
|
|
||||||
|
for (const user of userDocs.docs.map((d) => d.data() as User)) {
|
||||||
|
if (user.createdTime < twoWeekAgo) continue
|
||||||
|
|
||||||
|
const privateUser = await getPrivateUser(user.id)
|
||||||
|
if (!privateUser || privateUser.manaBonusEmailSent) continue
|
||||||
|
|
||||||
|
await firestore
|
||||||
|
.collection('private-users')
|
||||||
|
.doc(user.id)
|
||||||
|
.update({ manaBonusEmailSent: true })
|
||||||
|
|
||||||
|
console.log('sending m$ bonus email to', user.username)
|
||||||
|
await sendOneWeekBonusEmail(user, privateUser)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user