Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Stan/simple notifications #2101

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions infra/notifications/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const bodyParser = require('body-parser')
const webpush = require('web-push')
const { RateLimiterMemory } = require('rate-limiter-flexible')

const { mobilePush } = require('./mobilePush')
const { browserPush } = require('./browserPush')
// const { mobilePush } = require('./mobilePush')
// const { browserPush } = require('./browserPush')
const { emailSend } = require('./emailSend')

const app = express()
Expand Down Expand Up @@ -62,18 +62,18 @@ const config = {
verbose: args['--verbose'] || false
}

logger.log('Configuration:')
logger.log(config)

// ------------------------------------------------------------------

// should be tightened up for security
// TODO: Should be tightened up for security
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When deployed this is all handled by nginx, so this should only be applied in development, i.e. NODE_ENV === 'development'

app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
)

next()
})

Expand Down Expand Up @@ -227,10 +227,10 @@ app.post('/events', async (req, res) => {
res.status(200).send({ status: 'ok' })

// Mobile Push (linker) notifications
mobilePush(eventName, party, buyerAddress, sellerAddress, offer)
// mobilePush(eventName, party, buyerAddress, sellerAddress, offer)

// Browser push subscripttions
browserPush(eventName, party, buyerAddress, sellerAddress, offer)
// browserPush(eventName, party, buyerAddress, sellerAddress, offer)

// Email notifications
emailSend(
Expand Down
21 changes: 18 additions & 3 deletions infra/notifications/src/emailSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ async function emailSend(
if (config.verbose) {
logger.info(`No message found`)
}
} else {
} else {
const networkSubDomains = {
1: '',
4: 'staging.',
999: 'localhost.',
2222: 'dev.'
}
const listingNetwork = listing.id.split('-')[0] // First section of id is the network num
const vars = {
dappUrl:
`https://dapp.${networkSubDomains[listingNetwork]}originprotocol.com`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for network 999, I don't think https://dapp.localhost.originprotocol.com will resolve to local dapp ? I think we use http://localhost on local...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah crap you are right! Bit the bullet and have everything laid out explicitly.

ipfsGatewayUrl:
`https://gateway.${networkSubDomains[listingNetwork]}originprotocol.com`
}
const email = {
to: config.overrideEmail || s.email,
from: config.fromEmail,
Expand All @@ -93,14 +106,16 @@ async function emailSend(
message: message.text({
listing: listing,
offer: offer,
config: config
config: config,
...vars
})
}),
html: emailTemplateHtml({
message: message.html({
listing: listing,
offer: offer,
config: config
config: config,
...vars
})
}),
asm: {
Expand Down
81 changes: 56 additions & 25 deletions infra/notifications/templates/messageTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,29 @@ const messageTemplates = {
subject: 'New Offer',
html: _.template(
`
A buyer (<em><%- offer.buyer.identity.fullName %></em>) has made an offer on your listing <em><%= listing.title %></em>.

<% if (listing.media[0]) { %>
<img class="listing-img" src="https://ipfs.originprotocol.com/ipfs/<%- listing.media[0].url.slice(7,53) %>"/>
<% } %>
A buyer has made an offer on your listing <em><%= listing.title %></em>.
<br/><a href="<%= dappUrl %>/#/purchases/<%- offer.id %>">View Transaction</a>
`
),
text: _.template('A buyer has made an offer on your listing.')
text: _.template(`
A buyer has made an offer on your listing.
<%= dappUrl %>/#/purchases/<%- offer.id %>
`)
},
OfferWithdrawn: {
subject: 'Offer Withdrawn',
html: _.template(
`
The buyer <em><%- offer.buyer.identity.fullName %></em> has withdrawn their offer on your listing <em><%= listing.title %></em>.

<% if (listing.media[0]) { %>
<img class="listing-img" src="https://ipfs.originprotocol.com/ipfs/<%- listing.media[0].url.slice(7,53) %>"/>
<% } %>
The buyer has withdrawn their offer on your listing <em><%= listing.title %></em>.
<br/><a href="<%= dappUrl %>/#/purchases/<%- offer.id %>">View Transaction</a>
`
),
text: _.template('An offer on your listing has been withdrawn.')
text: _.template(
`
An offer on your listing has been withdrawn.
<%= dappUrl %>/#/purchases/<%- offer.id %>
`
)
},
OfferDisputed: {
subject: 'Dispute Initiated',
Expand All @@ -73,17 +75,16 @@ const messageTemplates = {
subject: 'Sale Completed',
html: _.template(
`
Your transaction with <em><%- offer.buyer.identity.fullName %></em> for
Your transaction with the buyer for
<em><%= listing.title %></em> has been completed.


<% if (listing.media[0]) { %>
<img class="listing-img" src="https://ipfs.originprotocol.com/ipfs/<%- listing.media[0].url.slice(7,53) %>"/>
<% } %>
<br/><a href="<%= dappUrl %>/#/purchases/<%- offer.id %>">View Transaction</a>
`
),
text: _.template(
'Your transaction with "<%= offer.buyer.identity.fullName %>" for "<%= listing.title %>" has been completed.'
`
Your transaction with the buyer for "<%= listing.title %>" has been completed.
<%= dappUrl %>/#/purchases/<%- offer.id %>
`
)
}
}
Expand Down Expand Up @@ -114,13 +115,33 @@ const messageTemplates = {
email: {
OfferWithdrawn: {
subject: 'Offer Rejected',
html: _.template('An offer you made has been rejected.'),
text: _.template('An offer you made has been rejected.')
html: _.template(
`
An offer you made has been rejected.
<br/><a href="<%= dappUrl %>/#/purchases/<%- offer.id %>">View Transaction</a>
`
),
text: _.template(
`
An offer you made has been rejected.
<%= dappUrl %>/#/purchases/<%- offer.id %>
`
)
},
OfferAccepted: {
subject: 'Offer Accepted',
html: _.template('An offer you made has been accepted.'),
text: _.template('An offer you made has been accepted.')
html: _.template(
`
An offer you made has been accepted.
<br/><a href="<%= dappUrl %>/#/purchases/<%- offer.id %>">View Transaction</a>
`
),
text: _.template(
`
An offer you made has been accepted.
<%= dappUrl %>/#/purchases/<%- offer.id %>
`
)
},
OfferDisputed: {
subject: 'Dispute Initiated',
Expand All @@ -138,8 +159,18 @@ const messageTemplates = {
},
OfferData: {
subject: 'New Review',
html: _.template('A review has been left on your transaction.'),
text: _.template('A review has been left on your transaction.')
html: _.template(
`
A review has been left on your transaction.
<br/><a href="<%= dappUrl %>/#/purchases/<%- offer.id %>">View Transaction</a>
`
),
text: _.template(
`
A review has been left on your transaction.
<%= dappUrl %>/#/purchases/<%- offer.id %>
`
)
}
}
}
Expand Down