slack
Version:
Slack API client writ in JS
36 lines (28 loc) • 844 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exec;
var _xhr = require('xhr');
var _xhr2 = _interopRequireDefault(_xhr);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var baseUrl = 'https://slack.com/api/';
function exec(ns, json, callback) {
var url = '' + baseUrl + ns;
_xhr2.default.post(url, { json: json }, function (err, res) {
if (err) {
// if request failed bubble the error
callback(err);
} else if (res.body.error) {
// if Slack returns an error bubble the error
callback(Error(res.body.error));
} else {
// success! clean up the response
var _json = res.body;
delete _json.ok;
callback(null, _json);
}
});
/// eom
}
module.exports = exports['default'];