Repository navigation
fix: preserve agent prompt fields in button models #2000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mwbrooks
merged 1 commit into
slackapi:main
from
samkantor123:skantor/button-agent-prompt-fields
Oct 28, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from copy import deepcopy | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from slack_sdk import WebClient | ||
| from slack_sdk.models.blocks import ActionsBlock, ButtonElement, SectionBlock | ||
| from slack_sdk.models.views import View | ||
|
|
||
|
|
||
| class TestViewsPublishAgentPrompt(unittest.TestCase): | ||
| def test_models_send_the_same_button_fields_as_raw_json(self): | ||
| button = { | ||
| "type": "button", | ||
| "text": {"type": "plain_text", "text": "Summarize with Slackbot"}, | ||
| "action_id": "summarize_incident", | ||
| "style": "primary", | ||
| "agent_prompt": "Summarize this incident and suggest next steps.", | ||
| "agent_prompt_display": "Summarize this incident", | ||
| "visible_to_user_ids": ["U123456"], | ||
| } | ||
| blocks = ( | ||
| {"type": "actions", "elements": [button]}, | ||
| { | ||
| "type": "section", | ||
| "text": {"type": "mrkdwn", "text": "Incident details"}, | ||
| "accessory": button, | ||
| }, | ||
| ) | ||
| client = WebClient(token="xoxb-api_test") | ||
| for block in blocks: | ||
| block_class = ActionsBlock if block["type"] == "actions" else SectionBlock | ||
| raw_view = {"type": "home", "blocks": [block]} | ||
| explicit_button_block = deepcopy(block) | ||
| if block["type"] == "actions": | ||
| explicit_button_block["elements"] = [ButtonElement(**deepcopy(button))] | ||
| else: | ||
| explicit_button_block["accessory"] = ButtonElement(**deepcopy(button)) | ||
| views = { | ||
| "raw_json": deepcopy(raw_view), | ||
| "button_model": View(type="home", blocks=[block_class(**explicit_button_block)]), | ||
| "raw_button_in_block_model": View(type="home", blocks=[block_class(**deepcopy(block))]), | ||
| "raw_blocks_in_view_model": View(**deepcopy(raw_view)), | ||
| } | ||
| for representation, view in views.items(): | ||
| with self.subTest(placement=block["type"], representation=representation): | ||
| # Keep the SDK's serialization intact; intercept only the HTTP transport. | ||
| with patch.object(client, "_sync_send", return_value={"ok": True}) as transport: | ||
| client.views_publish(user_id="U123456", view=view) | ||
| transport.assert_called_once() | ||
| request = transport.call_args[1]["req_args"]["json"] | ||
| self.assertDictEqual({"user_id": "U123456", "view": raw_view}, request) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: The model tests in
test_elements.pyalready cover the round trip, and this one patches the private_sync_send, which our other web tests don't do. Not blocking, so I'd merge as-is and leave it to @WilliamBergamin to keep or move it in a follow-up PR.