-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
182 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"automations": [ | ||
{ | ||
"name": "automation1", | ||
"description": "tell user about pro features", | ||
"trigger_name": "proplan", | ||
"emails": [ | ||
{ | ||
"trigger": "time", | ||
"sendDelay": 1, | ||
"subject": "w1e1", | ||
"body": "Customizations are great", | ||
"from": "[email protected]" | ||
}, | ||
{ | ||
"trigger": "time", | ||
"sendDelay": 3, | ||
"subject": "w1e2", | ||
"body": "Customizations are great", | ||
"from": "[email protected]" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "automation2", | ||
"description": "tell user about pro features 2", | ||
"trigger_name": "proplan", | ||
"emails": [ | ||
{ | ||
"trigger": "time", | ||
"sendDelay": 2, | ||
"subject": "w2e1", | ||
"body": "Customizations are great", | ||
"from": "[email protected]" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require('dotenv').config() | ||
const path = require('path') | ||
const candymail = require('../../index') | ||
const express = require('express') | ||
const app = express() | ||
const port = 3000 | ||
|
||
const automationPath = path.resolve('examples', 'candymail.automation.json') | ||
candymail.init(automationPath, { | ||
senderEmail: process.env.MAIL_USER, | ||
senderPassword: process.env.MAIL_PASSWORD, | ||
hostingURL: 'http://localhost:3000' | ||
}) | ||
|
||
candymail.start() | ||
|
||
const someConditionSatisfiedByUser = () => { | ||
const user = '[email protected]' | ||
candymail.runAutomation('automation1', user) | ||
} | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Welcome to Candymail Demo. Go to /trigger to trigger the `automation1` email automation. Be sure to replace email with yours in the `someConditionSatisfiedByUser` method to be able to view the messages.') | ||
}) | ||
|
||
app.get('/trigger', (req, res) => { | ||
someConditionSatisfiedByUser() | ||
res.send(candymail.getAllScheduledMessages()) | ||
}) | ||
|
||
app.get('/unsubscribe', (req, res) => { | ||
const { email } = req.query | ||
console.log(email) | ||
candymail.unsubscribeUser(email) | ||
res.send(`Sent a unsubscribe request for ${email}`) | ||
}) | ||
|
||
app.listen(port, () => { | ||
console.log(`Learn about our new features at http://localhost:${port}/trigger`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "candymail-demo", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"candymail": "^1.0.5", | ||
"dotenv": "^8.2.0", | ||
"express": "^4.17.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require('path') | ||
const candymail = require('../../index') | ||
|
||
const automationPath = path.resolve('examples', 'candymail.automation.json') | ||
|
||
candymail.init(automationPath, { | ||
senderEmail: process.env.MAIL_USER, | ||
senderPassword: process.env.MAIL_PASSWORD, | ||
hostingURL: 'http://localhost:3000' | ||
}) | ||
|
||
candymail.start() | ||
|
||
// candymail.unsubscribeUser('[email protected]') // Immediatedly unsubscribe user and they will not receive any more messages | ||
|
||
const someConditionSatisfiedByUser = () => { | ||
const user = '[email protected]' | ||
candymail.runAutomation('automation1', user) | ||
} | ||
|
||
someConditionSatisfiedByUser() | ||
console.log(candymail.getAllScheduledMessages()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require('dotenv').config() | ||
const { sendEmail } = require('./helper') | ||
const { unsubscribeUser } = require('./messages') | ||
|
||
// unsubscribeUser('[email protected]') | ||
|
||
sendEmail({ template: 'template', sendFrom: '[email protected]', sendTo: '[email protected]', subject: 'subject', body: '<h1> Welcome</h1> <p>That was easy!</p><br><a href="/unsubscribe">Click here to unsubscribe</a>' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { sendMessagesNow } = require('../index') | ||
const scheduler = require('../src/scheduler') | ||
|
||
describe('Basic Tests', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks() | ||
jest.resetAllMocks() | ||
scheduler.clearAllScheduledMessages() | ||
}) | ||
test('should throw an error when email about to be sent to unsubscribed user', () => { | ||
Date.now = jest.fn(() => new Date('2020-08-20T03:20:30Z')) | ||
const user = '[email protected]' | ||
scheduler.addScheduledMessage('8/19/2020:23', { template: 'template', sendFrom: 'sendFrom', sendTo: user, subject: 'subject', body: 'body' }) | ||
|
||
scheduler.unsubscribeUser(user) | ||
|
||
expect(() => { | ||
sendMessagesNow() | ||
}).toThrow(new Error('The user [email protected] you are trying to send a message to has already unsubscribed')) | ||
}) | ||
}) |