market creation email
This commit is contained in:
parent
ce3d092497
commit
159723ed0c
File diff suppressed because it is too large
Load Diff
|
@ -236,6 +236,37 @@ export const sendOneWeekBonusEmail = async (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const sendCreatorGuideEmail = async (
|
||||||
|
user: User,
|
||||||
|
privateUser: PrivateUser
|
||||||
|
) => {
|
||||||
|
if (
|
||||||
|
!privateUser ||
|
||||||
|
!privateUser.email ||
|
||||||
|
privateUser.unsubscribedFromGenericEmails
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
const { name, id: userId } = user
|
||||||
|
const firstName = name.split(' ')[0]
|
||||||
|
|
||||||
|
const emailType = 'generic'
|
||||||
|
const unsubscribeLink = `${UNSUBSCRIBE_ENDPOINT}?id=${userId}&type=${emailType}`
|
||||||
|
|
||||||
|
return await sendTemplateEmail(
|
||||||
|
privateUser.email,
|
||||||
|
'Market creation guide',
|
||||||
|
'creating-market',
|
||||||
|
{
|
||||||
|
name: firstName,
|
||||||
|
unsubscribeLink,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: 'David from Manifold <david@manifold.markets>',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const sendThankYouEmail = async (
|
export const sendThankYouEmail = async (
|
||||||
user: User,
|
user: User,
|
||||||
privateUser: PrivateUser
|
privateUser: PrivateUser
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import * as functions from 'firebase-functions'
|
import * as functions from 'firebase-functions'
|
||||||
import { getUser } from './utils'
|
import * as admin from 'firebase-admin'
|
||||||
|
|
||||||
|
import { getPrivateUser, getUser } from './utils'
|
||||||
import { createNotification } from './create-notification'
|
import { createNotification } from './create-notification'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { parseMentions, richTextToString } from '../../common/util/parse'
|
import { parseMentions, richTextToString } from '../../common/util/parse'
|
||||||
import { JSONContent } from '@tiptap/core'
|
import { JSONContent } from '@tiptap/core'
|
||||||
|
import { User } from 'common/user'
|
||||||
|
import { sendCreatorGuideEmail } from './emails'
|
||||||
|
|
||||||
export const onCreateContract = functions.firestore
|
export const onCreateContract = functions
|
||||||
.document('contracts/{contractId}')
|
.runWith({ secrets: ['MAILGUN_KEY'] })
|
||||||
|
.firestore.document('contracts/{contractId}')
|
||||||
.onCreate(async (snapshot, context) => {
|
.onCreate(async (snapshot, context) => {
|
||||||
const contract = snapshot.data() as Contract
|
const contract = snapshot.data() as Contract
|
||||||
const { eventId } = context
|
const { eventId } = context
|
||||||
|
@ -26,4 +31,23 @@ export const onCreateContract = functions.firestore
|
||||||
richTextToString(desc),
|
richTextToString(desc),
|
||||||
{ contract, recipients: mentioned }
|
{ contract, recipients: mentioned }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await sendGuideEmail(contractCreator)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const firestore = admin.firestore()
|
||||||
|
|
||||||
|
const sendGuideEmail = async (contractCreator: User) => {
|
||||||
|
const query = await firestore
|
||||||
|
.collection(`contracts`)
|
||||||
|
.where('creatorId', '==', contractCreator.id)
|
||||||
|
.limit(2)
|
||||||
|
.get()
|
||||||
|
|
||||||
|
if (query.size >= 2) return
|
||||||
|
|
||||||
|
const privateUser = await getPrivateUser(contractCreator.id)
|
||||||
|
if (!privateUser) return
|
||||||
|
|
||||||
|
await sendCreatorGuideEmail(contractCreator, privateUser)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user