Skip to content

Instantly share code, notes, and snippets.

@wozozo
Created October 19, 2019 14:28
Show Gist options
  • Save wozozo/1d4429f123b07049c98fbba664a102bf to your computer and use it in GitHub Desktop.
Save wozozo/1d4429f123b07049c98fbba664a102bf to your computer and use it in GitHub Desktop.
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