HTML resolved market email
This commit is contained in:
parent
b97a65cf2c
commit
c5ab1ba2e0
|
@ -1,8 +1,17 @@
|
||||||
import { sendEmail } from './send-email'
|
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { User } from '../../common/user'
|
import { User } from '../../common/user'
|
||||||
|
import { sendTemplateEmail } from './send-email'
|
||||||
import { getUser } from './utils'
|
import { getUser } from './utils'
|
||||||
|
|
||||||
|
type market_resolved_template = {
|
||||||
|
name: string
|
||||||
|
creatorName: string
|
||||||
|
question: string
|
||||||
|
outcome: string
|
||||||
|
payout: string
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
export const sendMarketResolutionEmail = async (
|
export const sendMarketResolutionEmail = async (
|
||||||
userId: string,
|
userId: string,
|
||||||
payout: number,
|
payout: number,
|
||||||
|
@ -13,22 +22,24 @@ export const sendMarketResolutionEmail = async (
|
||||||
const user = await getUser(userId)
|
const user = await getUser(userId)
|
||||||
if (!user) return
|
if (!user) return
|
||||||
|
|
||||||
const subject = `Resolved ${toDisplayResolution[resolution]}: ${contract.question}`
|
const outcome = toDisplayResolution[resolution]
|
||||||
|
|
||||||
const body = `Dear ${user.name},
|
const subject = `Resolved ${outcome}: ${contract.question}`
|
||||||
|
|
||||||
A market you bet in has been resolved!
|
const templateData: market_resolved_template = {
|
||||||
|
name: user.name,
|
||||||
|
creatorName: creator.name,
|
||||||
|
question: contract.question,
|
||||||
|
outcome,
|
||||||
|
payout: `${Math.round(payout)}`,
|
||||||
|
url: `https://manifold.markets/${creator.username}/${contract.slug}`,
|
||||||
|
}
|
||||||
|
|
||||||
Creator: ${contract.creatorName}
|
// Modify template here:
|
||||||
Question: ${contract.question}
|
// https://app.mailgun.com/app/sending/domains/mg.manifold.markets/templates/edit/market-resolved/initial
|
||||||
Resolution: ${toDisplayResolution[resolution]}
|
// Mailgun username: james@mantic.markets
|
||||||
|
|
||||||
Your payout is M$ ${Math.round(payout)}
|
await sendTemplateEmail(user.email, subject, 'market-resolved', templateData)
|
||||||
|
|
||||||
View the market here:
|
|
||||||
https://manifold.markets/${creator.username}/${contract.slug}
|
|
||||||
`
|
|
||||||
await sendEmail(user.email, subject, body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A', MKT: 'MKT' }
|
const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A', MKT: 'MKT' }
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as functions from 'firebase-functions'
|
||||||
const DOMAIN = 'mg.manifold.markets'
|
const DOMAIN = 'mg.manifold.markets'
|
||||||
const mg = mailgun({ apiKey: functions.config().mailgun.key, domain: DOMAIN })
|
const mg = mailgun({ apiKey: functions.config().mailgun.key, domain: DOMAIN })
|
||||||
|
|
||||||
export const sendEmail = (to: string, subject: string, text: string) => {
|
export const sendTextEmail = (to: string, subject: string, text: string) => {
|
||||||
const data = {
|
const data = {
|
||||||
from: 'Manifold Markets <no-reply@manifold.markets>',
|
from: 'Manifold Markets <no-reply@manifold.markets>',
|
||||||
to,
|
to,
|
||||||
|
@ -12,7 +12,27 @@ export const sendEmail = (to: string, subject: string, text: string) => {
|
||||||
text,
|
text,
|
||||||
}
|
}
|
||||||
|
|
||||||
return mg.messages().send(data, (error, body) => {
|
return mg.messages().send(data, (error) => {
|
||||||
console.log('Sent email', error, body)
|
if (error) console.log('Error sending email', error)
|
||||||
|
else console.log('Sent text email', to, subject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const sendTemplateEmail = (
|
||||||
|
to: string,
|
||||||
|
subject: string,
|
||||||
|
templateId: string,
|
||||||
|
templateData: Record<string, string>
|
||||||
|
) => {
|
||||||
|
const data = {
|
||||||
|
from: 'Manifold Markets <no-reply@manifold.markets>',
|
||||||
|
to,
|
||||||
|
subject,
|
||||||
|
template: templateId,
|
||||||
|
'h:X-Mailgun-Variables': JSON.stringify(templateData),
|
||||||
|
}
|
||||||
|
return mg.messages().send(data, (error) => {
|
||||||
|
if (error) console.log('Error sending email', error)
|
||||||
|
else console.log('Sent template email', templateId, to, subject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user