schedule emails from onCreateUser; send interesting markets on D1
This commit is contained in:
parent
fc8487dca0
commit
0cbc0010c1
|
@ -16,7 +16,6 @@ import {
|
|||
cleanDisplayName,
|
||||
cleanUsername,
|
||||
} from '../../common/util/clean-username'
|
||||
import { sendPersonalFollowupEmail, sendWelcomeEmail } from './emails'
|
||||
import { isWhitelisted } from '../../common/envs/constants'
|
||||
import {
|
||||
CATEGORIES_GROUP_SLUG_POSTFIX,
|
||||
|
@ -93,10 +92,8 @@ export const createuser = newEndpoint(opts, async (req, auth) => {
|
|||
}
|
||||
|
||||
await firestore.collection('private-users').doc(auth.uid).create(privateUser)
|
||||
|
||||
await addUserToDefaultGroups(user)
|
||||
await sendWelcomeEmail(user, privateUser)
|
||||
await sendPersonalFollowupEmail(user, privateUser)
|
||||
|
||||
await track(auth.uid, 'create user', { username }, { ip: req.ip })
|
||||
|
||||
return { user, privateUser }
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import * as dayjs from 'dayjs'
|
||||
|
||||
import { DOMAIN } from '../../common/envs/constants'
|
||||
import { Answer } from '../../common/answer'
|
||||
|
@ -170,7 +169,8 @@ export const sendWelcomeEmail = async (
|
|||
|
||||
export const sendPersonalFollowupEmail = async (
|
||||
user: User,
|
||||
privateUser: PrivateUser
|
||||
privateUser: PrivateUser,
|
||||
sendTime: string
|
||||
) => {
|
||||
if (!privateUser || !privateUser.email) return
|
||||
|
||||
|
@ -192,7 +192,6 @@ Cofounder of Manifold Markets
|
|||
https://manifold.markets
|
||||
`
|
||||
|
||||
const sendTime = dayjs().add(4, 'hours').toString()
|
||||
|
||||
await sendTextEmail(
|
||||
privateUser.email,
|
||||
|
|
|
@ -5,6 +5,7 @@ import { EndpointDefinition } from './api'
|
|||
admin.initializeApp()
|
||||
|
||||
// v1
|
||||
export * from './on-create-user'
|
||||
export * from './on-create-bet'
|
||||
export * from './on-create-comment-on-contract'
|
||||
export * from './on-view'
|
||||
|
@ -28,7 +29,6 @@ export * from './score-contracts'
|
|||
export * from './weekly-markets-emails'
|
||||
export * from './reset-betting-streaks'
|
||||
|
||||
|
||||
// v2
|
||||
export * from './health'
|
||||
export * from './transact'
|
||||
|
|
41
functions/src/on-create-user.ts
Normal file
41
functions/src/on-create-user.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import * as functions from 'firebase-functions'
|
||||
import * as dayjs from 'dayjs'
|
||||
import * as utc from 'dayjs/plugin/utc'
|
||||
dayjs.extend(utc)
|
||||
|
||||
import { getPrivateUser } from './utils'
|
||||
import { User } from 'common/user'
|
||||
import {
|
||||
sendInterestingMarketsEmail,
|
||||
sendPersonalFollowupEmail,
|
||||
sendWelcomeEmail,
|
||||
} from './emails'
|
||||
import { getTrendingContracts } from './weekly-markets-emails'
|
||||
|
||||
export const onCreateUser = functions
|
||||
.runWith({ secrets: ['MAILGUN_KEY'] })
|
||||
.firestore.document('users/{userId}')
|
||||
.onCreate(async (snapshot) => {
|
||||
const user = snapshot.data() as User
|
||||
const privateUser = await getPrivateUser(user.id)
|
||||
if (!privateUser) return
|
||||
|
||||
await sendWelcomeEmail(user, privateUser)
|
||||
|
||||
const followupSendTime = dayjs().add(4, 'hours').toString()
|
||||
await sendPersonalFollowupEmail(user, privateUser, followupSendTime)
|
||||
|
||||
// skip email if weekly email is about to go out
|
||||
const day = dayjs().utc().day()
|
||||
if (day === 0 || (day === 1 && dayjs().utc().hour() <= 19)) return
|
||||
|
||||
const contracts = await getTrendingContracts()
|
||||
const marketsSendTime = dayjs().add(24, 'hours').toString()
|
||||
|
||||
await sendInterestingMarketsEmail(
|
||||
user,
|
||||
privateUser,
|
||||
contracts,
|
||||
marketsSendTime
|
||||
)
|
||||
})
|
Loading…
Reference in New Issue
Block a user