Created
March 28, 2021 10:36
-
-
Save praveeno/685cf6982d93085632775d5c4259092b to your computer and use it in GitHub Desktop.
Slack Group / DM chat download script Js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const downloadSlackHistory = (cursor, channel, token, {ignore_replies, include_pin_count, limit, inclusive, no_user_profile, workspace_name}) => fetchJson(`https://${workspace_name}.slack.com/api/conversations.history?cursor=${cursor ? cursor: ''}`, { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8", | |
"cache-control": "no-cache", | |
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryB9uCttsJARlaTNGJ", | |
"pragma": "no-cache", | |
"sec-ch-ua": "\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-site" | |
}, | |
"referrerPolicy": "no-referrer", | |
"body": `------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"channel\"\r\n\r\n${channel}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"limit\"\r\n\r\n${limit}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"ignore_replies\"\r\n\r\n${ignore_replies}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"include_pin_count\"\r\n\r\n${include_pin_count}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"inclusive\"\r\n\r\n${inclusive}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"no_user_profile\"\r\n\r\n${no_user_profile}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\n${token}\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"_x_reason\"\r\n\r\nmessage-pane/requestHistory\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"_x_mode\"\r\n\r\nonline\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ\r\nContent-Disposition: form-data; name=\"_x_sonic\"\r\n\r\ntrue\r\n------WebKitFormBoundaryB9uCttsJARlaTNGJ--\r\n`, | |
"method": "POST", | |
"mode": "cors", | |
"credentials": "include" | |
}) | |
const fetchJson = async (...args) => (await fetch(...args)).json(); | |
async function downloadSlackHistoryWrapper(...args) { | |
const json = await downloadSlackHistory(...args); | |
msg = msg.concat(json.messages); | |
if (json.response_metadata&& json.response_metadata.next_cursor) { | |
const _args = [json.response_metadata.next_cursor, ...args.slice(1, args.length)] | |
return downloadSlackHistoryWrapper(..._args); | |
} | |
return msg; | |
} | |
// main | |
const msgs = []; | |
downloadSlackHistory(null, ).then(msgs => { | |
console.log('done') | |
console.log(msgs); | |
copy(msgs); // chrome copy function | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment