Skip to content

Commit 743af12

Browse files
committed
feat: add assistant_thread_started event listener with suggested prompts
1 parent db246f7 commit 743af12

6 files changed

Lines changed: 86 additions & 0 deletions

File tree

claude-agent-sdk/listeners/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
from .app_home_opened import handle_app_home_opened
44
from .app_mentioned import handle_app_mentioned
5+
from .assistant_thread_started import handle_assistant_thread_started
56
from .message_im import handle_message_im
67

78

89
def register(app: AsyncApp):
910
app.event("app_home_opened")(handle_app_home_opened)
1011
app.event("app_mention")(handle_app_mentioned)
12+
app.event("assistant_thread_started")(handle_assistant_thread_started)
1113
app.event("message")(handle_message_im)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from logging import Logger
2+
3+
from slack_sdk.web.async_client import AsyncWebClient
4+
5+
SUGGESTED_PROMPTS = [
6+
{"title": "Reset Password", "message": "I need to reset my password"},
7+
{"title": "Request Access", "message": "I need access to a system or tool"},
8+
{"title": "Network Issues", "message": "I'm having network connectivity issues"},
9+
]
10+
11+
12+
async def handle_assistant_thread_started(
13+
client: AsyncWebClient, event: dict, logger: Logger
14+
):
15+
"""Handle assistant thread started events by setting suggested prompts."""
16+
assistant_thread = event.get("assistant_thread", {})
17+
channel_id = assistant_thread.get("channel_id")
18+
thread_ts = assistant_thread.get("thread_ts")
19+
20+
try:
21+
await client.assistant_threads_setSuggestedPrompts(
22+
channel_id=channel_id,
23+
thread_ts=thread_ts,
24+
title="How can I help you today?",
25+
prompts=SUGGESTED_PROMPTS,
26+
)
27+
except Exception as e:
28+
logger.exception(f"Failed to handle assistant thread started: {e}")

openai-agents-sdk/listeners/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
from .app_home_opened import handle_app_home_opened
44
from .app_mentioned import handle_app_mentioned
5+
from .assistant_thread_started import handle_assistant_thread_started
56
from .message_im import handle_message_im
67

78

89
def register(app: App):
910
app.event("app_home_opened")(handle_app_home_opened)
1011
app.event("app_mention")(handle_app_mentioned)
12+
app.event("assistant_thread_started")(handle_assistant_thread_started)
1113
app.event("message")(handle_message_im)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from logging import Logger
2+
3+
from slack_sdk import WebClient
4+
5+
SUGGESTED_PROMPTS = [
6+
{"title": "Reset Password", "message": "I need to reset my password"},
7+
{"title": "Request Access", "message": "I need access to a system or tool"},
8+
{"title": "Network Issues", "message": "I'm having network connectivity issues"},
9+
]
10+
11+
12+
def handle_assistant_thread_started(client: WebClient, event: dict, logger: Logger):
13+
"""Handle assistant thread started events by setting suggested prompts."""
14+
assistant_thread = event.get("assistant_thread", {})
15+
channel_id = assistant_thread.get("channel_id")
16+
thread_ts = assistant_thread.get("thread_ts")
17+
18+
try:
19+
client.assistant_threads_setSuggestedPrompts(
20+
channel_id=channel_id,
21+
thread_ts=thread_ts,
22+
title="How can I help you today?",
23+
prompts=SUGGESTED_PROMPTS,
24+
)
25+
except Exception as e:
26+
logger.exception(f"Failed to handle assistant thread started: {e}")

pydantic-ai/listeners/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
from .app_home_opened import handle_app_home_opened
44
from .app_mentioned import handle_app_mentioned
5+
from .assistant_thread_started import handle_assistant_thread_started
56
from .message_im import handle_message_im
67

78

89
def register(app: App):
910
app.event("app_home_opened")(handle_app_home_opened)
1011
app.event("app_mention")(handle_app_mentioned)
12+
app.event("assistant_thread_started")(handle_assistant_thread_started)
1113
app.event("message")(handle_message_im)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from logging import Logger
2+
3+
from slack_sdk import WebClient
4+
5+
SUGGESTED_PROMPTS = [
6+
{"title": "Reset Password", "message": "I need to reset my password"},
7+
{"title": "Request Access", "message": "I need access to a system or tool"},
8+
{"title": "Network Issues", "message": "I'm having network connectivity issues"},
9+
]
10+
11+
12+
def handle_assistant_thread_started(client: WebClient, event: dict, logger: Logger):
13+
"""Handle assistant thread started events by setting suggested prompts."""
14+
assistant_thread = event.get("assistant_thread", {})
15+
channel_id = assistant_thread.get("channel_id")
16+
thread_ts = assistant_thread.get("thread_ts")
17+
18+
try:
19+
client.assistant_threads_setSuggestedPrompts(
20+
channel_id=channel_id,
21+
thread_ts=thread_ts,
22+
title="How can I help you today?",
23+
prompts=SUGGESTED_PROMPTS,
24+
)
25+
except Exception as e:
26+
logger.exception(f"Failed to handle assistant thread started: {e}")

0 commit comments

Comments
 (0)