Skip to content

Commit

Permalink
skip DMs
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Oct 21, 2024
1 parent ba984e1 commit c90be54
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cookbook/slackbot/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,18 @@ async def chat_endpoint(request: Request):
raise HTTPException(400, "Invalid event type")
match payload.type:
case "event_callback":
options = dict(
flow_run_name=(
"respond in"
f" {await get_channel_name(payload.event.channel)}/{payload.event.thread_ts}"
channel_name = await get_channel_name(payload.event.channel)
if channel_name.startswith("D"):
# This is a DM channel, we should not respond
logger.warning(f"Attempted to respond in DM channel: {channel_name}")
slack_webhook = await SlackWebhook.load("marvin-bot-pager")
await slack_webhook.notify(
body=f"Attempted to respond in DM channel: {channel_name}",
subject="Slackbot DM Warning",
)
return Completed(message="Skipped DM channel", name="SKIPPED")
options = dict(
flow_run_name=f"respond in {channel_name}/{payload.event.thread_ts}"
)
asyncio.create_task(handle_message.with_options(**options)(payload))
case "url_verification":
Expand Down

0 comments on commit c90be54

Please sign in to comment.