Post messages to Slack when events occur.

Using our official Slack integration

  • Create any tasks possible with the Slack API.

  • Use io.runTask() and the official SDK or fetch.

  • Example code using Slack

    Below are some working code examples of how you can use Slack with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

    import { TriggerClient } from "@trigger.dev/sdk";
    import { Github, events } from "@trigger.dev/github";
    import { Slack } from "@trigger.dev/slack";
    const github = new Github({ id: "github" });
    const slack = new Slack({ id: "slack" });
    // Sends a Slack message to a channel if a GitHub issue is left open for 24 hours
    client.defineJob({
    id: "github-new-issue-reminder",
    name: "GitHub: new issue reminder",
    version: "1.0.0",
    trigger: github.triggers.repo({
    event: events.onIssueOpened,
    owner: "<your-org-name>",
    repo: "<your-repo-name>",
    }),
    integrations: {
    github,
    slack,
    },
    run: async (payload, io, ctx) => {
    const delayDuration =
    ctx.environment.type === "DEVELOPMENT" ? 3 : 60 * 60 * 24;
    await io.wait("wait 24 hours", delayDuration);
    const issue = await io.github.getIssue("get issue", {
    owner: payload.repository.owner.login,
    repo: payload.repository.name,
    issueNumber: payload.issue.number,
    });
    if (issue.updated_at === payload.issue.updated_at) {
    const assigneeResult = await io.github.addIssueAssignees("add assignee", {
    owner: payload.repository.owner.login,
    repo: payload.repository.name,
    issueNumber: payload.issue.number,
    assignees: [payload.sender.login],
    });
    await io.slack.postMessage("send reminder", {
    channel: process.env.SLACK_CHANNEL_ID!,
    text: `Issue ${payload.issue.title} is still open. I've assigned it to ${payload.sender.login}.\n${issue.html_url}`,
    });
    }
    },
    });

    Full-stack Slack example projects

    ,