From 66624ff92c0f04ade61fc8b4904f1ffef599e57b Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 8 Feb 2022 03:26:33 -0800 Subject: [PATCH] Send a welcome email to new users --- functions/src/create-user.ts | 3 +++ functions/src/emails.ts | 24 ++++++++++++++++++++++-- functions/src/send-email.ts | 8 +++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/functions/src/create-user.ts b/functions/src/create-user.ts index 2b672358..13c880f3 100644 --- a/functions/src/create-user.ts +++ b/functions/src/create-user.ts @@ -13,6 +13,7 @@ import { cleanDisplayName, cleanUsername, } from '../../common/util/clean-username' +import { sendWelcomeEmail } from './emails' export const createUser = functions .runWith({ minInstances: 1 }) @@ -79,6 +80,8 @@ export const createUser = functions await firestore.collection('private-users').doc(userId).create(privateUser) + await sendWelcomeEmail(user, privateUser) + return { status: 'success', user } }) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 63d0c9d2..15f1e8b9 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -1,8 +1,8 @@ import { getProbability } from '../../common/calculate' import { Contract } from '../../common/contract' -import { User } from '../../common/user' +import { PrivateUser, User } from '../../common/user' import { formatPercent } from '../../common/util/format' -import { sendTemplateEmail } from './send-email' +import { sendTemplateEmail, sendTextEmail } from './send-email' import { getPrivateUser, getUser } from './utils' type market_resolved_template = { @@ -67,3 +67,23 @@ export const sendMarketResolutionEmail = async ( templateData ) } + +export const sendWelcomeEmail = async ( + user: User, + privateUser: PrivateUser +) => { + const firstName = user.name.split(' ')[0] + + await sendTextEmail( + privateUser.email || '', + 'Welcome to Manifold Markets!', + `Hi ${firstName}, + +Thanks for joining us! We can't wait to see what markets you create. +Questions? Feedback? I'd love to hear from you - just reply to this email! +Or come chat with us on Discord: https://discord.gg/eHQBNBqXuh + +Best, +Austin from Manifold` + ) +} diff --git a/functions/src/send-email.ts b/functions/src/send-email.ts index 1afc1526..938e3fc5 100644 --- a/functions/src/send-email.ts +++ b/functions/src/send-email.ts @@ -5,11 +5,13 @@ const DOMAIN = 'mg.manifold.markets' const mg = mailgun({ apiKey: functions.config().mailgun.key, domain: DOMAIN }) export const sendTextEmail = (to: string, subject: string, text: string) => { - const data = { - from: 'Manifold Markets ', + const data: mailgun.messages.SendData = { + from: 'Manifold Markets ', to, subject, text, + // Don't rewrite urls in plaintext emails + 'o:tracking-clicks': 'htmlonly', } return mg.messages().send(data, (error) => { @@ -25,7 +27,7 @@ export const sendTemplateEmail = ( templateData: Record ) => { const data = { - from: 'Manifold Markets ', + from: 'Manifold Markets ', to, subject, template: templateId,