From 7b2275a43089287ffd615680397e502f1ce71a99 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Fri, 1 May 2026 14:15:56 -0400 Subject: [PATCH] Post shift change notifications to the schedule channel (#21) (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Slash command handlers (drop, pick, swap) were posting notifications to command["channel_id"] — wherever the command was run. If someone ran /oncall drop from a DM, the notification went there instead of the schedule channel. Pickup buttons didn't have this problem because body["channel"]["id"] is always the channel where the button lives. Added SHIFT_CHANNEL_PARAM to the SlackBotFunction env vars, read it on cold start, and route all slash command shift-change notifications to the configured schedule channel. Closes #21 --- src/app.py | 8 ++++---- src/handler.py | 5 ++++- template.yaml | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app.py b/src/app.py index 0116b35..e5c7e45 100644 --- a/src/app.py +++ b/src/app.py @@ -78,7 +78,7 @@ def is_today(date_str: str) -> bool: return date_str == datetime.now(EASTERN).strftime("%Y-%m-%d") -def create_app(bot_token: str, signing_secret: str) -> App: +def create_app(bot_token: str, signing_secret: str, schedule_channel: str | None = None) -> App: app = App( token=bot_token, signing_secret=signing_secret, @@ -110,11 +110,11 @@ def create_app(bot_token: str, signing_secret: str) -> App: elif text.startswith("register"): _handle_register(respond, schedule, user_id, text) elif text.startswith("pick"): - _handle_pick(respond, schedule, user_id, text, channel_id, client) + _handle_pick(respond, schedule, user_id, text, schedule_channel or channel_id, client) elif text.startswith("drop"): - _handle_drop(respond, schedule, user_id, text, channel_id, client) + _handle_drop(respond, schedule, user_id, text, schedule_channel or channel_id, client) elif text.startswith("swap"): - _handle_swap(respond, schedule, user_id, text, channel_id, client) + _handle_swap(respond, schedule, user_id, text, schedule_channel or channel_id, client) else: respond(text="Unknown command. Try `/oncall help`") diff --git a/src/handler.py b/src/handler.py index 4cd7dbd..fe6abe3 100644 --- a/src/handler.py +++ b/src/handler.py @@ -28,8 +28,11 @@ def _get_handler() -> SlackRequestHandler: signing_secret = ssm.get_parameter( Name=os.environ["SLACK_SIGNING_SECRET_PARAM"], WithDecryption=True )["Parameter"]["Value"] + schedule_channel = ssm.get_parameter( + Name=os.environ["SHIFT_CHANNEL_PARAM"], WithDecryption=True + )["Parameter"]["Value"] - app = create_app(bot_token, signing_secret) + app = create_app(bot_token, signing_secret, schedule_channel=schedule_channel) _slack_handler = SlackRequestHandler(app=app) return _slack_handler diff --git a/template.yaml b/template.yaml index 3f387e9..feaa664 100644 --- a/template.yaml +++ b/template.yaml @@ -47,6 +47,7 @@ Resources: SHIFT_TABLE: !Ref ShiftTable SLACK_BOT_TOKEN_PARAM: /afterhours-shift-manager/slack-bot-token SLACK_SIGNING_SECRET_PARAM: /afterhours-shift-manager/slack-signing-secret + SHIFT_CHANNEL_PARAM: /afterhours-shift-manager/channel-id SCHEDULER_FUNCTION_NAME: !Ref SchedulerFunctionName TZ: !Ref Timezone Policies: