-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
132 lines (127 loc) · 4 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var express = require('express');
var needle = require('needle');
var async = require('async');
var cookieParser = require('cookie-parser')
var app = express();
var SparkPost = require('sparkpost');
var sp = new SparkPost('7c247123769702176276c6dd238c4bdf3184c8d9');
var contactInfo = {};
var savedRes;
var contacts = [];
app.set('port', (process.env.PORT || 3005));
app.use(cookieParser());
app.get("/connect", function(req, res) {
contacts.push({
name: req.query.name || "Unknown " + Math.floor(Math.random() * 900) + 100,
email: req.query.email
});
if (!savedRes) {
contactInfo = req.query;
savedRes = res;
return;
}
sp.transmissions.send({
transmissionBody: {
content: {
from: '[email protected]',
subject: 'You connected with ' + req.query.name,
reply_to: req.query.email,
html: 'You connected with ' + req.query.name + '. Reply to this email to this email to contact them.<br><br>Thanks, <br>Contap</p>',
},
recipients: [{
address: contactInfo.email
}]
}
}, function(err, res) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Woohoo! You just sent your first mailing!');
}
});
sp.transmissions.send({
transmissionBody: {
content: {
from: '[email protected]',
subject: 'You connected with ' + contactInfo.name,
html: 'You connected with ' + contactInfo.name + '. Reply to this email to this email to contact them.<br><br>Thanks, <br>Contap</p>',
reply_to: contactInfo.email
},
recipients: [{
address: req.query.email
}]
}
}, function(err, res) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Woohoo! You just sent your first mailing!');
}
});
res.json(contactInfo);
savedRes.json(req.query);
savedRes = null;
});
app.get("/connect2", function(req, res) {
contactInfo = false;
savedRes = false;
sp.transmissions.send({
transmissionBody: {
content: {
from: '[email protected]',
subject: 'You connected with ' + req.query.name,
html: '<html><body><p>Hi ' + req.query.name + ',<br/> You are now connected with Hillary Sanders. She will reach out to you shortly.<br><br>Thanks, <br>Contap</p></body></html>'
},
recipients: [{
address: req.query.email
}]
}
}, function(err, res) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Woohoo! You just sent your first mailing!');
}
});
needle.post('https://api.contactually.com/v2/contacts', '{\
"data": {\
"first_name": "' + req.query.name + '",\
"last_name": "",\
"company": null,\
"title": "' + req.query.name + '",\
"avatar_url": null,\
"email_addresses": [\
{\
"label": null,\
"address": "' + req.query.email + '"' +
'}\
]\
}\
}', {
json: true,
headers: {
Authorization: "Bearer 5c678fa1c39749d9859a93e651ff959f33e0ecf494a12cdc27e127f51e653bb9"
}
},
function(err, resp) {
console.log(err, resp)
})
});
app.get("/contacts", function(req, res) {
res.json({
contacts: contacts
})
contacts = [];
});
app.get("/memes", function(req, res) {
res.sendFile(__dirname + "/public/memes.html");
});
app.get("*", function(req, res) {
res.send("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
});
app.listen(app.get('port'), function() {
console.log('Started on port ' + app.get("port") + '!');
});