Skip to content
Open
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
6 changes: 5 additions & 1 deletion claude-agent-sdk/listeners/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ async def handle_app_home_opened(
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")
install_url = urljoin(redirect_uri, "/slack/install")

view = build_app_home_view(install_url=install_url, is_connected=is_connected)
view = build_app_home_view(
install_url=install_url,
is_connected=is_connected,
bot_user_id=context.bot_user_id,
)
await client.views_publish(user_id=user_id, view=view)
except Exception as e:
logger.exception(f"Failed to publish App Home: {e}")
16 changes: 10 additions & 6 deletions claude-agent-sdk/listeners/views/app_home_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@


def build_app_home_view(
install_url: str | None = None, is_connected: bool = False
install_url: str | None = None,
is_connected: bool = False,
bot_user_id: str | None = None,
) -> dict:
"""Build the App Home Block Kit view with category buttons.

Expand All @@ -37,13 +39,15 @@ def build_app_home_view(
connected and will see a link to install.
is_connected: When ``True``, the user is connected and the MCP
status section shows as connected.
bot_user_id: The bot's user ID for dynamic mentions.
"""
mention = f" with <@{bot_user_id}>" if bot_user_id else ""
blocks = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Hey there :wave: I'm Casey, your IT helpdesk agent.",
"text": "Hey there :wave: I'm your IT helpdesk agent.",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: "Helpdesk" is renamed in PR #65

},
},
{
Expand Down Expand Up @@ -79,7 +83,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "You can also mention me in any channel with `@Casey` or send me a DM.",
"text": f"You can also mention me in any channel{mention} or send me a DM.",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Again, this reads funny but it does allow for a safe fallback when no bot id provided.

}
],
},
Expand All @@ -102,7 +106,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "Casey has access to search messages, read channels, and more.",
"text": "This agent has access to search messages, read channels, and more.",
}
],
}
Expand All @@ -123,7 +127,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
}
],
}
Expand All @@ -144,7 +148,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
}
],
}
Expand Down
18 changes: 18 additions & 0 deletions claude-agent-sdk/tests/test_view_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ def test_build_app_home_view_connected():
]
mcp_section = next(t for t in section_texts if "Slack MCP Server" in t)
assert "connected" in mcp_section


def test_build_app_home_view_with_bot_user_id():
"""bot_user_id provided — context block includes dynamic mention."""
view = build_app_home_view(bot_user_id="U0BOT")

context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
mention_text = context_blocks[0]["elements"][0]["text"]
assert "<@U0BOT>" in mention_text


def test_build_app_home_view_without_bot_user_id():
"""bot_user_id not provided — context block omits mention."""
view = build_app_home_view()

context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
mention_text = context_blocks[0]["elements"][0]["text"]
assert "<@" not in mention_text
6 changes: 5 additions & 1 deletion openai-agents-sdk/listeners/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")
install_url = urljoin(redirect_uri, "/slack/install")

view = build_app_home_view(install_url=install_url, is_connected=is_connected)
view = build_app_home_view(
install_url=install_url,
is_connected=is_connected,
bot_user_id=context.bot_user_id,
)
client.views_publish(user_id=user_id, view=view)
except Exception as e:
logger.exception(f"Failed to publish App Home: {e}")
16 changes: 10 additions & 6 deletions openai-agents-sdk/listeners/views/app_home_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@


def build_app_home_view(
install_url: str | None = None, is_connected: bool = False
install_url: str | None = None,
is_connected: bool = False,
bot_user_id: str | None = None,
) -> dict:
"""Build the App Home Block Kit view with category buttons.

Expand All @@ -37,13 +39,15 @@ def build_app_home_view(
connected and will see a link to install.
is_connected: When ``True``, the user is connected and the MCP
status section shows as connected.
bot_user_id: The bot's user ID for dynamic mentions.
"""
mention = f" with <@{bot_user_id}>" if bot_user_id else ""
blocks = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Hey there :wave: I'm Casey, your IT helpdesk agent.",
"text": "Hey there :wave: I'm your IT helpdesk agent.",
},
},
{
Expand Down Expand Up @@ -79,7 +83,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "You can also mention me in any channel with `@Casey` or send me a DM.",
"text": f"You can also mention me in any channel{mention} or send me a DM.",
}
],
},
Expand All @@ -102,7 +106,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "Casey has access to search messages, read channels, and more.",
"text": "This agent has access to search messages, read channels, and more.",
}
],
}
Expand All @@ -123,7 +127,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
}
],
}
Expand All @@ -144,7 +148,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
}
],
}
Expand Down
18 changes: 18 additions & 0 deletions openai-agents-sdk/tests/test_view_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ def test_build_app_home_view_connected():
]
mcp_section = next(t for t in section_texts if "Slack MCP Server" in t)
assert "connected" in mcp_section


def test_build_app_home_view_with_bot_user_id():
"""bot_user_id provided — context block includes dynamic mention."""
view = build_app_home_view(bot_user_id="U0BOT")

context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
mention_text = context_blocks[0]["elements"][0]["text"]
assert "<@U0BOT>" in mention_text


def test_build_app_home_view_without_bot_user_id():
"""bot_user_id not provided — context block omits mention."""
view = build_app_home_view()

context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
mention_text = context_blocks[0]["elements"][0]["text"]
assert "<@" not in mention_text
6 changes: 5 additions & 1 deletion pydantic-ai/listeners/events/app_home_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")
install_url = urljoin(redirect_uri, "/slack/install")

view = build_app_home_view(install_url=install_url, is_connected=is_connected)
view = build_app_home_view(
install_url=install_url,
is_connected=is_connected,
bot_user_id=context.bot_user_id,
)
client.views_publish(user_id=user_id, view=view)
except Exception as e:
logger.exception(f"Failed to publish App Home: {e}")
16 changes: 10 additions & 6 deletions pydantic-ai/listeners/views/app_home_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@


def build_app_home_view(
install_url: str | None = None, is_connected: bool = False
install_url: str | None = None,
is_connected: bool = False,
bot_user_id: str | None = None,
) -> dict:
"""Build the App Home Block Kit view with category buttons.

Expand All @@ -37,13 +39,15 @@ def build_app_home_view(
connected and will see a link to install.
is_connected: When ``True``, the user is connected and the MCP
status section shows as connected.
bot_user_id: The bot's user ID for dynamic mentions.
"""
mention = f" with <@{bot_user_id}>" if bot_user_id else ""
blocks = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Hey there :wave: I'm Casey, your IT helpdesk agent.",
"text": "Hey there :wave: I'm your IT helpdesk agent.",
},
},
{
Expand Down Expand Up @@ -79,7 +83,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "You can also mention me in any channel with `@Casey` or send me a DM.",
"text": f"You can also mention me in any channel{mention} or send me a DM.",
}
],
},
Expand All @@ -102,7 +106,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "Casey has access to search messages, read channels, and more.",
"text": "This agent has access to search messages, read channels, and more.",
}
],
}
Expand All @@ -123,7 +127,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
}
],
}
Expand All @@ -144,7 +148,7 @@ def build_app_home_view(
"elements": [
{
"type": "mrkdwn",
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
}
],
}
Expand Down
18 changes: 18 additions & 0 deletions pydantic-ai/tests/test_view_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ def test_build_app_home_view_connected():
]
mcp_section = next(t for t in section_texts if "Slack MCP Server" in t)
assert "connected" in mcp_section


def test_build_app_home_view_with_bot_user_id():
"""bot_user_id provided — context block includes dynamic mention."""
view = build_app_home_view(bot_user_id="U0BOT")

context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
mention_text = context_blocks[0]["elements"][0]["text"]
assert "<@U0BOT>" in mention_text


def test_build_app_home_view_without_bot_user_id():
"""bot_user_id not provided — context block omits mention."""
view = build_app_home_view()

context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
mention_text = context_blocks[0]["elements"][0]["text"]
assert "<@" not in mention_text