Back to APIs

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.

Slack integration docs

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.

1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Github, events } from "@trigger.dev/github";
3
import { Slack } from "@trigger.dev/slack";
4
5
const github = new Github({ id: "github" });
6
const slack = new Slack({ id: "slack" });
7
8
// This Job will run when a star is added or removed from the triggerdotdev/trigger.dev repo
9
client.defineJob({
10
id: "github-new-star-to-slack",
11
name: "GitHub: new star to slack",
12
version: "1.0.0",
13
trigger: github.triggers.repo({
14
event: events.onStar,
15
owner: "<your-org-name>",
16
repo: "<your-repo-name>",
17
}),
18
integrations: {
19
slack,
20
},
21
run: async (payload, io, ctx) => {
22
await io.slack.postMessage("post message", {
23
channel: process.env.SLACK_CHANNEL_ID!,
24
text: `New GitHub star from ${payload.sender.html_url}, ${payload.sender.name}. Your new GitHub star count is ${payload.repository.stargazers_count}.`,
25
});
26
},
27
});

Full-stack Slack example projects