> ## Documentation Index
> Fetch the complete documentation index at: https://trigger-v3-fix-additional-files.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Slack tasks

Tasks are executed after the job is triggered and are the main building blocks of a job. You can string together as many tasks as you want.

***

## All tasks

### `postMessage`

Post a message to a channel. [Official Slack Docs](https://api.slack.com/methods/chat.postMessage)

```ts example.ts
// Send a Slack message using the io.slack.postMessage function
await io.slack.postMessage("post message", {
  // Specify the target channel by providing its ID
  channel: "<your-channel-id>",
  // Set the text content of the message
  text: "<your-slack-message>",
});
```

## Using the underlying client

If we don't have the task you need listed above, you can use `io.slack.runTask()` function, which lets you do anything that’s possible with the official Slack Node SDK. More information [here](/documentation/concepts/tasks#using-io-integration-runtask).

Example usage:

```ts
client.defineJob({
  id: "send-slack-message",
  name: "Send a Slack message",
  version: "1.0.0",
  trigger: eventTrigger({
    name: "send.slack.message",
    schema: z.object({
      message: z.string,
    }),
  }),
  integrations: {
    slack,
  },
  run: async (payload, io, ctx) => {
    // Use the Slack integration to create a task using the "post-message" cacheKey
    const message = await io.slack.postMessage("post-message", {
      channel: process.env.SLACK_CHANNEL_ID,
      message: payload.message,
    });

    // Use the Slack integration's runTask method to add a reaction to the message
    await io.slack.runTask("add-reaction", async (client) => {
      // client here is an authenticated instance of the Slack SDK
      await client.reactions.add({
        channel: process.env.SLACK_CHANNEL_ID,
        name: "thumbsup",
        timestamp: message.ts,
      });
    });
  },
});
```

## How to post rich messages to Slack

Use their [Block kit builder](https://api.slack.com/block-kit), and then use the `blocks` property to send the message.

```ts linearIssuesDailySlackAlert.ts
...
await io.slack.postMessage("post message", {
      channel: process.env.SLACK_CHANNEL_ID!,
      // Include text for notifications and blocks to get a rich Slack message in the channel
      text: `You have ${inProgressIssues.nodes.length} 'In Progress' issues in Linear!`,
      // Create rich Slack messages with the Block Kit builder https://app.slack.com/block-kit-builder/
      blocks: inProgressIssues.nodes.flatMap((issue) => [
        {
          type: "section",
          text: {
            type: "mrkdwn",
            text: `⏳ *${issue.title}*`,
          },
          accessory: {
            type: "button",
            text: {
              type: "plain_text",
              text: "View issue",
              emoji: true,
            },
            value: "click_me_123",
            url: issue.url,
            action_id: "button-action",
          },
        },
        {
          type: "divider",
        },
      ]),
    });
  },
});
```
