afterhours-shift-manager/src/handler.py
Adam Moussa 7b2275a430
Post shift change notifications to the schedule channel (#21) (#22)
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
2026-05-01 14:15:56 -04:00

41 lines
1.3 KiB
Python

"""Lambda handler — Slack Bolt app entry point."""
import logging
import os
import boto3
from slack_bolt.adapter.aws_lambda import SlackRequestHandler
from src.app import create_app
logger = logging.getLogger()
logger.setLevel(logging.INFO)
SlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s: %(message)s", level=logging.INFO)
# Lazy-initialized app singleton
_slack_handler = None
def _get_handler() -> SlackRequestHandler:
global _slack_handler
if _slack_handler is None:
ssm = boto3.client("ssm")
bot_token = ssm.get_parameter(
Name=os.environ["SLACK_BOT_TOKEN_PARAM"], WithDecryption=True
)["Parameter"]["Value"]
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, schedule_channel=schedule_channel)
_slack_handler = SlackRequestHandler(app=app)
return _slack_handler
def handler(event, context):
return _get_handler().handle(event, context)