slack-node
Advanced tools
Comparing version 0.1.0 to 0.1.2
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.0 | ||
// Generated by CoffeeScript 1.7.1 | ||
module.exports = require("./lib/slack.seed"); |
@@ -1,11 +0,15 @@ | ||
// Generated by CoffeeScript 1.9.0 | ||
var Slack, request, | ||
// Generated by CoffeeScript 1.7.1 | ||
var DEFAULT_MAX_ATTEMPTS, DEFAULT_TIMEOUT, Slack, request, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
request = require("request"); | ||
request = require("requestretry"); | ||
DEFAULT_TIMEOUT = 10 * 1000; | ||
DEFAULT_MAX_ATTEMPTS = 3; | ||
Slack = (function() { | ||
function Slack(_at_token, _at_domain) { | ||
this.token = _at_token; | ||
this.domain = _at_domain; | ||
function Slack(token, domain) { | ||
this.token = token; | ||
this.domain = domain; | ||
this.api = __bind(this.api, this); | ||
@@ -18,2 +22,4 @@ this.webhook = __bind(this.webhook, this); | ||
this.url = this.composeUrl(); | ||
this.timeout = DEFAULT_TIMEOUT; | ||
this.maxAttempts = DEFAULT_MAX_ATTEMPTS; | ||
} | ||
@@ -53,7 +59,14 @@ | ||
payload[emoji.key] = emoji.val; | ||
return request.post({ | ||
return request({ | ||
method: "POST", | ||
url: this.webhookUrl, | ||
body: JSON.stringify(payload) | ||
body: JSON.stringify(payload), | ||
timeout: this.timeout, | ||
maxAttempts: this.maxAttempts, | ||
retryDelay: 0 | ||
}, function(err, body, response) { | ||
return callback(err, { | ||
if (err != null) { | ||
return callback(err); | ||
} | ||
return callback(null, { | ||
status: err || response !== "ok" ? "fail" : "ok", | ||
@@ -79,3 +92,6 @@ statusCode: body.statusCode, | ||
request_arg = { | ||
url: this.url + method | ||
url: this.url + method, | ||
timeout: this.timeout, | ||
maxAttempts: this.maxAttempts, | ||
retryDelay: 0 | ||
}; | ||
@@ -82,0 +98,0 @@ if (this._is_post_api(method)) { |
@@ -1,8 +0,14 @@ | ||
// Generated by CoffeeScript 1.9.0 | ||
var Slack, apiToken, domain, should, webhookToken, webhookUri; | ||
// Generated by CoffeeScript 1.7.1 | ||
var Slack, apiToken, domain, nock, should, url, webhookToken, webhookUri; | ||
should = require("should"); | ||
nock = require("nock"); | ||
url = require("url"); | ||
Slack = require("../index"); | ||
nock.enableNetConnect(); | ||
domain = "slack-node"; | ||
@@ -31,2 +37,5 @@ | ||
}, function(err, response) { | ||
if (err) { | ||
return done(err); | ||
} | ||
response.should.be.ok.and.an.Object; | ||
@@ -43,2 +52,5 @@ return done(); | ||
}, function(err, response) { | ||
if (err) { | ||
return done(err); | ||
} | ||
response.should.be.ok.and.an.Object; | ||
@@ -55,2 +67,5 @@ return done(); | ||
}, function(err, response) { | ||
if (err) { | ||
return done(err); | ||
} | ||
response.statusCode.should.be.a.Number; | ||
@@ -121,1 +136,27 @@ response.headers.should.be.an.Object; | ||
}); | ||
describe("retry test", function() { | ||
var slack; | ||
this.timeout(50000); | ||
slack = null; | ||
beforeEach(function() { | ||
slack = new Slack(); | ||
slack.setWebhook(webhookUri); | ||
return slack.timeout = 10; | ||
}); | ||
return it("Should retry if a request to slack fails after a timeout", function(done) { | ||
var mockWebhook, webhookDetails; | ||
webhookDetails = url.parse(webhookUri); | ||
mockWebhook = nock(webhookDetails.protocol + "//" + webhookDetails.host).post(webhookDetails.path).times(3).socketDelay(20).reply(204, ''); | ||
return slack.webhook({ | ||
channel: "#general", | ||
username: "webhookbot", | ||
text: "This is posted to #general and comes from a bot named webhookbot." | ||
}, function(err, response) { | ||
should.exist(err); | ||
should.not.exist(response); | ||
should.equal(mockWebhook.isDone(), true); | ||
return done(); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "slack-node", | ||
"version": "0.1.0", | ||
"version": "0.1.2", | ||
"description": "slack for node verision, full support", | ||
@@ -10,2 +10,6 @@ "main": "lib/index.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/clonn/slack-node-sdk.git" | ||
}, | ||
"keywords": [ | ||
@@ -19,3 +23,3 @@ "slack", | ||
"dependencies": { | ||
"request": "~2.34.0" | ||
"requestretry": "^1.2.2" | ||
}, | ||
@@ -25,4 +29,5 @@ "devDependencies": { | ||
"mocha": "^2.1.0", | ||
"nock": "^1.2.0", | ||
"should": "~3.3.1" | ||
} | ||
} |
@@ -26,3 +26,3 @@ slack-node-sdk | ||
slack = new Slack(); | ||
slack.setWebHook(webhookUri); | ||
slack.setWebhook(webhookUri); | ||
@@ -45,3 +45,3 @@ slack.webhook({ | ||
slack = new Slack(); | ||
slack.setWebHook(webhookUri); | ||
slack.setWebhook(webhookUri); | ||
@@ -52,3 +52,4 @@ // slack emoji | ||
username: "webhookbot", | ||
icon_emoji: ":ghost:" | ||
icon_emoji: ":ghost:", | ||
text: "test message, test message" | ||
}, function(err, response) { | ||
@@ -62,3 +63,4 @@ console.log(response); | ||
username: "webhookbot", | ||
icon_emoji: "http://icons.iconarchive.com/icons/rokey/popo-emotions/128/after-boom-icon.png" | ||
icon_emoji: "http://icons.iconarchive.com/icons/rokey/popo-emotions/128/after-boom-icon.png", | ||
text: "test message, test message" | ||
}, function(err, response) { | ||
@@ -68,2 +70,4 @@ console.log(response); | ||
Otherwise, you can check usage from [example](https://github.com/clonn/slack-node-sdk/tree/master/example) | ||
## Slack API support | ||
@@ -88,9 +92,18 @@ | ||
slack.api('chat.postMessage', {text:'hello from nodejs', channel:'#general'}, function(){}); | ||
slack.api('chat.postMessage', { | ||
text:'hello from nodejs', | ||
channel:'#general' | ||
}, function(err, response){ | ||
console.log(response); | ||
}); | ||
## Changelog | ||
* 0.0.96 | ||
* 0.1.2 | ||
* support ES6, promise function. | ||
* 0.1.0 | ||
* fixed test type error | ||
* support new [slack webhook](https://api.slack.com/incoming-webhooks). | ||
* 0.0.95 | ||
@@ -97,0 +110,0 @@ * fixed webhook function and test |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
25632
17
300
116
0
4
+ Addedrequestretry@^1.2.2
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequestretry@1.13.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwhen@3.7.8(transitive)
- Removedrequest@~2.34.0
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedhawk@1.0.0(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedmime@1.2.11(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedrequest@2.34.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedtldts@6.1.48(transitive)
- Removedtldts-core@6.1.48(transitive)
- Removedtough-cookie@5.0.0(transitive)
- Removedtunnel-agent@0.3.0(transitive)