Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ 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:
* The `@assistant.thread_started` listener receives an event when users start new app thread.
* The `@assistant.user_message` listener processes user messages in app threads or from the app **Chat** and **History** tab.
- The `assistant_thread_started.py` file, which responds to new app threads with a list of suggested prompts.
- The `message.py` file, which responds to user messages sent to app threads or from the **Chat** and **History** tab with an LLM generated response.

`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.
The `llm_caller.py` file, which handles OpenAI API integration and message formatting. It includes the `call_llm()` function that sends conversation threads to OpenAI's models.

## 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 assistant_thread_started
from .message import message


# Refer to https://docs.slack.dev/tools/bolt-python/concepts/ai-apps#assistant for more details on the Assistant class
def register(app: App):
assistant = Assistant()

assistant.thread_started(assistant_thread_started)
assistant.user_message(message)

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 assistant_thread_started(
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,58 +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
@assistant.user_message
def respond_in_assistant_thread(
def message(
client: WebClient,
context: BoltContext,
logger: Logger,
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