Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// api.slack.com/files.upload requires multipart/form-data post
// which means we need to do a few things differently…
var isUploading = /files.upload/.test(url)
// stringify any objects under keys when application/x-www-form-urlencoded
if (!isUploading) {
Object.keys(form).forEach(function (key) {
if (typeof form[key] === 'object') {
form[key] = JSON.stringify(form[key])
}
})
}
// always post to slack
http.post({
url: `${origin}/api/${url}`,
headers: {
'Content-Type': isUploading? 'multipart/form-data' : 'application/x-www-form-urlencoded'
},
data: form
},
function _res(err, res) {
if (err && err.message === 'POST failed with: 429') {
// workaround Slacks lack of symmetry not ours…
var e = Error('ratelimited')
e.retry = err.raw.headers['retry-after']
callback(e)
}
else if (err) {
callback(err)
}
function _getValidationCode(headers) {
let data = { value: identifier }
tiny.post({
url,
headers,
data,
}, function _done(err) {
if (err) {
console.log(err)
}
else {
console.log(`Check ${identifier} for your validation code`)
}
})
}
)
module.exports = function AugustAccessTokenRequest(callback) {
tiny.post({
url,
headers,
data,
}, function _done(err, response) {
if (err) {
console.log(err)
}
else {
headers['x-august-access-token'] = response.headers['x-august-access-token']
callback(headers)
}
})
}
function _validateCode(headers) {
console.log(headers)
let data = {
code
}
data[identifierType] = identifier
tiny.post({
url,
headers,
data,
}, function _done(err) {
if (err) {
console.log(err)
}
else {
console.log('Your session is now validated! Please remove references to the validate methods from your code.')
}
})
}
)
function chatcommand(params, callback) {
tiny.post({
url: 'https://slack.com/api/chat.command',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: params
}, function _res(err, res) {
if (err) console.log(err)
});
}