slackbotapi
Advanced tools
Comparing version 1.3.1 to 1.3.3
@@ -62,1 +62,6 @@ ////////////////////////////////////////////////////////////////// | ||
}); | ||
slack.on('team_join', function(data) { | ||
// greet new member that joins | ||
slack.sendPM(data.user.id, 'Hello and welcome to the team! :simple_smile: :beers:'); | ||
}); |
76
index.js
@@ -76,5 +76,15 @@ ////////////////////////////////////////////////////////////////// | ||
bot_changed: 'bot_changed', | ||
accounts_changed: 'accounts_changed' | ||
accounts_changed: 'accounts_changed', | ||
reaction_added: 'reaction_added', | ||
reaction_removed: 'reaction_removed' | ||
}; | ||
var errors = { | ||
object_arg_required: 'Invalid arguments! Please provide an object with settings.', | ||
boolean_arg_required: 'Invalid arguments! Please provide a valid boolean for logging.', | ||
invalid_token: 'Invalid arguments! Please provide a valid auth token.', | ||
send_args_required: 'Send: No arguments specified!', | ||
data_type_undefined: 'data.type not defined' | ||
}; | ||
function slackAPI(args) { | ||
@@ -91,7 +101,7 @@ var self = this; | ||
this.logging = true; | ||
this.out('error', 'Invalid arguments! Please provide an object with settings.'); | ||
process.exit(1); | ||
this.out('error', errrs.object_arg_required); | ||
throw new Error(errors.object_arg_required); | ||
} if (typeof args['logging'] !== 'boolean') { | ||
this.logging = true; | ||
this.out('error', 'Invalid arguments! Please provide a valid boolean for logging.'); | ||
this.out('error', errors.boolean_arg_required); | ||
} else { | ||
@@ -101,4 +111,4 @@ this.logging = args['logging']; | ||
this.logging = true; | ||
this.out('error', 'Invalid arguments! Please provide a valid auth token.'); | ||
process.exit(1); | ||
this.out('error', errors.invalid_token); | ||
throw new Error(errors.invalid_token); | ||
} | ||
@@ -159,3 +169,3 @@ | ||
} else { | ||
this.out('error', 'Send: No arguments specified!'); | ||
this.out('error', errors.send_args_required); | ||
} | ||
@@ -180,7 +190,14 @@ }; | ||
if (typeof data.type != 'undefined'){ | ||
if (typeof events[data.type] !== 'undefined') { | ||
if (data.type === 'team_join') { | ||
var messageData = data; // allow cb() to run when user.list refreshes | ||
self.reqAPI('users.list', messageData, function(data) { | ||
data.members = self.slackData.users; | ||
cb(null, messageData); | ||
}) | ||
} | ||
else if (typeof events[data.type] !== 'undefined') { | ||
cb(null, data); | ||
} | ||
} else { | ||
cb(new Error("data.type not defined")); | ||
cb(new Error(errors.data_type_undefined)); | ||
} | ||
@@ -242,3 +259,3 @@ }); | ||
slackAPI.prototype.getIM = function(term) { | ||
var im = null; | ||
var im = null, self = this; | ||
for (var i in self.slackData.ims) { | ||
@@ -250,6 +267,9 @@ if(self.slackData.ims[i]['user'] === term) { | ||
if (im === null) { | ||
for (var i_ in self.slackData.ims) { | ||
if (self.slackData.ims[i_]['user'] === this.getUser(term).id) { | ||
im = self.slackData.ims[i_]; | ||
} | ||
var user = this.getUser(term); | ||
if(user !== null) { | ||
for (var i_ in self.slackData.ims) { | ||
if (self.slackData.ims[i_]['user'] === user.id) { | ||
im = self.slackData.ims[i_]; | ||
} | ||
} | ||
} | ||
@@ -265,4 +285,9 @@ } | ||
return im; | ||
}; | ||
} | ||
slackAPI.prototype.sendTyping = function(channel) { | ||
sendSock({'type': 'typing', channel: channel}); | ||
return this; | ||
} | ||
slackAPI.prototype.sendMsg = function(channel, text) { | ||
@@ -272,4 +297,19 @@ this.sendSock({'type': 'message', 'channel': channel, 'text': text}); | ||
slackAPI.prototype.sendPM = function(user, text) { | ||
this.sendSock({'type': 'message', 'channel': this.getIM(user).id, 'text': text}); | ||
slackAPI.prototype.sendPM = function(userID, text) { | ||
var self = this; | ||
var channel = self.getIM(userID); | ||
if(channel !== null) { | ||
self.sendSock({'type': 'message', 'channel': channel.id, 'text': text}); | ||
} else { | ||
if(this.getUser(userID)) userID = this.getUser(userID).id; // userID is username here | ||
self.reqAPI('im.open', { user : userID }, function(data){ | ||
if(data.ok === true) { | ||
self.slackData.ims.push(data.channel); | ||
self.sendSock({'type': 'message', 'channel': data.channel.id, 'text': text}); | ||
} else { | ||
self.out('error', 'Error. Unable to create an im channel: ' + data); | ||
self.emit("error", data); | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -279,2 +319,2 @@ | ||
module.exports = slackAPI; | ||
module.exports = slackAPI; |
@@ -0,0 +0,0 @@ GNU LESSER GENERAL PUBLIC LICENSE |
{ | ||
"name": "slackbotapi", | ||
"version": "1.3.1", | ||
"version": "1.3.3", | ||
"description": "a node.js API using Slack their RTM API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ SlackbotAPI | ||
[![GitHub Issues](https://img.shields.io/github/issues/xBytez/slackbotapi.svg?style=flat-square)](https://github.com/xBytez/slackbotapi/issues) | ||
[![Current Version](https://img.shields.io/badge/version-1.2.3-green.svg?style=flat-square)](https://github.com/xBytez/slackbotapi) | ||
[![Current Version](https://img.shields.io/badge/version-1.3.3-green.svg?style=flat-square)](https://github.com/xBytez/slackbotapi) | ||
@@ -19,3 +19,2 @@ A Node.JS module for Slack's RTM API | ||
* A valid Slack API Token | ||
* An internet connection | ||
@@ -22,0 +21,0 @@ #### Installation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22582
344
27