Slack bot for managing after-hours on-call shifts with 3CX integration
Find a file
Adam Moussa efa4bc569d
Some checks failed
Deploy / deploy (push) Has been cancelled
INFRA-28: add HTTP API access logging and throttling (audit M-18) (#98)
Add AccessLogSettings on the implicit HTTP API stage pointing at a new
/aws/apigateway/afterhours-shift-manager log group with 90-day retention,
plus DefaultRouteSettings throttling (100 rps / 50 burst). Mirrors the
M-18 pattern landed on payments-dashboard.
2026-06-05 17:47:41 -04:00
.github Add dependency-review caller workflow (#97) 2026-06-05 12:26:41 -04:00
scripts Initial commit: after-hours shift manager Slack bot 2026-04-03 18:32:32 -04:00
src Update boto3 requirement from >=1.43.19 to >=1.43.22 in /src/weekly-post (#96) 2026-06-04 01:00:31 +00:00
tests Lock shift drops within 24h of start (#84) (#88) 2026-06-01 19:32:40 -04:00
.gitignore Add pytest suite and wire it into CI (#85) (#86) 2026-06-01 19:07:08 -04:00
CHANGELOG.md Add a plain-language changelog from inception (#91) 2026-06-01 20:02:17 -04:00
pyproject.toml Add pytest suite and wire it into CI (#85) (#86) 2026-06-01 19:07:08 -04:00
README.md Lock shift drops within 24h of start (#84) (#88) 2026-06-01 19:32:40 -04:00
samconfig.toml.example Merge ring-scheduler-3cx and resolve all open issues (#62) 2026-05-12 19:55:39 -04:00
SETUP.md Fix SETUP.md to use Secrets Manager, not SSM (compliance #68) (#89) 2026-06-01 19:46:47 -04:00
template.yaml INFRA-28: add HTTP API access logging and throttling (audit M-18) (#98) 2026-06-05 17:47:41 -04:00

After-Hours Shift Manager

Slack bot for managing after-hours on-call shifts at Sea Haven Industries. Employees can pick up, drop, and swap shifts directly from Slack. Changes automatically update 3CX queue routing via the integrated ring scheduler.

How It Works

A recurring weekly schedule assigns employees to after-hours phone duty. Weekend shifts are split into Day (8am-5pm) and Night (5pm-8am). Any unassigned shift shows as Available in Slack with a pickup button. When someone picks up or drops a shift for today, the 3CX queue is updated immediately. Future changes take effect when the ring scheduler runs at 8am daily and 5pm on weekends.

The weekly schedule post is updated live when shifts change, and the previous week's post is automatically deleted when the new one goes out.

Slack Commands

Command Description
/oncall Show this week's schedule
/oncall next Show next week's schedule
/oncall pick <date> Pick up an available shift
/oncall drop <date> Drop your shift (marks it available) — blocked within 24h of shift start; swap or ask an admin instead
/oncall swap <date> @person Request a swap — the other person gets an Accept/Decline DM and the shift only moves once they accept
/oncall register <ext> Link your Slack account to your phone extension
/oncall roster Show all employees and their link status
/oncall pay Show last week's bonus pay summary
/oncall rate Show current shift pay rates
/oncall rate default <amount> Set the default per-shift rate
/oncall rate <ext> <amount> Set a per-person shift rate
/oncall help Show help

Admin Commands

Available to users listed in admin_users in the CONFIG record:

Command Description
/oncall admin override <date> <ext> Assign a shift to an extension
/oncall admin open <date> Mark a shift as open
/oncall admin clear <date> Remove override (revert to weekly)
/oncall admin roster add <ext> <name> Add an employee to the roster
/oncall admin roster remove <ext> Remove an employee
/oncall admin roster rename <ext> <name> Rename an employee

Dates accept: today, tomorrow, monday-sunday, 4/5, 2026-04-05

Architecture

  • Runtime: Python 3.12 on AWS Lambda (arm64)
  • Data: DynamoDB single-table (afterhours-shifts)
  • IaC: AWS SAM (template.yaml) with shared Lambda Layer
  • Slack: Slack Bolt framework with /oncall slash command
  • 3CX Integration: Queue routing updated directly via 3CX Queue XAPI
  • Secrets: AWS Secrets Manager (afterhours-shift-manager/*)

Lambda Functions

Function Trigger Purpose
afterhours-shift-manager API Gateway (POST /slack/events) Slack bot — handles /oncall commands and interactive buttons
afterhours-weekly-post EventBridge (Monday 7am ET) Posts weekly schedule to Slack, sends pay report email
afterhours-roster-sync EventBridge (daily 6am ET) Syncs employee roster from 3CX
afterhours-ring-scheduler EventBridge (daily 8am ET + weekend 5pm ET) Updates 3CX queue routing based on who's on shift

Project Layout

src/
  slack-bot/        Slack Bolt Lambda (handler + app)
  weekly-post/      Monday schedule + pay post
  roster-sync/      Daily 3CX roster sync
  ring-scheduler/   3CX queue routing updates
  shared/           Lambda Layer (schedule, blocks, 3CX client, secrets)
tests/              pytest suite (mirrors src/, one dir per Lambda + shared)

DynamoDB Schema

Single table with PK / SK keys:

PK SK Description
ROSTER <extension> Employee: name, extension, slack_user_id
WEEKLY <DayName> Default weekly schedule: extension, name
OVERRIDE <YYYY-MM-DD> Date override from pickup/drop (or OPEN)
SWAP <YYYY-MM-DD> Pending/verified swap request: requester, target, status, expires_at (TTL)
SCHEDULE_POST <channel_id> Current schedule message timestamp
PAY <YYYY-MM-DD> Weekly pay record (Monday date key)
CONFIG CONFIG Settings: shift_rate, fallback_extension, admin_users

Weekend day-shift rows use a -DAY suffix on the SK (e.g. OVERRIDE / 2026-04-05-DAY). The table has TTL enabled on expires_at so abandoned pending swaps self-clean.

Swap flow: /oncall swap writes a pending SWAP record and DMs the target Accept/Decline buttons; it does not reassign the shift. On Accept, the override is written, 3CX is repointed if it's the active shift, and the record is marked verified. On Decline (or once the shift has started) the request is dropped and the shift stays with the original owner.

Secrets Manager

Secret Description
afterhours-shift-manager/slack-bot-token Slack bot OAuth token (xoxb-...)
afterhours-shift-manager/slack-signing-secret Slack app signing secret
afterhours-shift-manager/3cx-domain 3CX FQDN (e.g. company.3cx.us)
afterhours-shift-manager/3cx-client-id 3CX OAuth2 client ID
afterhours-shift-manager/3cx-client-secret 3CX OAuth2 client secret

Deployment

Merges to main are automatically deployed via GitHub Actions using reusable SAM workflows from the Sea Haven org.

For manual deploys:

sam build
sam deploy

Testing

Unit tests use pytest with all external boundaries mocked — DynamoDB / SES / Secrets Manager via moto, 3CX HTTP via responses, Slack via fakes, and time via freezegun. No test touches the network or real AWS.

python -m venv .venv && source .venv/bin/activate
pip install -r tests/requirements.txt              # test-only deps
pip install -r src/slack-bot/requirements.txt \
            -r src/weekly-post/requirements.txt \
            -r src/shared/requirements.txt          # runtime deps the imports need
pytest

Each Lambda has its own app.py, so the per-package conftest.py loads each one under a unique module name (importlib mode) to avoid collisions. CI runs the same suite on every PR via the org ci-python-sam workflow (run-tests: true).

See SETUP.md for full deployment and Slack app creation instructions.