-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (40 loc) · 1.39 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var yaml_config = require('node-yaml-config');
var Slack = require('slack-node');
var vCardJS = require('vcards-js');
var fs = require('fs');
var config = yaml_config.load('./config.yml');
slack = new Slack(config.slackToken);
//get the team info
slack.api("team.info", function(err, response){
if(err) throw err;
if(!response.ok) throw new Error(response.error);
var organization = response.team.name;
var vFile = organization + '.vcf';
//Check if file already exists
if (fs.existsSync(vFile)){
fs.unlinkSync(vFile);
}
console.log("Getting users for organization '" + organization + "'.");
//Get the team user list
slack.api("users.list", function(err, response) {
if(err){ throw err; }
if(!response.ok) throw new Error(response.error);
response.members.forEach(function(user) {
var vCard = vCardJS();
//set properties
if(user.profile.first_name)
vCard.firstName = user.profile.first_name;
if(user.profile.last_name)
vCard.lastName = user.profile.last_name;
vCard.organization = organization;
vCard.photo.attachFromUrl(user.profile.image_72, 'JPEG');
vCard.cellPhone = user.profile.phone;
vCard.title = user.profile.title;
vCard.workEmail = user.profile.email;
vCard.socialUrls['skype'] = user.profile.skype;
//Append vCard to file
fs.appendFile(vFile, vCard.getFormattedString());
});
console.log("vCard '" + vFile + "' created.");
});
});