Slack
People talk to kōjō in Slack by direct message or by mentioning the bot in a channel. kōjō answers in the thread and asks for approvals with buttons.
See Surfaces for how Slack compares with the other chat platforms, and Who may trigger what for what a request may do, depending on who sent it.
How it connects
| Mode | How Slack reaches kōjō | Needs |
|---|---|---|
socket (default) |
kōjō opens a Socket Mode WebSocket to Slack. No public ingress. | bot_token, app_token |
http |
Slack posts to <public_url>/slack/events and <public_url>/slack/interactive. The public URL must be https. |
bot_token, signing_secret |
In http mode every request is checked against Slack’s v0 signature: the HMAC-SHA256 of v0:<timestamp>:<body> with the signing secret, in X-Slack-Signature, with a timestamp no more than 5 minutes from now. A request that fails gets 401. Bodies are limited to 1 MiB.
Delivery is at least once in both modes. kōjō acknowledges an event once it has accepted it and drops the repeats Slack sends afterwards.
Set up
-
Print the app manifest. Socket mode:
kojo setup slack -o slack-manifest.yamlHttp mode:
kojo setup slack --mode http --public-url https://kojo.example.com -o slack-manifest.yamlWithout
-othe manifest goes to stdout. The next steps are printed to stderr. -
At api.slack.com/apps choose Create New App → From a manifest and paste the manifest.
-
Install the app to your workspace and copy the bot token (
xoxb-...). -
Socket mode: create an app-level token (
xapp-...) with theconnections:writescope. Http mode: copy the signing secret. -
Add Slack to
kojo.yaml. Socket mode:chat: slack: mode: socket bot_token: ${SLACK_BOT_TOKEN} app_token: ${SLACK_APP_TOKEN}Http mode:
chat: slack: mode: http bot_token: ${SLACK_BOT_TOKEN} signing_secret: ${SLACK_SIGNING_SECRET} -
In the dashboard under Settings → Access, give the operator role to the people who may trigger code changes and decide approvals from Slack. kōjō matches a Slack user to a kōjō user by the email address of the Slack profile.
-
Run
kojo doctor. It callsauth.testwith the bot token and, in socket mode, checks thatapp_tokenis an app-level token.
| Flag | Default | Meaning |
|---|---|---|
--mode |
socket |
socket or http. |
--public-url |
none | kōjō’s public URL. Required in http mode. |
-o, --output |
stdout | Write the manifest to this file. |
The manifest asks for these bot scopes:
| Scope | Used for |
|---|---|
app_mentions:read |
Receive messages that mention the bot |
chat:write |
Post and update messages |
im:history |
Receive direct messages |
im:read, im:write |
See and open direct message conversations |
users:read, users:read.email |
Resolve a sender’s name and email, which maps the sender onto a kōjō user |
It subscribes to two events, app_mention and message.im, and turns interactivity on for the approval buttons.
Mentions, messages and replies
Write to the bot in plain words, in a direct message or with a mention in a channel. Each message becomes one session, unless it goes to a session already at work in its thread (below), and kōjō replies in the thread of that message.
@kojo why does the nightly build of github/acme/api fail?
kōjō picks the repository this way:
- A repository named in the message as
forge/owner/name, when that repository is enabled. - Otherwise, the only enabled repository, when exactly one is enabled.
- Otherwise the session has no repository.
What the request may do depends on the sender’s role in kōjō, not on anything in Slack. See who may trigger what.
While a session is at work, an operator’s message in its thread goes to that session instead of starting another one: its next step reads it. In a channel the message mentions the bot; in a direct message any reply in the thread counts. A new top-level message is a new session. See Talking to a session at work.
Channel messages that do not mention the bot are ignored. In direct messages, edits and deletions are ignored. Slash commands are not used.
Approvals
When the merge policy asks a human, kōjō posts a message with Approve and Deny buttons in the thread and parks the session until someone clicks or the question’s deadline passes.
| Question | Asked when |
|---|---|
| “Open a pull request?” | The merge policy mode is ask. |
| “Merge this pull request?” | The mode is auto_merge and the change is medium risk. |
| “Create this schedule?” | Someone asked for a recurring job in the conversation. |
Only a user with the operator or admin role decides. A click from anyone else changes nothing: the buttons stay, kōjō says in the thread that the operator role is needed, and the attempt is written to the audit log. The first valid click stands, and the buttons are replaced by the outcome and the name of who decided.
The two questions of the merge policy close at a deadline, which their message states in UTC: the policy’s approval_timeout, 2 hours by default. Without an answer by then, “Open a pull request?” becomes a draft pull request and “Merge this pull request?” leaves the pull request open; the buttons are replaced by “No answer by” and the time, and kōjō says in the thread what it did. A click after the deadline changes nothing, and kōjō replies that it came too late. See No answer. “Create this schedule?” has no deadline.
Schedules
Ask for something to happen on a schedule, for example:
@kojo run security-audit on github/acme/api every Monday at 9:00
The orchestrator proposes a schedule (name, cron expression, skill, repository) and kōjō posts it with the question “Create this schedule?”. It is stored only after an operator or admin approves it, as a new revision of the organization’s schedules. A name that already exists is refused. This is offered only to senders with the operator or admin role. Schedules describes the format.