Created
October 19, 2019 14:28
-
-
Save wozozo/1d4429f123b07049c98fbba664a102bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { WebClient } = require('@slack/web-api'); | |
const slackToken = process.env.SLACK_TOKEN; | |
async function uploadFile() { | |
const { createReadStream } = require('fs'); | |
const web = new WebClient(slackToken); | |
const conversationId = ''; | |
try { | |
const result = await web.files.upload({ | |
channels: conversationId, | |
file: createReadStream(`./${fileName}`), | |
filename: fileName, | |
}); | |
console.log('File uploaded: ', result.file.id); | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
async function postMessage() { | |
const web = new WebClient(slackToken); | |
const result = await web.text.postMessage({ | |
text: fileName, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment