Skip to content

Instantly share code, notes, and snippets.

@wozozo

wozozo/slack.js

Created Oct 19, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.