Skip to content

Commit 4617b8b

Browse files
author
Ramesh, Gaurav
committed
support for slack-terminalize upgrade
1 parent 78bee45 commit 4617b8b

File tree

8 files changed

+23
-29
lines changed

8 files changed

+23
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# slack-terminalize-cli
1+
# slack-sample-cli
22

33
Sample app to work with [slack-terminalize](https://github.com/ggauravr/slack-terminalize) with some basic custom commands

commands/app-error.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

commands/error.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function (param) {
2+
console.log("Invalid command entered: %s with arguments", param.args[0], param.args.slice(1));
3+
};

commands/gem.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,22 @@ var request = require('request'),
44
module.exports = function (param) {
55
var channel = param.channel,
66
endpoint = param.commandConfig.endpoint.replace('{gem}', param.args[0]);
7-
8-
(function(channel){
97

10-
request(endpoint, function (err, response, body) {
11-
var info = [];
12-
13-
if (!err && response.statusCode === 200) {
14-
body = JSON.parse(body);
8+
request(endpoint, function (err, response, body) {
9+
var info = [];
1510

16-
info.push('Gem: ' + body.name + ' - ' + body.info);
17-
info.push('Authors: ' + body.authors);
18-
info.push('Project URI: ' + body.project_uri);
19-
}
20-
else {
21-
info = ['No such gem found!'];
22-
}
11+
if (!err && response.statusCode === 200) {
12+
body = JSON.parse(body);
2313

24-
util.postMessage(channel, info.join('\n\n'));
25-
});
14+
info.push('Gem: ' + body.name + ' - ' + body.info);
15+
info.push('Authors: ' + body.authors);
16+
info.push('Project URI: ' + body.project_uri);
17+
}
18+
else {
19+
info = ['No such gem found!'];
20+
}
2621

27-
})(channel);
22+
util.postMessage(channel, info.join('\n\n'));
23+
});
2824

2925
};

config/commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"description": "Fetches details of the specified Ruby gem"
1414
},
1515

16-
"app-error": {
16+
"error": {
1717
"exclude": true
1818
}
1919
}

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var slackTerminal = require('slack-terminalize');
22

3-
slackTerminal.init({
4-
SLACK_TOKEN: '<xoxb-your-token-here>'
5-
}, {
3+
slackTerminal.init('xoxb-token', {}, {
64
CONFIG_DIR: __dirname + '/config',
75
COMMAND_DIR: __dirname + '/commands'
86
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"dependencies": {
77
"request": "^2.65.0",
8-
"slack-terminalize": "^0.0.3"
8+
"slack-terminalize": "file:///Users/gnramesh/Documents/dev/personal/slack-terminalize"
99
},
1010
"scripts": {
1111
"test": "echo \"Error: no test specified\" && exit 1"

util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var webClient = require('slack-terminalize').getWebClient();
12
/**
23
* Wrapper function for postMessage from slack-client to handle formatting.
34
*
@@ -12,9 +13,8 @@ var postMessage = function (channel, response, format) {
1213
format = format || true;
1314
response = (format && '```' + response + '```') || response;
1415

15-
channel.postMessage({
16-
as_user: true,
17-
text: response
16+
webClient.chat.postMessage(channel, response, {
17+
as_user: true
1818
});
1919

2020
};

0 commit comments

Comments
 (0)