Skip to content

Commit ff18e20

Browse files
authored
fix(model): add agent prompt and visibility fields to the button block element (#1666)
* fix(model): add agent prompt and visibility fields to the button block element * chore(model): update json-logs samples with the new button fields
1 parent 71b89d5 commit ff18e20

8 files changed

Lines changed: 143 additions & 8 deletions

File tree

‎json-logs/samples/api/views.open.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,10 @@
25982598
},
25992599
"style": ""
26002600
},
2601-
"accessibility_label": ""
2601+
"accessibility_label": "",
2602+
"agent_prompt": "",
2603+
"agent_prompt_display": "",
2604+
"visible_to_user_ids": []
26022605
},
26032606
"dispatch_action": false,
26042607
"hint": {
@@ -3205,7 +3208,10 @@
32053208
},
32063209
"style": ""
32073210
},
3208-
"accessibility_label": ""
3211+
"accessibility_label": "",
3212+
"agent_prompt": "",
3213+
"agent_prompt_display": "",
3214+
"visible_to_user_ids": []
32093215
},
32103216
{
32113217
"type": "workflow_button",

‎json-logs/samples/api/views.publish.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,10 @@
25982598
},
25992599
"style": ""
26002600
},
2601-
"accessibility_label": ""
2601+
"accessibility_label": "",
2602+
"agent_prompt": "",
2603+
"agent_prompt_display": "",
2604+
"visible_to_user_ids": []
26022605
},
26032606
"dispatch_action": false,
26042607
"hint": {
@@ -3205,7 +3208,10 @@
32053208
},
32063209
"style": ""
32073210
},
3208-
"accessibility_label": ""
3211+
"accessibility_label": "",
3212+
"agent_prompt": "",
3213+
"agent_prompt_display": "",
3214+
"visible_to_user_ids": []
32093215
},
32103216
{
32113217
"type": "workflow_button",

‎json-logs/samples/api/views.push.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,10 @@
25982598
},
25992599
"style": ""
26002600
},
2601-
"accessibility_label": ""
2601+
"accessibility_label": "",
2602+
"agent_prompt": "",
2603+
"agent_prompt_display": "",
2604+
"visible_to_user_ids": []
26022605
},
26032606
"dispatch_action": false,
26042607
"hint": {
@@ -3205,7 +3208,10 @@
32053208
},
32063209
"style": ""
32073210
},
3208-
"accessibility_label": ""
3211+
"accessibility_label": "",
3212+
"agent_prompt": "",
3213+
"agent_prompt_display": "",
3214+
"visible_to_user_ids": []
32093215
},
32103216
{
32113217
"type": "workflow_button",

‎json-logs/samples/api/views.update.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,10 @@
25982598
},
25992599
"style": ""
26002600
},
2601-
"accessibility_label": ""
2601+
"accessibility_label": "",
2602+
"agent_prompt": "",
2603+
"agent_prompt_display": "",
2604+
"visible_to_user_ids": []
26022605
},
26032606
"dispatch_action": false,
26042607
"hint": {
@@ -3205,7 +3208,10 @@
32053208
},
32063209
"style": ""
32073210
},
3208-
"accessibility_label": ""
3211+
"accessibility_label": "",
3212+
"agent_prompt": "",
3213+
"agent_prompt_display": "",
3214+
"visible_to_user_ids": []
32093215
},
32103216
{
32113217
"type": "workflow_button",

‎slack-api-model-kotlin-extension/src/main/kotlin/com/slack/api/model/kotlin_extension/block/element/ButtonElementBuilder.kt‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class ButtonElementBuilder : Builder<ButtonElement> {
1717
private var style: String? = null
1818
private var confirm: ConfirmationDialogObject? = null
1919
private var accessibilityLabel: String? = null
20+
private var agentPrompt: String? = null
21+
private var agentPromptDisplay: String? = null
22+
private var visibleToUserIds: List<String>? = null
2023

2124
/**
2225
* An identifier for this action. You can use this when you receive an interaction payload to identify the source
@@ -103,6 +106,44 @@ class ButtonElementBuilder : Builder<ButtonElement> {
103106
this.accessibilityLabel = accessibilityLabel
104107
}
105108

109+
/**
110+
* A prompt sent to Slackbot when the button is clicked, if Slackbot AI is available to the user.
111+
* Maximum length for this field is 4000 characters.
112+
*
113+
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
114+
*/
115+
fun agentPrompt(agentPrompt: String) {
116+
this.agentPrompt = agentPrompt
117+
}
118+
119+
/**
120+
* Short text shown instead of the full agent_prompt in the user's Slackbot message.
121+
* Requires agent_prompt and defaults to the button's text.
122+
*
123+
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
124+
*/
125+
fun agentPromptDisplay(agentPromptDisplay: String) {
126+
this.agentPromptDisplay = agentPromptDisplay
127+
}
128+
129+
/**
130+
* An array of user IDs for which the button appears. If not provided, the button is visible to all users.
131+
*
132+
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
133+
*/
134+
fun visibleToUserIds(visibleToUserIds: List<String>) {
135+
this.visibleToUserIds = visibleToUserIds
136+
}
137+
138+
/**
139+
* An array of user IDs for which the button appears. If not provided, the button is visible to all users.
140+
*
141+
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
142+
*/
143+
fun visibleToUserIds(vararg visibleToUserIds: String) {
144+
this.visibleToUserIds = visibleToUserIds.toList()
145+
}
146+
106147
override fun build(): ButtonElement {
107148
return ButtonElement.builder()
108149
.actionId(actionId)
@@ -112,6 +153,9 @@ class ButtonElementBuilder : Builder<ButtonElement> {
112153
.style(style)
113154
.confirm(confirm)
114155
.accessibilityLabel(accessibilityLabel)
156+
.agentPrompt(agentPrompt)
157+
.agentPromptDisplay(agentPromptDisplay)
158+
.visibleToUserIds(visibleToUserIds)
115159
.build()
116160
}
117161
}

‎slack-api-model-kotlin-extension/src/test/kotlin/test_locally/block/ActionsBlockTest.kt‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ class ActionsBlockTest {
3131
assertEquals(expected, result)
3232
}
3333

34+
@Test
35+
fun buttonWithAgentPrompt() {
36+
val gson = GsonFactory.createSnakeCase()
37+
val blocks = withBlocks {
38+
actions {
39+
button {
40+
actionId("summarize_incident")
41+
text("Summarize with Slackbot")
42+
agentPrompt("Summarize this incident and suggest next steps.")
43+
agentPromptDisplay("Summarize this incident")
44+
visibleToUserIds("U123456")
45+
}
46+
}
47+
}
48+
val result = gson.toJson(blocks)
49+
val expected = """[{"type":"actions","elements":[{"type":"button","text":{"type":"plain_text","text":"Summarize with Slackbot"},"action_id":"summarize_incident","agent_prompt":"Summarize this incident and suggest next steps.","agent_prompt_display":"Summarize this incident","visible_to_user_ids":["U123456"]}]}]"""
50+
assertEquals(expected, result)
51+
}
52+
3453
@Test
3554
fun `multi-selects`() {
3655
val gson = GsonFactory.createSnakeCase()

‎slack-api-model/src/main/java/com/slack/api/model/block/element/ButtonElement.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.slack.api.model.block.composition.PlainTextObject;
55
import lombok.*;
66

7+
import java.util.List;
8+
79
/**
810
* https://docs.slack.dev/reference/block-kit/block-elements/button-element
911
*/
@@ -68,4 +70,21 @@ public class ButtonElement extends BlockElement {
6870
* Maximum length for this field is 75 characters.
6971
*/
7072
private String accessibilityLabel;
73+
74+
/**
75+
* A prompt sent to Slackbot when the button is clicked, if Slackbot AI is available to the user.
76+
* Maximum length for this field is 4000 characters.
77+
*/
78+
private String agentPrompt;
79+
80+
/**
81+
* Short text shown instead of the full agent_prompt in the user's Slackbot message.
82+
* Requires agent_prompt and defaults to the button's text.
83+
*/
84+
private String agentPromptDisplay;
85+
86+
/**
87+
* An array of user IDs for which the button appears. If not provided, the button is visible to all users.
88+
*/
89+
private List<String> visibleToUserIds;
7190
}

‎slack-api-model/src/test/java/test_locally/api/model/block/BlockKitTest.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,35 @@ public void parseContextActionsBlock() {
13131313
assertEquals(Arrays.asList("USLACKBOT", "U0123456789"), iconButton.getVisibleToUserIds());
13141314
}
13151315

1316+
@Test
1317+
public void parseButtonWithAgentPrompt() {
1318+
String json = "{\n" +
1319+
" \"type\": \"actions\",\n" +
1320+
" \"elements\": [\n" +
1321+
" {\n" +
1322+
" \"type\": \"button\",\n" +
1323+
" \"text\": {\n" +
1324+
" \"type\": \"plain_text\",\n" +
1325+
" \"text\": \"Summarize with Slackbot\"\n" +
1326+
" },\n" +
1327+
" \"action_id\": \"summarize_incident\",\n" +
1328+
" \"agent_prompt\": \"Summarize this incident and suggest next steps.\",\n" +
1329+
" \"agent_prompt_display\": \"Summarize this incident\",\n" +
1330+
" \"visible_to_user_ids\": [\"U123456\"]\n" +
1331+
" }\n" +
1332+
" ]\n" +
1333+
"}";
1334+
ActionsBlock block = GsonFactory.createSnakeCase().fromJson(json, ActionsBlock.class);
1335+
ButtonElement button = (ButtonElement) block.getElements().get(0);
1336+
assertEquals("Summarize this incident and suggest next steps.", button.getAgentPrompt());
1337+
assertEquals("Summarize this incident", button.getAgentPromptDisplay());
1338+
assertEquals(Arrays.asList("U123456"), button.getVisibleToUserIds());
1339+
String serialized = GsonFactory.createSnakeCase().toJson(block);
1340+
assertThat(serialized, containsString("\"agent_prompt\":\"Summarize this incident and suggest next steps.\""));
1341+
assertThat(serialized, containsString("\"agent_prompt_display\":\"Summarize this incident\""));
1342+
assertThat(serialized, containsString("\"visible_to_user_ids\":[\"U123456\"]"));
1343+
}
1344+
13161345
String richTextSkinTone = "{ \"blocks\": [\n" +
13171346
" {\n" +
13181347
" \"type\": \"rich_text\",\n" +

0 commit comments

Comments
 (0)