Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mailchimp support #65

Closed
wants to merge 2 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
11 changes: 11 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ There are currently two different drivers available to store captured user data.

* Webhooks
* Google Sheets
* Mailchimp

### Webhooks

Expand Down Expand Up @@ -124,6 +125,16 @@ To configure Google Sheets the following environment variables must be set
2. Add headings for the data you want to see in the sheet such as `name`, `email` etc. These headings must match the `name` attribute of the inputs in the html form that the users are submitting when they conncect to the hotspot.
3. note the Google Sheets ID - from the sheets URL after `/d/` and before `/edit`

#### Mailchimp

Allows you to automatically add guests to a Mailchimp list.

Settings are as follows:

* `MAILCHIMP_API_KEY`: Your Mailchimp API key.
* `MAILCHIMP_SERVER_PREFIX`: The server prefix for your Mailchimp account (e.g., us1, us2, etc.).
* `MAILCHIMP_LIST_ID`: The ID of the Mailchimp list to which you want to add subscribers.

## Bind Mounts

### Custom Auth Page
Expand Down
123 changes: 120 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/woodjme/unifi-hotspot#readme",
"dependencies": {
"@mailchimp/mailchimp_marketing": "^3.0.80",
"axios": "^1.6.0",
"body-parser": "^1.20.0",
"express": "^4.17.2",
Expand Down
26 changes: 26 additions & 0 deletions src/helpers/logAuthDrivers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const axios = require('axios')
const { GoogleSpreadsheet } = require('google-spreadsheet')
const mailchimp = require('@mailchimp/mailchimp_marketing');

module.exports = {
webhook: async (formData) => {
Expand Down Expand Up @@ -45,5 +46,30 @@ module.exports = {
} else {
console.error('Skipping Google Sheets - required env vars not set')
}
},
mailchimp: async (formData) => {
// Add email to Mailchimp list
if (process.env.MAILCHIMP_API_KEY &&
process.env.MAILCHIMP_SERVER_PREFIX &&
process.env.MAILCHIMP_LIST_ID) {
try {
mailchimp.setConfig({
apiKey: process.env.MAILCHIMP_API_KEY,
server: process.env.MAILCHIMP_SERVER_PREFIX
});

const response = await mailchimp.lists.addListMember(process.env.MAILCHIMP_LIST_ID, {
email_address: formData.email,
status: 'subscribed'
});

return response;
} catch (err) {
console.error(err);
console.error('Mailchimp Failed');
}
} else {
console.error('Skipping Mailchimp - required env vars not set');
}
}
}