Skip to main content

Slack

Send Slack messages from YepCode processes

Official Websitehttps://slack.com/
Tagsslack

Credential configuration

To configure this credential, you need the signingSecret and the Bolt token of your Slack app. You can see how to create an app and find the needed secrets here.

Optionally, you can set any of the extra config parameters you can see here.

Here is an example of a filled credential configuration form in YepCode:

Slack Snippets available in Editor

note

The title is the triggering text for YepCode to autocomplete the script.

Excluding the Web API, the rest of the Slack Bolt features have no place in YepCode due its nature.

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();