snippets_js
Integration
New integration from credential
const app = await yepcode.integration.slack("credential-slug")
New integration from plain authentication data
const { App } = require("@slack/bolt")
const app = new App({
token: "my-token"
signingSecret: "my-signing-secret"
})
Using the Web API
Lists channels
const listChannels = async () => {
try {
const { channels } = await app.client.conversations.list();
console.log(result);
} catch (error) {
console.error(error);
}
};
listChannels();
Retrieve messages
const retrieveChannelMessages = async () => {
try {
const result = await app.client.conversations.history({
channel: "channel",
});
const { messages } = result.messages;
console.log(messages);
} catch (error) {
console.error(error);
}
};
retrieveChannelMessages();
Post a message
const postMessage = async () => {
try {
const result = await app.client.chat.postMessage({
channel: "channel",
text: "He who controls the Spice, controls the universe!",
});
console.log(result);
} catch (error) {
console.error(error);
}
};
postMessage();
Upload a file
const { Readable } = require("stream");
// You can use any read stream to upload a file
const readStream = new Readable({
read() {
this.push("Sample stream data");
this.push(null);
},
});
const uploadAFile = async () => {
try {
const result = await app.client.files.uploadV2({
channels: "channel",
initial_comment: "Here's my file :smile:",
filename: "filename.txt",
file: readStream,
});
console.log(result);
} catch (error) {
console.error(error);
}
};
uploadAFile();