Skip to content

Commit

Permalink
Add handler for block_actions interactions
Browse files Browse the repository at this point in the history
These will be interactions from e.g. choosing a template from a static
select menu.
  • Loading branch information
jonathansick committed Sep 24, 2024
1 parent aaa039c commit c09e353
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/templatebot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ class Config(BaseSettings):
),
)

interaction_topic: str = Field(
"squarebot.interaction",
title="interaction Kafka topic",
description=("Kafka topic name for `interaction` Slack events"),
block_actions_topic: str = Field(
"squarebot.block-actions",
description=(
"Kafka topic name for Slack block actions interaction "
"Slack events"
),
)

model_config = SettingsConfigDict(
Expand Down
18 changes: 18 additions & 0 deletions src/templatebot/handlers/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from faststream.security import BaseSecurity
from rubin.squarebot.models.kafka import (
SquarebotSlackAppMentionValue,
SquarebotSlackBlockActionsValue,
SquarebotSlackMessageValue,
)
from structlog import get_logger
Expand Down Expand Up @@ -68,3 +69,20 @@ async def handle_slack_app_mention(

message_service = factory.create_slack_message_service()
await message_service.handle_app_mention(message)


@kafka_router.subscriber(
config.block_actions_topic,
group_id=f"{config.consumer_group_id}-block-actions",
)
async def handle_slack_block_actions(
payload: SquarebotSlackBlockActionsValue,
context: Annotated[ConsumerContext, Depends(consumer_context_dependency)],
) -> None:
"""Handle a Slack block_actions interaction."""
logger = context.logger

logger.debug(
"Got Slack block_actions",
actions=payload.actions[0].model_dump(mode="json"),
)

0 comments on commit c09e353

Please sign in to comment.