Published
Edited
Jun 12, 2019
Insert cell
md`# Slack viewer`
Insert cell
axios = require('https://bundle.run/axios@0.19.0')
Insert cell
slack_zip = axios.get("https://gist.githubusercontent.com/stevekrouse/fd2e70db41849946d5077a494f04349f/raw/f6f92551de6ffe4743e40f29f987258279487cc6/foc-slack-export.zip", {responseType: 'blob'})
Insert cell
jszip = require("jszip@3.1.5/dist/jszip.min.js")
Insert cell
archive = jszip.loadAsync(slack_zip.data)
Insert cell
channelFiles = Object.keys(archive.files).filter(name => name.endsWith(".json"))
Insert cell
parse = file => {
return archive.file(file).async("text").then(JSON.parse).then(json => json.map(obj => ({...obj, channelName: file.split("/")[0]})))
}
Insert cell
parsedChannelFiles = Promise.all(channelFiles.map(parse))
Insert cell
messages = parsedChannelFiles.reduce((a,b) => a.concat(b), [])
Insert cell
users = archive.file("users.json").async("text").then(JSON.parse)
Insert cell
viewof searchText = html`<input type="text" value="eve">`
Insert cell
searchResult = messages.filter(message => message.text && message.text.includes(searchText))
Insert cell
html`<div>
${searchResult.map(message => renderMessage(message))}
</div>`
Insert cell
renderMessage = message => {
return html`
<div>
<div><img src="${findUser(message.user).profile.image_24}"></img>${findUser(message.user).real_name}</div>
<div>${message.text}</div> <!--TODO find and replace <@UDRKY9D3R> with users highlighted in blue-->
</div>`
}
Insert cell
findUser = userID => {
return users.find(user => user.id == userID)
}
Insert cell
users
Insert cell
md`
# Todo

- way that replacing the beginning of Slack URL sends us here to a message
- organize this page: search, list of channels
- nested messages
- render markdown
- render emojis
- render reactions
- render message date, link to message ID here as permalink
- find a way to generate and upload slack export regularly
- OR: use the Slack search API to do it all based on search
`
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more