Add Codex target commands and session routing
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
|
||||
from slack_bolt import App
|
||||
from slack_bolt.adapter.socket_mode import SocketModeHandler
|
||||
@@ -22,8 +23,8 @@ class SlackHandler:
|
||||
self.app = App(token=config.slack_bot_token)
|
||||
self._handler: SocketModeHandler | None = None
|
||||
self._stop_requested = False
|
||||
self._on_message_callback: callable | None = None
|
||||
self._on_command_callback: callable | None = None
|
||||
self._on_message_callback: Callable[[str, str], None] | None = None
|
||||
self._on_command_callback: Callable[[str, str, str], None] | None = None
|
||||
|
||||
self._register_listeners()
|
||||
|
||||
@@ -46,7 +47,7 @@ class SlackHandler:
|
||||
"""Slack 이벤트 리스너를 등록한다."""
|
||||
|
||||
@self.app.event("message")
|
||||
def handle_message(event: dict, say: callable) -> None:
|
||||
def handle_message(event: dict, say: Callable[..., None]) -> None:
|
||||
user_id = event.get("user", "")
|
||||
channel_id = event.get("channel", "")
|
||||
text = event.get("text", "")
|
||||
@@ -58,7 +59,7 @@ class SlackHandler:
|
||||
self._on_message_callback(text, channel_id)
|
||||
|
||||
@self.app.command("/start-claude")
|
||||
def handle_start(ack: callable, body: dict) -> None:
|
||||
def handle_start_claude(ack: Callable[..., None], body: dict) -> None:
|
||||
ack()
|
||||
user_id = body.get("user_id", "")
|
||||
channel_id = body.get("channel_id", "")
|
||||
@@ -67,10 +68,10 @@ class SlackHandler:
|
||||
return
|
||||
|
||||
if self._on_command_callback:
|
||||
self._on_command_callback("start", channel_id)
|
||||
self._on_command_callback("start", "claude", channel_id)
|
||||
|
||||
@self.app.command("/stop-claude")
|
||||
def handle_stop(ack: callable, body: dict) -> None:
|
||||
def handle_stop_claude(ack: Callable[..., None], body: dict) -> None:
|
||||
ack()
|
||||
user_id = body.get("user_id", "")
|
||||
channel_id = body.get("channel_id", "")
|
||||
@@ -79,13 +80,37 @@ class SlackHandler:
|
||||
return
|
||||
|
||||
if self._on_command_callback:
|
||||
self._on_command_callback("stop", channel_id)
|
||||
self._on_command_callback("stop", "claude", channel_id)
|
||||
|
||||
def on_message(self, callback: callable) -> None:
|
||||
@self.app.command("/start-codex")
|
||||
def handle_start_codex(ack: Callable[..., None], body: dict) -> None:
|
||||
ack()
|
||||
user_id = body.get("user_id", "")
|
||||
channel_id = body.get("channel_id", "")
|
||||
|
||||
if not self._is_authorized(user_id, channel_id):
|
||||
return
|
||||
|
||||
if self._on_command_callback:
|
||||
self._on_command_callback("start", "codex", channel_id)
|
||||
|
||||
@self.app.command("/stop-codex")
|
||||
def handle_stop_codex(ack: Callable[..., None], body: dict) -> None:
|
||||
ack()
|
||||
user_id = body.get("user_id", "")
|
||||
channel_id = body.get("channel_id", "")
|
||||
|
||||
if not self._is_authorized(user_id, channel_id):
|
||||
return
|
||||
|
||||
if self._on_command_callback:
|
||||
self._on_command_callback("stop", "codex", channel_id)
|
||||
|
||||
def on_message(self, callback: Callable[[str, str], None]) -> None:
|
||||
"""메시지 수신 콜백을 등록한다."""
|
||||
self._on_message_callback = callback
|
||||
|
||||
def on_command(self, callback: callable) -> None:
|
||||
def on_command(self, callback: Callable[[str, str, str], None]) -> None:
|
||||
"""슬래시 커맨드 콜백을 등록한다."""
|
||||
self._on_command_callback = callback
|
||||
|
||||
|
||||
Reference in New Issue
Block a user