Skip to content

Commit f2dcfaa

Browse files
committed
fix: Replace hardcoded Casey name in App Home with dynamic bot mention
1 parent 092fefb commit f2dcfaa

9 files changed

Lines changed: 96 additions & 18 deletions

File tree

claude-agent-sdk/listeners/events/app_home_opened.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ async def handle_app_home_opened(
2424
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")
2525
install_url = urljoin(redirect_uri, "/slack/install")
2626

27-
view = build_app_home_view(install_url=install_url, is_connected=is_connected)
27+
view = build_app_home_view(
28+
install_url=install_url,
29+
is_connected=is_connected,
30+
bot_user_id=context.bot_user_id,
31+
)
2832
await client.views_publish(user_id=user_id, view=view)
2933
except Exception as e:
3034
logger.exception(f"Failed to publish App Home: {e}")

claude-agent-sdk/listeners/views/app_home_builder.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
def build_app_home_view(
31-
install_url: str | None = None, is_connected: bool = False
31+
install_url: str | None = None,
32+
is_connected: bool = False,
33+
bot_user_id: str | None = None,
3234
) -> dict:
3335
"""Build the App Home Block Kit view with category buttons.
3436
@@ -37,13 +39,15 @@ def build_app_home_view(
3739
connected and will see a link to install.
3840
is_connected: When ``True``, the user is connected and the MCP
3941
status section shows as connected.
42+
bot_user_id: The bot's user ID for dynamic mentions.
4043
"""
44+
mention = f" with <@{bot_user_id}>" if bot_user_id else ""
4145
blocks = [
4246
{
4347
"type": "header",
4448
"text": {
4549
"type": "plain_text",
46-
"text": "Hey there :wave: I'm Casey, your IT helpdesk agent.",
50+
"text": "Hey there :wave: I'm your IT helpdesk agent.",
4751
},
4852
},
4953
{
@@ -79,7 +83,7 @@ def build_app_home_view(
7983
"elements": [
8084
{
8185
"type": "mrkdwn",
82-
"text": "You can also mention me in any channel with `@Casey` or send me a DM.",
86+
"text": f"You can also mention me in any channel{mention} or send me a DM.",
8387
}
8488
],
8589
},
@@ -102,7 +106,7 @@ def build_app_home_view(
102106
"elements": [
103107
{
104108
"type": "mrkdwn",
105-
"text": "Casey has access to search messages, read channels, and more.",
109+
"text": "This agent has access to search messages, read channels, and more.",
106110
}
107111
],
108112
}
@@ -123,7 +127,7 @@ def build_app_home_view(
123127
"elements": [
124128
{
125129
"type": "mrkdwn",
126-
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
130+
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
127131
}
128132
],
129133
}

claude-agent-sdk/tests/test_view_builders.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ def test_build_app_home_view_connected():
6363
]
6464
mcp_section = next(t for t in section_texts if "Slack MCP Server" in t)
6565
assert "connected" in mcp_section
66+
67+
68+
def test_build_app_home_view_with_bot_user_id():
69+
"""bot_user_id provided — context block includes dynamic mention."""
70+
view = build_app_home_view(bot_user_id="U0BOT")
71+
72+
context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
73+
mention_text = context_blocks[0]["elements"][0]["text"]
74+
assert "<@U0BOT>" in mention_text
75+
76+
77+
def test_build_app_home_view_without_bot_user_id():
78+
"""bot_user_id not provided — context block omits mention."""
79+
view = build_app_home_view()
80+
81+
context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
82+
mention_text = context_blocks[0]["elements"][0]["text"]
83+
assert "<@" not in mention_text

openai-agents-sdk/listeners/events/app_home_opened.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
2222
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")
2323
install_url = urljoin(redirect_uri, "/slack/install")
2424

25-
view = build_app_home_view(install_url=install_url, is_connected=is_connected)
25+
view = build_app_home_view(
26+
install_url=install_url,
27+
is_connected=is_connected,
28+
bot_user_id=context.bot_user_id,
29+
)
2630
client.views_publish(user_id=user_id, view=view)
2731
except Exception as e:
2832
logger.exception(f"Failed to publish App Home: {e}")

openai-agents-sdk/listeners/views/app_home_builder.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
def build_app_home_view(
31-
install_url: str | None = None, is_connected: bool = False
31+
install_url: str | None = None,
32+
is_connected: bool = False,
33+
bot_user_id: str | None = None,
3234
) -> dict:
3335
"""Build the App Home Block Kit view with category buttons.
3436
@@ -37,13 +39,15 @@ def build_app_home_view(
3739
connected and will see a link to install.
3840
is_connected: When ``True``, the user is connected and the MCP
3941
status section shows as connected.
42+
bot_user_id: The bot's user ID for dynamic mentions.
4043
"""
44+
mention = f" with <@{bot_user_id}>" if bot_user_id else ""
4145
blocks = [
4246
{
4347
"type": "header",
4448
"text": {
4549
"type": "plain_text",
46-
"text": "Hey there :wave: I'm Casey, your IT helpdesk agent.",
50+
"text": "Hey there :wave: I'm your IT helpdesk agent.",
4751
},
4852
},
4953
{
@@ -79,7 +83,7 @@ def build_app_home_view(
7983
"elements": [
8084
{
8185
"type": "mrkdwn",
82-
"text": "You can also mention me in any channel with `@Casey` or send me a DM.",
86+
"text": f"You can also mention me in any channel{mention} or send me a DM.",
8387
}
8488
],
8589
},
@@ -102,7 +106,7 @@ def build_app_home_view(
102106
"elements": [
103107
{
104108
"type": "mrkdwn",
105-
"text": "Casey has access to search messages, read channels, and more.",
109+
"text": "This agent has access to search messages, read channels, and more.",
106110
}
107111
],
108112
}
@@ -123,7 +127,7 @@ def build_app_home_view(
123127
"elements": [
124128
{
125129
"type": "mrkdwn",
126-
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
130+
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
127131
}
128132
],
129133
}

openai-agents-sdk/tests/test_view_builders.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ def test_build_app_home_view_connected():
6363
]
6464
mcp_section = next(t for t in section_texts if "Slack MCP Server" in t)
6565
assert "connected" in mcp_section
66+
67+
68+
def test_build_app_home_view_with_bot_user_id():
69+
"""bot_user_id provided — context block includes dynamic mention."""
70+
view = build_app_home_view(bot_user_id="U0BOT")
71+
72+
context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
73+
mention_text = context_blocks[0]["elements"][0]["text"]
74+
assert "<@U0BOT>" in mention_text
75+
76+
77+
def test_build_app_home_view_without_bot_user_id():
78+
"""bot_user_id not provided — context block omits mention."""
79+
view = build_app_home_view()
80+
81+
context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
82+
mention_text = context_blocks[0]["elements"][0]["text"]
83+
assert "<@" not in mention_text

pydantic-ai/listeners/events/app_home_opened.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
2222
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")
2323
install_url = urljoin(redirect_uri, "/slack/install")
2424

25-
view = build_app_home_view(install_url=install_url, is_connected=is_connected)
25+
view = build_app_home_view(
26+
install_url=install_url,
27+
is_connected=is_connected,
28+
bot_user_id=context.bot_user_id,
29+
)
2630
client.views_publish(user_id=user_id, view=view)
2731
except Exception as e:
2832
logger.exception(f"Failed to publish App Home: {e}")

pydantic-ai/listeners/views/app_home_builder.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
def build_app_home_view(
31-
install_url: str | None = None, is_connected: bool = False
31+
install_url: str | None = None,
32+
is_connected: bool = False,
33+
bot_user_id: str | None = None,
3234
) -> dict:
3335
"""Build the App Home Block Kit view with category buttons.
3436
@@ -37,13 +39,15 @@ def build_app_home_view(
3739
connected and will see a link to install.
3840
is_connected: When ``True``, the user is connected and the MCP
3941
status section shows as connected.
42+
bot_user_id: The bot's user ID for dynamic mentions.
4043
"""
44+
mention = f" with <@{bot_user_id}>" if bot_user_id else ""
4145
blocks = [
4246
{
4347
"type": "header",
4448
"text": {
4549
"type": "plain_text",
46-
"text": "Hey there :wave: I'm Casey, your IT helpdesk agent.",
50+
"text": "Hey there :wave: I'm your IT helpdesk agent.",
4751
},
4852
},
4953
{
@@ -79,7 +83,7 @@ def build_app_home_view(
7983
"elements": [
8084
{
8185
"type": "mrkdwn",
82-
"text": "You can also mention me in any channel with `@Casey` or send me a DM.",
86+
"text": f"You can also mention me in any channel{mention} or send me a DM.",
8387
}
8488
],
8589
},
@@ -102,7 +106,7 @@ def build_app_home_view(
102106
"elements": [
103107
{
104108
"type": "mrkdwn",
105-
"text": "Casey has access to search messages, read channels, and more.",
109+
"text": "This agent has access to search messages, read channels, and more.",
106110
}
107111
],
108112
}
@@ -123,7 +127,7 @@ def build_app_home_view(
123127
"elements": [
124128
{
125129
"type": "mrkdwn",
126-
"text": "The Slack MCP Server enables Casey to search messages, read channels, and more.",
130+
"text": "The Slack MCP Server enables this agent to search messages, read channels, and more.",
127131
}
128132
],
129133
}

pydantic-ai/tests/test_view_builders.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ def test_build_app_home_view_connected():
6363
]
6464
mcp_section = next(t for t in section_texts if "Slack MCP Server" in t)
6565
assert "connected" in mcp_section
66+
67+
68+
def test_build_app_home_view_with_bot_user_id():
69+
"""bot_user_id provided — context block includes dynamic mention."""
70+
view = build_app_home_view(bot_user_id="U0BOT")
71+
72+
context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
73+
mention_text = context_blocks[0]["elements"][0]["text"]
74+
assert "<@U0BOT>" in mention_text
75+
76+
77+
def test_build_app_home_view_without_bot_user_id():
78+
"""bot_user_id not provided — context block omits mention."""
79+
view = build_app_home_view()
80+
81+
context_blocks = [b for b in view["blocks"] if b["type"] == "context"]
82+
mention_text = context_blocks[0]["elements"][0]["text"]
83+
assert "<@" not in mention_text

0 commit comments

Comments
 (0)