Implementation:OpenHands OpenHands SlackView
| Knowledge Sources | |
|---|---|
| Domains | Platform_Integration, Slack |
| Last Updated | 2026-02-11 21:00 GMT |
Overview
View hierarchy and factory for creating and updating OpenHands conversations from Slack events, supporting both V0 and V1 conversation APIs.
Description
The Slack view module defines a class hierarchy: SlackUnknownUserView (unauthenticated users), SlackNewConversationView (new conversations), SlackNewConversationFromRepoFormView (form-selected repositories), and SlackUpdateExistingConversationView (follow-up messages). The SlackFactory creates the appropriate view type. Each view handles Slack message history retrieval (CONTEXT_LIMIT=21), Jinja2 template rendering, and conversation lifecycle management. Supports both V0 (legacy) and V1 (current) conversation APIs with sandbox management.
Usage
Use these classes when Slack events need to create or update OpenHands conversations. The factory pattern automatically selects the correct view type based on the event context (new user, new conversation, existing conversation, repo form selection).
Code Reference
Source Location
- Repository: OpenHands
- File: enterprise/integrations/slack/slack_view.py
- Lines: 1-658
Signature
@dataclass
class SlackNewConversationView:
bot_access_token: str
user_msg: str
slack_user_id: str
channel_id: str
slack_to_openhands_user: SlackUser
saas_user_auth: UserAuth
message_ts: str
thread_ts: str | None
selected_repo: str
async def create_or_update_conversation(self, jinja_env: Environment) -> str: ...
async def save_slack_convo(self, v1_enabled: bool) -> None: ...
class SlackFactory:
@staticmethod
def create_view(message: Message, ...) -> SlackViewInterface: ...
Import
from enterprise.integrations.slack.slack_view import SlackFactory, SlackNewConversationView
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| bot_access_token | str | Yes | Slack bot OAuth token |
| user_msg | str | Yes | User message text from Slack |
| slack_user_id | str | Yes | Slack user identifier |
| channel_id | str | Yes | Slack channel identifier |
| selected_repo | str | Yes | Selected repository name |
| jinja_env | Environment | Yes | Jinja2 template environment |
Outputs
| Name | Type | Description |
|---|---|---|
| create_or_update_conversation() | str | Conversation ID |
| save_slack_convo() | None | Persists conversation tracking record |
Usage Examples
from enterprise.integrations.slack.slack_view import SlackFactory
# Create view from Slack message context
view = SlackFactory.create_view(
message=slack_message,
slack_user=slack_user_record,
user_auth=saas_auth,
)
# Create conversation and save tracking record
conversation_id = await view.create_or_update_conversation(jinja_env)
await view.save_slack_convo(v1_enabled=True)