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

Commit

Permalink
Merge pull request #691 from max/master
Browse files Browse the repository at this point in the history
Add script to subscribe to Mailchimp list
  • Loading branch information
Tom Bell committed Jan 10, 2013
2 parents 8ef8156 + be3040b commit f7f3804
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/scripts/mailchimp-subscribe.coffee
@@ -0,0 +1,47 @@
# Description:
# Add email to Mailchimp list
#
# Dependencies:
# "mailchimp": "0.9.5"
#
# Configuration:
# MAILCHIMP_API_KEY
# MAILCHIMP_LIST_ID
#
# Commands:
# hubot subscribe <email> - Add email to list
#
# Author:
# max, lmarburger

MailChimpAPI = require('mailchimp').MailChimpAPI

apiKey = process.env.MAILCHIMP_API_KEY
listId = process.env.MAILCHIMP_LIST_ID

module.exports = (robot)->
robot.respond /subscribe (.+@.+)/i, (message)->
subscribeToList message

subscribeToList = (message) ->
emailAddress = message.match[1]

try
api = new MailChimpAPI(apiKey,
version: "1.3"
secure: false
)
catch error
console.log error.message
return

api.listSubscribe
id: listId
# Hack until this PR lands: https://github.com/gomfunkel/node-mailchimp/pull/21
email_address: encodeURIComponent(emailAddress)
double_optin: false
, (error, data) ->
if error
message.send "Uh oh, something went wrong: #{error.message}"
else
message.send "You succesfully subscribed #{emailAddress}."

0 comments on commit f7f3804

Please sign in to comment.