Skip to content
Latchkey

Slack chat.postMessage "not_in_channel" error in CI

The Slack Web API returns ok:false with error:"not_in_channel" when a bot token calls chat.postMessage for a channel the bot has not joined. Posting with a bot token requires the bot to be a member of that channel (public channels included).

What this error means

The notify step calls chat.postMessage and Slack responds HTTP 200 with a JSON body {"ok":false,"error":"not_in_channel"}. No message appears in the channel.

Slack API
{"ok":false,"error":"not_in_channel"}

Common causes

The bot was never invited to the channel

Unlike incoming webhooks, chat.postMessage with a bot token only works in channels the bot has joined. A new channel or a renamed one leaves the bot outside.

The channel ID points to a different channel

A hard-coded channel ID that was archived or recreated no longer matches a channel the bot is in.

How to fix it

Invite the bot to the channel

  1. Open the target Slack channel.
  2. Run /invite @your-bot-name so the bot becomes a member.
  3. Re-run the notify step; postMessage now succeeds.
Slack
/invite @ci-bot

Join programmatically for public channels

A bot with channels:join can add itself to a public channel before posting.

Terminal
curl -sS -X POST https://slack.com/api/conversations.join \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H 'Content-type: application/json; charset=utf-8' \
  --data '{"channel":"C0123456789"}'

How to prevent it

  • Invite the CI bot to every channel it must post to, before wiring the workflow.
  • Reference channels by stable ID and keep an eye on archives/recreations.
  • Grant channels:join if the bot should self-add to public channels.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →