Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ Every incoming request is routed to a "listener". This directory groups each lis

Configures the new Slack Assistant features, providing a dedicated side panel UI for users to interact with the AI chatbot. This module includes:

`assistant.py`, which contains two listeners:
`assistant_thread_started.py`, which contains:
* The `@assistant.thread_started` listener receives an event when users start new app thread.

`message.py`, which contains:
* The `@assistant.user_message` listener processes user messages in app threads or from the app **Chat** and **History** tab.
Comment thread
srtaalej marked this conversation as resolved.
Outdated

`ai/llm_caller.py`, which handles OpenAI API integration and message formatting. It includes the `call_llm()` function that sends conversation threads to OpenAI's models.
### `ai/`
Comment thread
srtaalej marked this conversation as resolved.
`llm_caller.py`, which handles OpenAI API integration and message formatting. It includes the `call_llm()` function that sends conversation threads to OpenAI's models.
Comment thread
srtaalej marked this conversation as resolved.
Outdated

## App Distribution / OAuth

Expand Down
11 changes: 9 additions & 2 deletions listeners/assistant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from slack_bolt import App
from slack_bolt import App, Assistant

from .assistant import assistant
from .assistant_thread_started import start_assistant_thread
from .message import respond_in_assistant_thread


# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details on the Assistant class
Comment thread
srtaalej marked this conversation as resolved.
Outdated
def register(app: App):
assistant = Assistant()

assistant.thread_started(start_assistant_thread)
assistant.user_message(respond_in_assistant_thread)
Comment thread
srtaalej marked this conversation as resolved.
Outdated

app.assistant(assistant)
41 changes: 41 additions & 0 deletions listeners/assistant/assistant_thread_started.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from logging import Logger
from typing import Dict, List

from slack_bolt import Say, SetSuggestedPrompts


def start_assistant_thread(
say: Say,
set_suggested_prompts: SetSuggestedPrompts,
logger: Logger,
):
"""
Handle the assistant thread start event by greeting the user and setting suggested prompts.

Args:
say: Function to send messages to the thread from the app
set_suggested_prompts: Function to configure suggested prompt options
logger: Logger instance for error tracking
"""
try:
say("How can I help you?")

prompts: List[Dict[str, str]] = [
{
"title": "What does Slack stand for?",
"message": "Slack, a business communication service, was named after an acronym. Can you guess what it stands for?",
},
{
"title": "Write a draft announcement",
"message": "Can you write a draft announcement about a new feature my team just released? It must include how impactful it is.",
},
{
"title": "Suggest names for my Slack app",
"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.",
},
]

set_suggested_prompts(prompts=prompts)
except Exception as e:
logger.exception(f"Failed to handle an assistant_thread_started event: {e}", e)
say(f":warning: Something went wrong! ({e})")
Original file line number Diff line number Diff line change
@@ -1,57 +1,15 @@
from logging import Logger
from typing import Dict, List

from slack_bolt import Assistant, BoltContext, Say, SetStatus, SetSuggestedPrompts
from slack_bolt import BoltContext, Say, SetStatus
from slack_sdk import WebClient

from ai.llm_caller import call_llm

from ..views.feedback_block import create_feedback_block

# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details
assistant = Assistant()


@assistant.thread_started
def start_assistant_thread(
say: Say,
set_suggested_prompts: SetSuggestedPrompts,
logger: Logger,
):
"""
Handle the assistant thread start event by greeting the user and setting suggested prompts.

Args:
say: Function to send messages to the thread from the app
set_suggested_prompts: Function to configure suggested prompt options
logger: Logger instance for error tracking
"""
try:
say("How can I help you?")

prompts: List[Dict[str, str]] = [
{
"title": "What does Slack stand for?",
"message": "Slack, a business communication service, was named after an acronym. Can you guess what it stands for?",
},
{
"title": "Write a draft announcement",
"message": "Can you write a draft announcement about a new feature my team just released? It must include how impactful it is.",
},
{
"title": "Suggest names for my Slack app",
"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.",
},
]

set_suggested_prompts(prompts=prompts)
except Exception as e:
logger.exception(f"Failed to handle an assistant_thread_started event: {e}", e)
say(f":warning: Something went wrong! ({e})")


# This listener is invoked when the human user sends a reply in the assistant thread
Comment thread
srtaalej marked this conversation as resolved.
Outdated
@assistant.user_message
def respond_in_assistant_thread(
client: WebClient,
context: BoltContext,
Expand Down
2 changes: 0 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
"app_mentions:read",
"assistant:write",
"im:history",
"channels:read",
Comment thread
srtaalej marked this conversation as resolved.
"chat:write"
]
}
},
"settings": {
"event_subscriptions": {
"bot_events": [
"assistant_thread_context_changed",
"assistant_thread_started",
"message.im",
"app_mention"
Expand Down