From 159723ed0c1072a017f62fe982113c19ff056c60 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 17 Aug 2022 17:36:52 -0500 Subject: [PATCH] market creation email --- .../src/email-templates/creating-market.html | 927 +++++++----------- functions/src/emails.ts | 31 + functions/src/on-create-contract.ts | 30 +- 3 files changed, 420 insertions(+), 568 deletions(-) diff --git a/functions/src/email-templates/creating-market.html b/functions/src/email-templates/creating-market.html index 64273e7c..674a30ed 100644 --- a/functions/src/email-templates/creating-market.html +++ b/functions/src/email-templates/creating-market.html @@ -1,46 +1,48 @@ - - - (no subject) - - - - - - - + + + + + + - - - - - - - - - + + - + + + - - - -
- -
+
+ +
- - - - + + +
+ + + + + + +
- -
+ +
- - - - - - -
+ + + + - - -
- +
- - - + + - - -
- +
+ -
-
- - -
-
- -
+
+
+
+ + + + + +
+ +
- - - -
+ + + + + + +
- -
+ +
- - - - - - -
+ + + + + + + - - -
+
+

+ Hi {{name}},

+
+
-
+
-

+

- + On Manifold Markets, several important factors - go into making a good question. These lead to - more people betting on them and allowing a more - accurate prediction to be formed! -

-

-   -

-

- Congrats on creating your first market on Manifold! +

+ +

+ Manifold also gives its creators 10 Mana for + ">The following is a short guide to creating markets. +

+

+   +

+

+ What makes a good market? +

+
    +
  • + Interesting + topic. Manifold gives + creators M$10 for each unique trader that bets on your - market! -

    -

    -   -

    -

    - + Clear resolution criteria. Any ambiguities or edge cases in your description + will drive traders away from your markets. +

  • + +
  • + Detailed description. Include images/videos/tweets and any context or + background + information that could be useful to people who + are interested in learning more that are + uneducated on the subject. +
  • +
  • + Add it to a group. Groups are the + primary way users filter for relevant markets. + Also, consider making your own groups and + inviting friends/interested communities to + them from other sites! +
  • +
  • + Share it on social media. You'll earn the M$500 + referral bonus if you get new users to sign up! +
  • +
+

+   +

+

+ What makes a good question? -

- +

+   +

+

+ Why not - - - - Why not + + + + create a marketcreate another market + "> while it is still fresh on your mind? -

-

- + Thanks for reading! -

-

Thanks for reading! +

+

- + David from Manifold -

-
-
- - -
-
- -
- - - - + + +
David from Manifold +

+ +
+
+ +
+ + +
+ + + +
- - -
- - - - + + +
+ + +
+ + + + - - -
- -
+ +
- - - - - - -
- + "> +
-
+ + + + - - - + + + + "> + + +
-
+
-

- This e-mail has been sent to {{name}}, - +

+ This e-mail has been sent to {{name}}, + click here to unsubscribe. -

-
-
click here to unsubscribe. +

+ +
+
-
-
- -
-
- + + +
+
+ - - + + + \ No newline at end of file diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 710ecab1..acab22d8 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -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 ', + } + ) +} + export const sendThankYouEmail = async ( user: User, privateUser: PrivateUser diff --git a/functions/src/on-create-contract.ts b/functions/src/on-create-contract.ts index 6b57a9a0..73076b7f 100644 --- a/functions/src/on-create-contract.ts +++ b/functions/src/on-create-contract.ts @@ -1,12 +1,17 @@ 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 { Contract } from '../../common/contract' import { parseMentions, richTextToString } from '../../common/util/parse' import { JSONContent } from '@tiptap/core' +import { User } from 'common/user' +import { sendCreatorGuideEmail } from './emails' -export const onCreateContract = functions.firestore - .document('contracts/{contractId}') +export const onCreateContract = functions + .runWith({ secrets: ['MAILGUN_KEY'] }) + .firestore.document('contracts/{contractId}') .onCreate(async (snapshot, context) => { const contract = snapshot.data() as Contract const { eventId } = context @@ -26,4 +31,23 @@ export const onCreateContract = functions.firestore richTextToString(desc), { 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) +}