Slack

Send Slack notifications.
Airplane's Slack SDK makes it easy to send Slack messages from a task. To use this SDK, you'll need to connect to Slack.

Message

Send Slack messages to your connected Slack workspace.
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "send_slack_notifs",
6
},
7
async () => {
8
await airplane.slack.message("#my-channel", "Hello world");
9
// Sends message to user with Slack ID U0G9QF9C6.
10
await airplane.slack.message("U0G9QF9C6", "Hello world");
11
// Sends message using Slack's Block Kit API.
12
await airplane.slack.message("#my-channel", {
13
blocks: [
14
{
15
type: "section",
16
text: {
17
type: "mrkdwn",
18
text: "Task created by <example.com|Fred Enriquez> has completed\n\n<https://example.com|View task>",
19
},
20
},
21
],
22
});
23
},
24
);
airplane.slack.message(channelName, message)
channelName
REQUIRED
string

The Slack channel to send messages to. channelName also accepts a Slack channel ID or Slack user ID (for direct messages).

message
REQUIRED
string or object

Contents of the message. message is a string that can be formatted using Slack markdown. message also support more advanced formatting like @-mentioning, date formatting, etc. To learn more, see the Slack formatting docs. For more control (e.g. to use Block Kit), message can also be an object of Slack postMessage arguments.

Output

This built-in has no output.

Upload

Upload files to your connected Slack workspace.
typescript
Copied
1
import airplane from "airplane";
2
3
const CSV_TEXT = `Name,Email,Phone,JoinDate
4
John Doe,john@airplane.dev,123-456-7890,2021-03-14`;
5
6
/** Uploads a CSV string to #my-channel. */
7
export const uploadCSV = airplane.task({ slug: "upload_csv" }, async () => {
8
await airplane.slack.upload("#my-channel", {
9
payload: CSV_TEXT,
10
filename: "employees.csv",
11
message: "Here are our employees.",
12
});
13
});
14
15
/** Uploads an image passed in the task param to user with Slack ID U0G9QF9C6. */
16
export const uploadImage = airplane.task(
17
{
18
slug: "upload_file_to_slack",
19
parameters: { image: { type: "upload" } },
20
},
21
async (params) => {
22
await airplane.slack.upload("U0G9QF9C6", {
23
payload: params.image,
24
filename: "image.png",
25
message: "Here's my uploaded image.",
26
});
27
},
28
);
airplane.slack.upload(channelName, uploadOption)
channelName
REQUIRED
string

The Slack channel to send notifications to. channelName also accepts a Slack channel ID or Slack user ID (for direct messages).

uploadOption
REQUIRED
{payload: Blob | AirplaneFile | string; filename: string; message?: string}

The options to use when uploading the file.<br/>The options include the payload, filename, and an optional message. The payload is the file that is uploaded to Slack. The filename is the name of the upload and is also used to determine the file type of the payload.

Output

This built-in has no output.