Blog

How to post to Slack from an app you built with AI

Your agent built a tracker, and the team wants its updates in a Slack channel. Webhooks or a bot token, why the difference matters for an app that holds company data, and how to post a daily summary.

A tool your agent built is working. The support team logs escalations in it, or finance tracks which invoices are waiting for approval. Now someone asks the obvious next thing: "can it post in our channel?" A message in Slack each morning saying "4 escalations are still open" is worth more than a tool people have to remember to check.

There are two ways for an app to post to Slack, and they look almost the same in code. They are very different in what they let the app do with your data. This article covers both, how to set up the one we recommend, and how to post on a schedule.

We make Spryloom, which runs apps like this for teams behind sign-in. It supports one of the two ways and refuses the other, and the reason is the most useful part of the article, whatever you host on.

Way 1: an incoming webhook

Slack lets you create an incoming webhook: a web address that posts whatever is sent to it into one channel. The app sends a small piece of JSON to that address, and the message appears.

It is the quickest way to get a message into Slack, and for a script on your own machine, or a build server posting "deploy finished", it is a good choice. There is no token to manage, only the address, and the address goes in a secret like any key.

The catch is not in Slack. It is in what the address is. Anyone can create a webhook, in any Slack workspace they control. So an app that is allowed to send to webhook addresses can post to anybody's Slack, not only yours. If the code is changed, by a mistake, a confused agent or a dependency that does something it shouldn't, your customer list can go to a channel in somebody else's workspace, and from the outside it looks exactly like a normal post.

Way 2: a bot token and chat.postMessage

The other way is a Slack app with a bot. You create the app in your own Slack workspace, give it permission to post, install it, and get a bot token. The app then calls Slack's Web API method chat.postMessage at https://slack.com/api/chat.postMessage, with the token and the channel.

The token belongs to your workspace. It can post where the bot has been added, and nowhere else. It takes a few more minutes to set up than a webhook, and it can do more later: post in a thread, update a message, read a channel if you give it that permission.

A webhook app your Slack anyone's Slack any address works A bot token app slack.com yours only your workspace
The code is almost the same. What the app can reach is not.

For a tool that holds company data, the bot token is the better choice wherever you host it.

Setting up the bot, in general terms

Slack's own pages describe each screen, and they change, so here is the shape of it rather than every click:

Create a Slack appFrom Slack's developer site. A workspace admin may need to approve it.
Allow postingThe scope is chat:write.
Install itSlack shows a bot token starting xoxb-.
Add the bot to the channelWhere it should post.
Keep the token out of the codeAn environment variable, set outside the repository.

The posting code is plain fetch:

const CHANNEL = 'C0123ABCDEF'; // the channel's ID, shown in its details in Slack

const answer = await fetch('https://slack.com/api/chat.postMessage', {
  method: 'POST',
  headers: {
    authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`,
    'content-type': 'application/json',
  },
  body: JSON.stringify({ channel: CHANNEL, text: '4 escalations are still open.' }),
});
const result = await answer.json();
if (!result.ok) throw new Error(`Slack said: ${result.error}`);

Slack answers with JSON that has ok: true, or ok: false and an error, so check the answer rather than only the status code. A common first error is that the bot isn't in the channel yet.

Posting every morning

A daily post doesn't belong in a timer inside the server. Many hosts stop an app when nobody is using it, and the timer stops too. It belongs in a scheduled job: a script run on a schedule, which posts and exits. How to send a daily email reminder from an app you built with AI explains why in more detail; the same reasoning applies to Slack.

The version on Spryloom

On Spryloom an app reaches its own database and nothing else, unless it names a host in spryloom.yaml from a fixed list. Webhook hosts are left off for the reason above: anyone can create a webhook there.

slack.comhooks.slack.comdiscord.com

Say to your agent: "post the open escalations to #support-leads every weekday at 9". Spryloom's instructions tell it to use the bot API, a secret for the token and a declared job, so it writes something like:

egress:
  - slack.com
jobs:
  - name: morning-post
    command: node jobs/post-to-slack.js
    schedule: "0 9 * * 1-5"
    timezone: America/New_York
  1. The bot API's host, the only outside host it can reach.
  2. A job, not a timer in the server.
  3. A script that posts and exits.
  4. 9:00 on weekdays.
  5. The team's time zone. The agent asks rather than assuming.

Then the agent gives you the token command, which you run yourself so the token never passes through the chat. Secrets reach the app when it is published, so publish again after setting it. If the app can't start without the token, the first publish fails and the second works.

escalations
spry secrets escalations set SLACK_BOT_TOKEN=xoxb-...
spry publish
# try the post without waiting for tomorrow
spry jobs run escalations morning-post
# see what it did
spry logs escalations --job morning-post

The app's label page, at /~label on its address, says it "Reads from and posts to Slack". A coworker can see where the data goes before typing anything into it.

What it doesn't do

  • No webhooks. Slack's incoming webhooks and Discord's are refused. Use a bot token at slack.com.
  • At most once every 10 hours. A job can post once or twice a day. A post every hour, or a live feed of every change, isn't what jobs are for.
  • It doesn't set up the Slack app for you. Creating the bot and installing it is done in Slack, by someone allowed to.
  • It doesn't receive from Slack. Slash commands and buttons in Slack would need Slack to call the app, and the only way into an app is through sign-in. The app posts out; people click through to it.
  • Five failures in a row pause the job. You are emailed when that happens. spry logs shows why, and spry jobs resume escalations morning-post starts it again once fixed.
  • 500 MB a day sent and received per app. Far more than a daily post needs.

Start here

In Claude Code, add the plugin once:

/plugin marketplace add spryloom/claude-plugin
/plugin install spryloom@spryloom

In Codex:

codex mcp add spryloom -- npx -y spryloom mcp

Then ask for the post in plain words, and run the spry secrets line the agent gives you.

Spryloom publishes apps and pages built with a coding agent behind sign-in, for the people you invite. This article was written by the people building it.

Get started free