# Add Scheduled Messages to a Slack Bolt App

Yes. An agent adds a listener that schedules messages with chat.scheduleMessage, handles the 120-day and per-channel limits, lists and cancels them, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-scheduled-messages/slack-bolt/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the app first. In an app laid out like slack-samples/bolt-js-getting-started-app, `app.js` is the whole thing: `new App({ token: process.env.SLACK_BOT_TOKEN, socketMode: true, appToken: process.env.SLACK_APP_TOKEN })`, one `app.message('hello', ...)` listener that replies with a section block and a button whose `action_id` is `button_click`, one `app.action('button_click', ...)` handler that acknowledges and replies, and `app.start(process.env.PORT || 3000)`. `package.json` is `"type": "module"` with a single dependency, `@slack/bolt` at `^5.1.0` (5.1.0 in `package-lock.json`), a `start` script and no test or lint script. `manifest.json` grants the bot `channels:history`, `chat:write` and `im:history`, subscribes to `message.channels` and `message.im`, and has Socket Mode and interactivity enabled. `.github/dependabot.yml` checks npm weekly and `dependencies.yml` auto-merges Dependabot's patch and minor updates.

The Slack method is `chat.scheduleMessage`. It takes `channel`, `post_at` as a Unix timestamp, and the `text` or `blocks` to post; it needs only `chat:write`, which the manifest already grants, so no reinstall is required. A message can be scheduled up to 120 days ahead; a `post_at` in the past answers `time_in_past` and one too far out answers `time_too_far`. A channel also refuses more than 30 scheduled posts inside the same five-minute window with `restricted_too_many`. The response carries a `scheduled_message_id`, which is what `chat.deleteScheduledMessage` needs to cancel it, and `chat.scheduledMessages.list` returns what is pending.

The agent adds a listener in the same style as the existing one. `app.message(/^remind (.+) in (\d+) (minutes?|hours?)$/i, ...)` reads the captured text and delay from `context.matches`, computes `post_at` from `Date.now()` in seconds, and calls `client.chat.scheduleMessage({ channel: message.channel, post_at, text })`, where `client` is the `WebClient` Bolt passes to every listener. The parsing and the bounds check live in a new `schedule.js` module that exports a pure function, so the listener stays a few lines: on success it uses `say` to confirm with the time and the `scheduled_message_id`; on `time_too_far` or `restricted_too_many` it says what the limit is instead of letting the error reach the logger. A second listener on `list reminders` calls `chat.scheduledMessages.list` for the channel, and a button on each row with an `action_id` of `cancel_reminder` carries the id in its `value` so an `app.action` handler can call `chat.deleteScheduledMessage`.

The repository has no test runner, so the agent uses the one Node ships with. It adds `schedule.test.js` using `node:test` and `node:assert` to cover the parser and the bounds check, including the day-120 edge and a zero delay, and a `test` script of `node --test`. The Slack calls themselves are not mocked in unit tests; instead the pull request shows the listener running against a workspace is a matter of the two tokens in the environment, exactly as `README.md` already describes. `manifest.json` is unchanged, because the scopes and the `message.channels` event the new listener depends on are already there.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add scheduled messages to this Slack Bolt app. Read app.js, package.json, package-lock.json, manifest.json, README.md and the files under .github first. Add a message listener matching 'remind <text> in <n> minutes|hours' that computes post_at as a Unix timestamp and calls client.chat.scheduleMessage with the channel the message came from, confirming with say including the scheduled_message_id. Put the parsing and the limit checks in a separate schedule.js module: refuse a time more than 120 days out before calling Slack, and turn the time_in_past, time_too_far and restricted_too_many errors into plain replies. Add a 'list reminders' listener that calls chat.scheduledMessages.list for the channel and renders each pending message with a cancel button whose action handler calls chat.deleteScheduledMessage. Do not change manifest.json unless a new scope is needed, and say so if it is. Add node:test unit tests for schedule.js with a test script, run them, and open a pull request that quotes the output and lists each Slack method used with the scope it needs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `app.js` (two message listeners and one action handler), adds `schedule.js` and `schedule.test.js`, and adds a `test` script to `package.json`. Its description quotes the `node --test` output and has a table of the three Slack methods used, `chat.scheduleMessage`, `chat.scheduledMessages.list` and `chat.deleteScheduledMessage`, each with the scope it needs and whether the manifest already grants it.

A reviewer checks that `post_at` is in seconds rather than milliseconds, which is the most common mistake with this method, that the 120-day check happens before the API call, and that the cancel button carries the `scheduled_message_id` in its `value` rather than in the button text. They also confirm that the regex does not swallow ordinary messages that happen to start with the word remind.

Once merged and restarted with the same two tokens, the bot answers a reminder request with a confirmation and posts the text at the scheduled time without the app process needing to stay up for it, since Slack holds the schedule.

## Run it on every pull request that changes app.js

An automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` runs on each change to `app.js` and reads the diff for new `client.chat.*` calls. An automation's run is read-only, so it posts a review comment that names any call whose scope the manifest does not grant, or any `post_at` computed in milliseconds, and leaves the fix to the author.

For a company with several Bolt apps, a handler on the reader's own server sends this body once per repository to `POST /o/{org}/sessions`, with the repository in `resources` and a `request_id` that is a UUID v5 of the repository name, so a retried loop returns the run it already started. Each run reads its own `manifest.json` and says whether a reinstall is needed.

## Why run it on Rush?

The Slack rules for this method, the 120-day horizon, the per-channel burst limit, the seconds-not-milliseconds timestamp, are the kind of thing that only shows up at runtime. The agent reads the method documentation, encodes each rule in the pure module, writes the tests that pin them, and keeps the test output with the pull request, so the reviewer is checking a diff rather than remembering the API.

A sample app with no test runner is where mistakes hide longest. Running the change in a sandbox that installs dependencies from `package-lock.json`, runs `node --test`, and records every command gives a small repository the same evidence trail as a large one.

## Frequently asked questions

### Does the app need new scopes?

No. `chat.scheduleMessage`, `chat.scheduledMessages.list` and `chat.deleteScheduledMessage` all work with `chat:write`, which `manifest.json` already grants the bot, and the listeners rely on the `message.channels` and `message.im` events it already subscribes to. The pull request says so explicitly so nobody reinstalls the app for nothing.

### How far ahead can a message be scheduled?

Up to 120 days. The `schedule.js` module refuses anything past that before calling Slack, and it also maps the `time_too_far` and `time_in_past` errors to plain replies in case the clock on the host disagrees with Slack's.

### What happens if someone schedules many reminders at once?

Slack refuses more than 30 scheduled posts within the same five-minute window in one channel and answers `restricted_too_many`. The listener catches that error and replies with the limit instead of logging a stack trace.

### Does the app have to stay running for the message to post?

No. Once `chat.scheduleMessage` returns a `scheduled_message_id`, Slack delivers the message at `post_at` on its own. The app only needs to be up to accept new requests and to cancel pending ones.

### Why node:test rather than Jest?

The repository has one dependency and no test tooling, and Dependabot auto-merges updates. Using Node's built-in runner adds no package and nothing for Dependabot to churn, and the `node --test` script runs on the Node version the README assumes.

## More Slack Bolt jobs

- [Add a Slash Command With a Modal to a Slack Bolt App](https://getrush.ai/run/add-slash-command/slack-bolt/)
- [Add Structured Logging to a Slack Bolt App](https://getrush.ai/run/add-structured-logging/slack-bolt/)
- [Convert a Bolt for JavaScript Slack App to TypeScript](https://getrush.ai/run/convert-javascript-to-typescript/slack-bolt/)

## More jobs like this: Hand off a long task

- [Add a Schedule to a Dagster Project](https://getrush.ai/run/add-schedules/dagster/)
- [Add Search Autocomplete to a Wagtail Site](https://getrush.ai/run/add-search-autocomplete/wagtail/)
- [Add Search to a Hugo Site](https://getrush.ai/run/add-search/hugo/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
