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.
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";5const github = new Github({6id: "github",7token: process.env.GITHUB_TOKEN!,8});910const openai = new OpenAI({11id: "openai",12apiKey: process.env.OPENAI_API_KEY!,13});1415const slack = new Slack({ id: "slack" });1617// This Job runs at 7am every day using a cron schedule expression.18client.defineJob({19id: "summarize-yesterday-commits-on-slack",20name: "Summarize yesterdays GitHub commits on Slack",21version: "1.0.0",22trigger: cronTrigger({23// Note that the time is in UTC.24// Converted to cron schedule expression using https://crontab.guru/25cron: "0 7 * * *",26}),27integrations: {28github,29openai,30slack,31},32run: async (payload, io, ctx) => {33// 1. Get the 'since' and 'until' timestamps34const since = payload.lastTimestamp?.toISOString();35const until = payload.ts?.toISOString();3637// 2. Get yesterday's commits from GitHub38const owner = "<your-org-name>";39const repo = "<your-repo-name>";4041const { data } = await io.github.runTask(42"get-yesterdays-commits",43async (client) => {44return client.rest.repos.listCommits({45owner,46repo,47since,48until,49});50},51{ name: "Get Yesterday's Commits" }52);5354// 3. Turn the commit data into a shorter format for OpenAI:55const formattedCommits = await io.runTask("format-commits", async () => {56return data.map((commit) => {57return {58author: commit.commit.author?.name,59message: commit.commit.message,60time: commit.commit.author?.date,61link: commit.html_url,62};63});64});6566// 4. Summarize the commits with OpenAI67const chatCompletion = await io.openai.createChatCompletion(68"chat-completion",69{70model: "gpt-3.5-turbo",71messages: [72{73role: "system",74content: `You are a expert programmer experienced in GitHub.75You are to concisely summarize the GitHub commits in one message.76Reply with a heading message -- 'GitHub Commits for ${repo} yesterday'77-- followed by a summary of the commits. Use bullet points in your summary78list and use appropriate spacing for maximum readability.`,79},80{81role: "user",82content: `Here are all of the GitHub commits from yesterday83(delimited by triple quotes below). Please summarize them like84"{user} {message} ({url})".\n\n"""${JSON.stringify(85formattedCommits,86null,87288)}"""`,89},90],91}92);9394// 5. Post to Slack95const response = await io.slack.postMessage("post message", {96channel: process.env.SLACK_CHANNEL_ID!,97text: chatCompletion.choices[0]?.message?.content || "No summary found",98});99},100});