From c01f5708c9eac1545124b6c06a9c68bebc4adbfe Mon Sep 17 00:00:00 2001 From: Yonatan Miller Date: Wed, 16 Dec 2020 10:22:27 +0100 Subject: [PATCH] Autopost to new newsletter's mailchimp which has id 243735091b Missing Mailchimp API key most likely (don't have access to it) --- lib/commands/addToMailchimp.js | 20 ++++++++++++++++++++ lib/res/signup.js | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 lib/commands/addToMailchimp.js diff --git a/lib/commands/addToMailchimp.js b/lib/commands/addToMailchimp.js new file mode 100644 index 0000000..8f95161 --- /dev/null +++ b/lib/commands/addToMailchimp.js @@ -0,0 +1,20 @@ +const Mailchimp = require('mailchimp-api-v3') + +const mailchimp = new Mailchimp(process.env.MAILCHIMP_API_KEY); + +module.exports.postToMailchimp = function(userInformation) { + console.log('Posting to mailchimp') + return mailchimp.post('/lists/243735091b/members', { + email_address: userInformation.email, + status: 'subscribed', + merge_fields: { + MMERGE3: userInformation.company_name, + MMERGE6: userInformation.name + } + }) + .catch(err => { + console.log('Error adding user to mailchimp') + console.log(params) + console.log(err) + }) +} diff --git a/lib/res/signup.js b/lib/res/signup.js index d14b14d..3efd508 100644 --- a/lib/res/signup.js +++ b/lib/res/signup.js @@ -3,6 +3,7 @@ const Team = require("../models/team"); const qs = require("querystring"); const invite = require("../buttons/invite"); +const postToMailchimp = require('../commands/addToMailchimp').postToMailchimp const CHANNEL = process.env.SIGNUP_CHANNEL || "admin-signups"; @@ -26,6 +27,9 @@ function signup(req, res, next) { console.log(params); postToSlack(params) + .then(() => { + postToMailchimp(params); + }) .then(() => { if (!params.redirect_uri) { res.send(200, "signup request sent");