This project posts high-match opportunity alerts to Slack using the same credential model as Slack CLI / Bolt apps, not Incoming Webhooks (webhooks remain a legacy fallback only).
Docs: Slack CLI · Authorize CLI · Bolt Python tokens
| Variable | Example | Required? | Role |
|---|---|---|---|
SLACK_BOT_TOKEN |
xoxb-... |
Yes (preferred path) | Bot User OAuth token → chat.postMessage |
SLACK_CHANNEL_ID |
C0123ABCD or #bid-alerts-test |
Yes (with bot token) | Where to post |
SLACK_APP_TOKEN |
xapp-... |
Optional | Socket Mode / slack run only; not used for match posts |
SLACK_MATCH_NOTIFY_ENABLED |
true |
Default true | Master switch |
TEAMS_MATCH_SCORE_THRESHOLD |
40 |
Shared with Teams | Min score 0–100 |
SLACK_WEBHOOK_URL |
https://hooks.slack.com/... |
Legacy only | Fallback if bot token unset |
Install SDK:
pip install -e ".[slack]"Windows: follow Install Slack CLI for Windows.
slack version
slack login
# Complete /slackauthticket + challenge in Slack
slack auth listAuth data for the CLI itself lives in ~/.slack/credentials.json (do not commit).
This Python app does not read that file — you still paste app tokens into repo .env (below).
Either:
# Optional: separate Bolt sample app to mint tokens quickly
slack create bid-alerts-app --template slack-samples/bolt-python-getting-started-app
cd bid-alerts-app
slack run
# Select create/install app when promptedOr create an app from api.slack.com/apps / slack app settings for an existing CLI project.
In app settings → OAuth & Permissions → Bot Token Scopes, ensure at least:
chat:write(required)chat:write.public(optional; post to public channels without join)
Reinstall the app to the test workspace after adding scopes.
Invite the bot to the target channel (if private, or if missing chat:write.public):
/invite @YourBotName
| Token | Where in Slack app UI |
|---|---|
Bot User OAuth Token xoxb-... |
OAuth & Permissions → Bot User OAuth Token → env SLACK_BOT_TOKEN |
App-Level Token xapp-... |
Basic Information → App-Level Tokens (connections:write) → env SLACK_APP_TOKEN (only if you also run Bolt Socket Mode) |
In Slack (desktop): channel name → View channel details → bottom Channel ID C...
Or use #channel-name if the bot can resolve it.
# Slack CLI / Bolt config (preferred)
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_CHANNEL_ID=C0123456789
# Optional (not used by match notify):
# SLACK_APP_TOKEN=xapp-your-app-token
SLACK_MATCH_NOTIFY_ENABLED=true
TEAMS_MATCH_SCORE_THRESHOLD=40
# Quiet Teams while testing Slack:
TEAMS_MATCH_NOTIFY_ENABLED=falsecd <repository-root>
.\.venv\Scripts\Activate.ps1
pip install -e ".[slack]"
python -c "from opportunity_ingest.config import get_settings; s=get_settings(); print('web_api', s.slack_web_api_configured()); print('token', bool(s.resolved_slack_bot_token())); print('channel', s.resolved_slack_channel_id()); print('threshold', s.teams_match_score_threshold)"Expect: web_api True, token True, channel set.
python -c @"
from opportunity_ingest.config import get_settings
from opportunity_ingest.notify import post_slack_chat_message
s = get_settings()
post_slack_chat_message(
bot_token=s.resolved_slack_bot_token(),
channel=s.resolved_slack_channel_id(),
text='contractbiddingsystem Slack CLI config OK',
blocks=None,
)
print('posted ok')
"@Message should appear in the configured channel.
TEAMS_MATCH_SCORE_THRESHOLD=1python -m opportunity_ingest interpret-rank --status New --limit 5 --no-sync-sheetsConsole should show slack=True. Then set threshold back to 40.
If you already have a test app:
- Install app to test workspace with
chat:write. - Copy
xoxb-bot token →SLACK_BOT_TOKEN. - Set
SLACK_CHANNEL_ID. - Same verify steps §7–9.
This is still the CLI/Bolt env contract (SLACK_BOT_TOKEN + channel), even if you did not use slack create.
If only a hooks.slack.com URL exists, set:
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...The app logs a warning and uses the webhook. Migrate to bot token when possible.
| Error / symptom | Fix |
|---|---|
slack-sdk not installed |
pip install -e ".[slack]" |
not_authed / invalid_auth |
Wrong/revoked bot token; reinstall app |
channel_not_found |
Bad SLACK_CHANNEL_ID; use C... ID |
not_in_channel |
/invite @bot into channel |
missing_scope |
Add chat:write, reinstall app |
web_api False |
Both token and channel required |
| No post, threshold | Lower TEAMS_MATCH_SCORE_THRESHOLD for test |
- Never commit
.env, tokens, or~/.slack/credentials.json. - Prefer a test workspace / developer sandbox.
- Rotate bot tokens if leaked.