Skip to content

Commit 9221080

Browse files
committed
ref: breakup assistant.py into separate files
1 parent 62122da commit 9221080

File tree

4 files changed

+51
-47
lines changed

4 files changed

+51
-47
lines changed

listeners/assistant/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
from slack_bolt import App
1+
from slack_bolt import App, Assistant
22

3-
from .assistant import assistant
3+
from .assistant_thread_started import start_assistant_thread
4+
from .message import respond_in_assistant_thread
45

56

7+
# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details on the Assistant class
68
def register(app: App):
9+
assistant = Assistant()
10+
11+
assistant.thread_started(start_assistant_thread)
12+
assistant.user_message(respond_in_assistant_thread)
13+
714
app.assistant(assistant)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from logging import Logger
2+
from typing import Dict, List
3+
4+
from slack_bolt import Say, SetSuggestedPrompts
5+
6+
7+
def start_assistant_thread(
8+
say: Say,
9+
set_suggested_prompts: SetSuggestedPrompts,
10+
logger: Logger,
11+
):
12+
"""
13+
Handle the assistant thread start event by greeting the user and setting suggested prompts.
14+
15+
Args:
16+
say: Function to send messages to the thread from the app
17+
set_suggested_prompts: Function to configure suggested prompt options
18+
logger: Logger instance for error tracking
19+
"""
20+
try:
21+
say("How can I help you?")
22+
23+
prompts: List[Dict[str, str]] = [
24+
{
25+
"title": "What does Slack stand for?",
26+
"message": "Slack, a business communication service, was named after an acronym. Can you guess what it stands for?",
27+
},
28+
{
29+
"title": "Write a draft announcement",
30+
"message": "Can you write a draft announcement about a new feature my team just released? It must include how impactful it is.",
31+
},
32+
{
33+
"title": "Suggest names for my Slack app",
34+
"message": "Can you suggest a few names for my Slack app? The app helps my teammates better organize information and plan priorities and action items.",
35+
},
36+
]
37+
38+
set_suggested_prompts(prompts=prompts)
39+
except Exception as e:
40+
logger.exception(f"Failed to handle an assistant_thread_started event: {e}", e)
41+
say(f":warning: Something went wrong! ({e})")
Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,15 @@
11
from logging import Logger
22
from typing import Dict, List
33

4-
from slack_bolt import Assistant, BoltContext, Say, SetStatus, SetSuggestedPrompts
4+
from slack_bolt import BoltContext, Say, SetStatus
55
from slack_sdk import WebClient
66

77
from ai.llm_caller import call_llm
88

99
from ..views.feedback_block import create_feedback_block
1010

11-
# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details
12-
assistant = Assistant()
13-
14-
15-
@assistant.thread_started
16-
def start_assistant_thread(
17-
say: Say,
18-
set_suggested_prompts: SetSuggestedPrompts,
19-
logger: Logger,
20-
):
21-
"""
22-
Handle the assistant thread start event by greeting the user and setting suggested prompts.
23-
24-
Args:
25-
say: Function to send messages to the thread from the app
26-
set_suggested_prompts: Function to configure suggested prompt options
27-
logger: Logger instance for error tracking
28-
"""
29-
try:
30-
say("How can I help you?")
31-
32-
prompts: List[Dict[str, str]] = [
33-
{
34-
"title": "What does Slack stand for?",
35-
"message": "Slack, a business communication service, was named after an acronym. Can you guess what it stands for?",
36-
},
37-
{
38-
"title": "Write a draft announcement",
39-
"message": "Can you write a draft announcement about a new feature my team just released? It must include how impactful it is.",
40-
},
41-
{
42-
"title": "Suggest names for my Slack app",
43-
"message": "Can you suggest a few names for my Slack app? The app helps my teammates better organize information and plan priorities and action items.",
44-
},
45-
]
46-
47-
set_suggested_prompts(prompts=prompts)
48-
except Exception as e:
49-
logger.exception(f"Failed to handle an assistant_thread_started event: {e}", e)
50-
say(f":warning: Something went wrong! ({e})")
51-
5211

5312
# This listener is invoked when the human user sends a reply in the assistant thread
54-
@assistant.user_message
5513
def respond_in_assistant_thread(
5614
client: WebClient,
5715
context: BoltContext,

manifest.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
"app_mentions:read",
2424
"assistant:write",
2525
"im:history",
26-
"channels:read",
2726
"chat:write"
2827
]
2928
}
3029
},
3130
"settings": {
3231
"event_subscriptions": {
3332
"bot_events": [
34-
"assistant_thread_context_changed",
3533
"assistant_thread_started",
3634
"message.im",
3735
"app_mention"

0 commit comments

Comments
 (0)