Skip to content

Commit 2890ab4

Browse files
srtaalejzimegmwbrooks
authored
build: bump slack sdk and bolt to latest release (#22)
* build: bump slack sdk and bolt to latest release * fix: remove channel summary functionality * chore: update scopes in manifest.json * fix: remove users:read scope * fix: remove message.channels event Co-authored-by: Michael Brooks <mbrooks@slack-corp.com> --------- Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com> Co-authored-by: Michael Brooks <mbrooks@slack-corp.com>
1 parent b2a270a commit 2890ab4

3 files changed

Lines changed: 14 additions & 54 deletions

File tree

listeners/assistant/assistant.py

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
from typing import Dict, List
33

44
from slack_bolt import Assistant, BoltContext, Say, SetStatus, SetSuggestedPrompts
5-
from slack_bolt.context.get_thread_context import GetThreadContext
65
from slack_sdk import WebClient
7-
from slack_sdk.errors import SlackApiError
86

97
from ai.llm_caller import call_llm
108

@@ -17,7 +15,6 @@
1715
@assistant.thread_started
1816
def start_assistant_thread(
1917
say: Say,
20-
get_thread_context: GetThreadContext,
2118
set_suggested_prompts: SetSuggestedPrompts,
2219
logger: Logger,
2320
):
@@ -26,7 +23,6 @@ def start_assistant_thread(
2623
2724
Args:
2825
say: Function to send messages to the thread from the app
29-
get_thread_context: Function to retrieve thread context information
3026
set_suggested_prompts: Function to configure suggested prompt options
3127
logger: Logger instance for error tracking
3228
"""
@@ -48,14 +44,6 @@ def start_assistant_thread(
4844
},
4945
]
5046

51-
thread_context = get_thread_context()
52-
if thread_context is not None and thread_context.channel_id is not None:
53-
summarize_channel = {
54-
"title": "Summarize the referred channel",
55-
"message": "Can you generate a brief summary of the referred channel?",
56-
}
57-
prompts.append(summarize_channel)
58-
5947
set_suggested_prompts(prompts=prompts)
6048
except Exception as e:
6149
logger.exception(f"Failed to handle an assistant_thread_started event: {e}", e)
@@ -67,7 +55,6 @@ def start_assistant_thread(
6755
def respond_in_assistant_thread(
6856
client: WebClient,
6957
context: BoltContext,
70-
get_thread_context: GetThreadContext,
7158
logger: Logger,
7259
payload: dict,
7360
say: Say,
@@ -79,7 +66,6 @@ def respond_in_assistant_thread(
7966
Args:
8067
client: Slack WebClient for making API calls
8168
context: Bolt context containing channel and thread information
82-
get_thread_context: Function to retrieve thread context (e.g., referred channel)
8369
logger: Logger instance for error tracking
8470
payload: Event payload with message details (channel, user, text, etc.)
8571
say: Function to send messages to the thread
@@ -90,7 +76,6 @@ def respond_in_assistant_thread(
9076
team_id = context.team_id
9177
thread_ts = payload["thread_ts"]
9278
user_id = context.user_id
93-
user_message = payload["text"]
9479

9580
set_status(
9681
status="thinking...",
@@ -103,36 +88,16 @@ def respond_in_assistant_thread(
10388
],
10489
)
10590

106-
if user_message == "Can you generate a brief summary of the referred channel?":
107-
thread_context = get_thread_context()
108-
referred_channel_id = thread_context.get("channel_id")
109-
try:
110-
channel_history = client.conversations_history(channel=referred_channel_id, limit=50)
111-
except SlackApiError as e:
112-
if e.response["error"] == "not_in_channel":
113-
# If this app's bot user is not in the public channel,
114-
# we'll try joining the channel and then calling the same API again
115-
client.conversations_join(channel=referred_channel_id)
116-
channel_history = client.conversations_history(channel=referred_channel_id, limit=50)
117-
else:
118-
raise e
119-
prompt = f"Can you generate a brief summary of these messages in a Slack channel <#{referred_channel_id}>?\n\n"
120-
for message in reversed(channel_history.get("messages")):
121-
if message.get("user") is not None:
122-
prompt += f"\n<@{message['user']}> says: {message['text']}\n"
123-
messages_in_thread = [{"role": "user", "content": prompt}]
124-
125-
else:
126-
replies = client.conversations_replies(
127-
channel=context.channel_id,
128-
ts=context.thread_ts,
129-
oldest=context.thread_ts,
130-
limit=10,
131-
)
132-
messages_in_thread: List[Dict[str, str]] = []
133-
for message in replies["messages"]:
134-
role = "user" if message.get("bot_id") is None else "assistant"
135-
messages_in_thread.append({"role": role, "content": message["text"]})
91+
replies = client.conversations_replies(
92+
channel=context.channel_id,
93+
ts=context.thread_ts,
94+
oldest=context.thread_ts,
95+
limit=10,
96+
)
97+
messages_in_thread: List[Dict[str, str]] = []
98+
for message in replies["messages"]:
99+
role = "user" if message.get("bot_id") is None else "assistant"
100+
messages_in_thread.append({"role": role, "content": message["text"]})
136101

137102
returned_message = call_llm(messages_in_thread)
138103

manifest.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222
"bot": [
2323
"app_mentions:read",
2424
"assistant:write",
25-
"channels:join",
2625
"im:history",
27-
"channels:history",
2826
"channels:read",
29-
"groups:history",
30-
"chat:write",
31-
"users:read"
27+
"chat:write"
3228
]
3329
}
3430
},
@@ -38,8 +34,7 @@
3834
"assistant_thread_context_changed",
3935
"assistant_thread_started",
4036
"message.im",
41-
"app_mention",
42-
"message.channels"
37+
"app_mention"
4338
]
4439
},
4540
"interactivity": {

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
slack-sdk==3.36.0.dev6
2-
slack-bolt==1.26.0.dev3
1+
slack-sdk==3.37.0
2+
slack-bolt==1.26.0
33

44
# If you use a different LLM vendor, replace this dependency
55
openai

0 commit comments

Comments
 (0)