Skip to content

Commit

Permalink
Creation of vCards from Slack API
Browse files Browse the repository at this point in the history
  • Loading branch information
tallnato authored and Renato Almeida committed Nov 1, 2015
1 parent 699f6f9 commit b612fff
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"slackToken" : "",
"organization" : ""
}
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var config = require('./config.json')
var Slack = require('slack-node');
var vCard = require('vcards-js');
var request = require('request');
var fs = require('fs');

slack = new Slack(config.slackToken);
vCard = vCard();

console.log(config);

var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};


slack.api("users.list", function(err, response) {
response.members.forEach(function(user) {

download(user.profile.image_72, user.name+'.jpg' , function () {

//set properties
vCard.firstName = user.profile.first_name;
vCard.lastName = user.profile.last_name;
vCard.organization = config.organization;
vCard.photo.embedFromFile(user.name+'.jpg');

vCard.cellPhone = user.profile.phone;
vCard.title = user.profile.title;
vCard.email = user.profile.email;

vCard.socialUrls['skype'] = user.profile.skype;

//save to file
vCard.saveToFile('./contacts/'+user.name+'.vcf');

//Clean photo after save
fs.unlink(user.name+'.jpg');
});
});
});



5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
"author": "Renato Almeida <[email protected]>",
"private": true,
"license": "MIT",
"dependencies": {
"request": "^2.64.0",
"slack-node": "^0.1.3",
"vcards-js": "^2.2.0"
}
}

0 comments on commit b612fff

Please sign in to comment.