slack.slack
Home > @runlightyear/slack > Slack
Slack class
Connector to the Slack API
Signature:declare class Slack extends RestConnector
Extends:
Example 1
Post text message
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "postMessage",
title: "Post Message",
apps: ["slack"],
variables: [
{
name: "channel",
description:
"Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name.",
},
{
name: "text",
description: "The formatted text of the message to be published.",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({
auth: auths.slack,
});
const response = await slack.postMessage({
channel: variables.channel!,
text: variables.text!,
});
console.log("Response data: ", response.data);
},
});
Example 2
Post message with blocks
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "postMessageWithBlocks",
title: "Post Message With Blocks",
apps: ["slack"],
variables: [
{
name: "channel",
description:
"Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name.",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({ auth: auths.slack });
const response = await slack.postMessage({
channel: variables.channel!,
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: "The header of the message",
},
},
{
type: "section",
text: {
type: "mrkdwn",
text: "A message *with some bold text* and _some italicized text_.",
},
},
{
type: "divider",
},
{
type: "section",
fields: [
{
type: "mrkdwn",
text: "*Priority*\nHigh",
},
{
type: "mrkdwn",
text: "*Assignee*\nJohn",
},
{
type: "mrkdwn",
text: "*Labels*\nBug",
},
{
type: "mrkdwn",
text: "*Milestone*\nRelease 1.0",
},
],
},
],
text: "Text for screens where blocks are not supported.",
});
console.log("Response data: ", response.data);
},
});
Example 3
Schedule a message
import { dayjsUtc, defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "scheduleMessage",
title: "Schedule Message",
apps: ["slack"],
variables: [
{
name: "channel",
description:
"Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name.",
},
{
name: "delay?",
description:
"Amount of time in seconds to delay sending message. Defaults to 60.",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({
auth: auths.slack,
});
const delay = variables.delay ? parseInt(variables.delay) : 60;
const response = await slack.scheduleMessage({
channel: variables.channel!,
postAt: dayjsUtc().add(delay, "seconds").unix(),
text: `This message was delayed ${delay} seconds.`,
});
console.log("Response data: ", response.data);
},
});
Example 4
Create a new conversation
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "createPublicChannel",
title: "Create Public Channel",
apps: ["slack"],
variables: [
{
name: "name",
description: "Name of the public channel to create",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({
auth: auths.slack,
});
const response = await slack.createConversation({
name: variables.name!,
isPrivate: false,
});
console.log("Response data: ", response.data);
},
});
Example 5
Invite a user to a channel
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "inviteToChannel",
title: "Invite to Channel",
apps: ["slack"],
variables: [
{
name: "channel",
description: "ID of the channel to invite user to. Example: C1234567890",
},
{
name: "user",
description: "ID of the user to invite. Example: U3456789012",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({
auth: auths.slack,
});
const response = await slack.inviteToConversation({
channel: variables.channel!,
users: [variables.user!],
});
console.log("Response data: ", response.data);
},
});
Example 6
List users
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "listUsers",
title: "List Users",
apps: ["slack"],
run: async ({ auths }) => {
const slack = new Slack({
auth: auths.slack,
});
const response = await slack.listUsers();
console.log("Response data: ", response.data);
},
});
Example 7
Get user info
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "getUser",
title: "Get User",
apps: ["slack"],
variables: [
{
name: "user",
description: "User to get info on. Example: W1234567890",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({
auth: auths.slack,
});
const response = await slack.getUser({
user: variables.user!,
});
console.log("Response data: ", response.data);
},
});
Example 8
Lookup user by email
import { defineAction } from "@runlightyear/lightyear";
import { Slack } from "@runlightyear/slack";
defineAction({
name: "lookupUserByEmail",
title: "Lookup User By Email",
apps: ["slack"],
variables: [
{
name: "email",
description: "Email address of user to look up",
},
],
run: async ({ auths, variables }) => {
const slack = new Slack({
auth: auths.slack,
});
const response = await slack.lookupUserByEmail({
email: variables.email!,
});
console.log("Response data: ", response.data);
},
});
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(props) | Create a new slack connector |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
AppWebhook | static | typeof SlackAppWebhook | |
authType | static | AuthType | |
OAuth | static | typeof SlackOAuth | |
secrets | static | string[] | |
variables | static | string[] |
Chat Methods
Method | Modifiers | Description |
---|---|---|
postMessage(props) | Sends a message to a channel | |
scheduleMessage(props) | Schedules a message to be sent to a channel. |
Conversations Methods
Method | Modifiers | Description |
---|---|---|
createConversation(props) | Initiates a public or private channel-based conversation | |
inviteToConversation(props) | Invites users to a channel. | |
joinConversation(props) | Join an existing conversation | |
kickFromConversation(props) | Kick a user from a conversation | |
leaveConversation(props) | Leave a conversation | |
listConversations(props) | List conversations |
Team Methods
Method | Modifiers | Description |
---|---|---|
getTeamInfo(props) | Get team info |
Users Methods
Method | Modifiers | Description |
---|---|---|
getUser(props) | Gets information about a user. | |
listUsers(props) | List users | |
lookupUserByEmail(props) | Find a user with an email address. |
Other Methods
Method | Modifiers | Description |
---|---|---|
getBaseUrl() | ||
getDefaultHeaders() |