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
// Sends a Slack message to a channel if a GitHub issue is left open for 24 hours
9
client.defineJob({
10
id: "github-new-issue-reminder",
11
name: "GitHub: new issue reminder",
12
version: "1.0.0",
13
trigger: github.triggers.repo({
14
event: events.onIssueOpened,
15
owner: "<your-org-name>",
16
repo: "<your-repo-name>",
17
}),
18
integrations: {
19
github,
20
slack,
21
},
22
run: async (payload, io, ctx) => {
23
const delayDuration =
24
ctx.environment.type === "DEVELOPMENT" ? 3 : 60 * 60 * 24;
25
await io.wait("wait 24 hours", delayDuration);
26
27
const issue = await io.github.getIssue("get issue", {
28
owner: payload.repository.owner.login,
29
repo: payload.repository.name,
30
issueNumber: payload.issue.number,
31
});
32
33
if (issue.updated_at === payload.issue.updated_at) {
34
const assigneeResult = await io.github.addIssueAssignees("add assignee", {
35
owner: payload.repository.owner.login,
36
repo: payload.repository.name,
37
issueNumber: payload.issue.number,
38
assignees: [payload.sender.login],
39
});
40
41
await io.slack.postMessage("send reminder", {
42
channel: process.env.SLACK_CHANNEL_ID!,
43
text: `Issue ${payload.issue.title} is still open. I've assigned it to ${payload.sender.login}.\n${issue.html_url}`,
44
});
45
}
46
},
47
});

Full-stack Slack example projects