Last active
August 29, 2015 14:24
-
-
Save sperand-io/8bb29e4eea216d1ddcc9 to your computer and use it in GitHub Desktop.
Get Emails of Users Interested in Raw Data from Zendesk
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
var includes = require('@ndhoule/includes'); | |
var fold = require('@ndhoule/foldl'); | |
var each = require('@ndhoule/each'); | |
var ZD = require('node-zendesk') | |
var Batch = require('batch'); | |
var batch = new Batch; | |
var zendesk = ZD.createClient({ | |
username: /*usernamen*/, | |
token: /*token*/, | |
remoteUri: 'https://'+ /*subdomain*/ +'.zendesk.com/api/v2' | |
}); | |
//edit this list | |
var subjects = ['s3', 'kinesis', 'raw data', 'webhooks', 'export api', 'lambda']; | |
each(function(subject) { | |
var queries = ['type:ticket subject:' + subject, 'type:ticket ' + subject]; | |
each(function(derivedQuery){ | |
batch.push(function(done) { | |
findEmailsForQuery(derivedQuery, done) | |
}); | |
}, queries) | |
}, subjects); | |
batch.end(function(err, emails) { | |
if (err) return console.log(err); | |
var results = fold(function(acc, val) { | |
return acc.concat(val) | |
}, [], emails); | |
console.log(results); | |
}); | |
function findEmailsForQuery(query, done) { | |
zendesk.search.query(query, function(err, req, res) { | |
if (err) return done(err, null); | |
var ids = fold(function(acc, val) { | |
if (val.requester_id) acc.push(val.requester_id); | |
return acc; | |
}, [], res).join(','); | |
zendesk.users.showMany(ids, function(err, req, res) { | |
if (err) return done(err, null); | |
var emails = fold(function(acc, val) { | |
if (val.email && !includes(val.email, acc)) acc.push(val.email); | |
return acc; | |
}, [], res) | |
done(null, emails); | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment