Back to APIs
Slack
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.
Send a message to a Slack channel when a repo is starred.Send a reminder message to a Slack channel if a GitHub issue is left open for 24 hours.Posts Linear issues to Slack every weekday at 9am using Cron.Summarize GitHub commits using OpenAI and then post them to Slack.Send an activity summary email, and post it to Slack at 4pm every Friday.
1import { TriggerClient, cronTrigger } from "@trigger.dev/sdk";2import { Github } from "@trigger.dev/github";3import { OpenAI } from "@trigger.dev/openai";4import { Slack } from "@trigger.dev/slack";56const github = new Github({7id: "github",8token: process.env.GITHUB_TOKEN!,9});1011const openai = new OpenAI({12id: "openai",13apiKey: process.env.OPENAI_API_KEY!,14});1516const slack = new Slack({ id: "slack" });1718// This Job runs at 7am every day using a cron schedule expression.19client.defineJob({20id: "summarize-yesterday-commits-on-slack",21name: "Summarize yesterdays GitHub commits on Slack",22version: "1.0.0",23trigger: cronTrigger({24// Note that the time is in UTC.25// Converted to cron schedule expression using https://crontab.guru/26cron: "0 7 * * *",27}),28integrations: {29github,30openai,31slack,32},33run: async (payload, io, ctx) => {34// 1. Get the 'since' and 'until' timestamps35const since = payload.lastTimestamp?.toISOString();36const until = payload.ts?.toISOString();3738// 2. Get yesterday's commits from GitHub39const owner = "<your-org-name>";40const repo = "<your-repo-name>";4142const { data } = await io.github.runTask(43"get-yesterdays-commits",44async (client) => {45return client.rest.repos.listCommits({46owner,47repo,48since,49until,50});51},52{ name: "Get Yesterday's Commits" }53);5455// 3. Turn the commit data into a shorter format for OpenAI:56const formattedCommits = await io.runTask("format-commits", async () => {57return data.map((commit) => {58return {59author: commit.commit.author?.name,60message: commit.commit.message,61time: commit.commit.author?.date,62link: commit.html_url,63};64});65});6667// 4. Summarize the commits with OpenAI68const chatCompletion = await io.openai.createChatCompletion(69"chat-completion",70{71model: "gpt-3.5-turbo",72messages: [73{74role: "system",75content: `You are a expert programmer experienced in GitHub.76You are to concisely summarize the GitHub commits in one message.77Reply with a heading message -- 'GitHub Commits for ${repo} yesterday'78-- followed by a summary of the commits. Use bullet points in your summary79list and use appropriate spacing for maximum readability.`,80},81{82role: "user",83content: `Here are all of the GitHub commits from yesterday84(delimited by triple quotes below). Please summarize them like85"{user} {message} ({url})".\n\n"""${JSON.stringify(86formattedCommits,87null,88289)}"""`,90},91],92}93);9495// 5. Post to Slack96const response = await io.slack.postMessage("post message", {97channel: process.env.SLACK_CHANNEL_ID!,98text: chatCompletion.choices[0]?.message?.content || "No summary found",99});100},101});