-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (23 loc) · 865 Bytes
/
Copy pathindex.js
File metadata and controls
24 lines (23 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
var Sandbox = new (require('sandbox'));
function evalJSHandler(request, reply){
if(request.payload.token !== process.env.slackToken) return reply('Incorrect token').code(401);
var code = request.payload.text.slice(3).trim();
Sandbox.run(code, function(out){
var response = '';
if( (!out.result || out.result === 'null') && out.console.length === 0 ) return reply('Snippet ran sucessfully.');
if(out.console.length > 0){
response += out.console.reduce(function(s, c){
return s + c.replace('\n', ' ');
}, '');
return reply({text : response});
}
response = out.result.split('\n').slice(0,3).join('\n');
reply({text : response});
});
}
module.exports = {
handler : evalJSHandler,
path : '/slack/outgoing/eval-js',
method : 'POST'
};