Skip to content

Commit dda8c83

Browse files
authored
feat: replace assistant handlers with agent argument methods (#51)
* feat: replace assistant handlers with agent argument methods * refactor: remove unused parameters from listeners
1 parent 55657d6 commit dda8c83

3 files changed

Lines changed: 15 additions & 31 deletions

File tree

listeners/assistant/assistant_thread_started.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from logging import Logger
22

3-
from slack_bolt import Say, SetSuggestedPrompts
3+
from slack_bolt import BoltAgent, Say
44

55

66
def assistant_thread_started(
7-
say: Say,
8-
set_suggested_prompts: SetSuggestedPrompts,
7+
agent: BoltAgent,
98
logger: Logger,
9+
say: Say,
1010
):
1111
"""
1212
Handle the assistant thread start event by greeting the user and setting suggested prompts.
@@ -18,7 +18,7 @@ def assistant_thread_started(
1818
"""
1919
try:
2020
say("What would you like to do today?")
21-
set_suggested_prompts(
21+
agent.set_suggested_prompts(
2222
prompts=[
2323
{
2424
"title": "Prompt a task with thinking steps",

listeners/assistant/message.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from logging import Logger
33

44
from openai.types.responses import ResponseInputParam
5-
from slack_bolt import BoltAgent, BoltContext, Say, SetStatus
6-
from slack_sdk import WebClient
5+
from slack_bolt import BoltAgent, Say
76
from slack_sdk.models.messages.chunk import (
87
MarkdownTextChunk,
98
PlanUpdateChunk,
@@ -16,36 +15,24 @@
1615

1716
def message(
1817
agent: BoltAgent,
19-
client: WebClient,
20-
context: BoltContext,
2118
logger: Logger,
2219
message: dict,
23-
payload: dict,
2420
say: Say,
25-
set_status: SetStatus,
2621
):
2722
"""
2823
Handles when users send messages or select a prompt in an assistant thread and generate AI responses:
2924
3025
Args:
3126
agent: BoltAgent for making API calls
32-
client: Slack WebClient for making API calls
33-
context: Bolt context containing channel and thread information
3427
logger: Logger instance for error tracking
35-
payload: Event payload with message details (channel, user, text, etc.)
28+
message: Dictionary with message information
3629
say: Function to send messages to the thread
37-
set_status: Function to update the assistant's status
3830
"""
3931
try:
40-
channel_id = payload["channel"]
41-
team_id = context.team_id
42-
thread_ts = payload["thread_ts"]
43-
user_id = context.user_id
44-
4532
# The first example shows a message with thinking steps that has different
4633
# chunks to construct and update a plan alongside text outputs.
4734
if message["text"] == "Wonder a few deep thoughts.":
48-
set_status(
35+
agent.set_status(
4936
status="thinking...",
5037
loading_messages=[
5138
"Teaching the hamsters to type faster…",
@@ -125,7 +112,7 @@ def message(
125112
# This second example shows a generated text response for a provided prompt
126113
# displayed as a timeline.
127114
else:
128-
set_status(
115+
agent.set_status(
129116
status="thinking...",
130117
loading_messages=[
131118
"Teaching the hamsters to type faster…",

listeners/events/app_mentioned.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@
22

33
from openai.types.responses import ResponseInputParam
44
from slack_bolt import BoltAgent, Say
5-
from slack_sdk import WebClient
65

76
from agent.llm_caller import call_llm
87
from listeners.views.feedback_block import create_feedback_block
98

109

11-
def app_mentioned_callback(agent: BoltAgent, client: WebClient, event: dict, logger: Logger, say: Say):
10+
def app_mentioned_callback(
11+
agent: BoltAgent,
12+
event: dict,
13+
logger: Logger,
14+
say: Say,
15+
):
1216
"""
1317
Handles the event when the app is mentioned in a Slack conversation
1418
and generates an AI response.
1519
1620
Args:
1721
agent: BoltAgent for making API calls
18-
client: Slack WebClient for making API calls
1922
event: Event payload containing mention details (channel, user, text, etc.)
2023
logger: Logger instance for error tracking
2124
say: Function to send messages to the thread from the app
2225
"""
2326
try:
24-
channel_id = event.get("channel")
25-
team_id = event.get("team")
2627
text = event.get("text")
27-
thread_ts = event.get("thread_ts") or event.get("ts")
28-
user_id = event.get("user")
2928

30-
client.assistant_threads_setStatus(
31-
channel_id=channel_id,
32-
thread_ts=thread_ts,
29+
agent.set_status(
3330
status="thinking...",
3431
loading_messages=[
3532
"Teaching the hamsters to type faster…",

0 commit comments

Comments
 (0)