Skip to content
Merged
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
10 changes: 8 additions & 2 deletions json-logs/samples/api/views.open.json
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
"dispatch_action": false,
"hint": {
Expand Down Expand Up @@ -3205,7 +3208,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
{
"type": "workflow_button",
Expand Down
10 changes: 8 additions & 2 deletions json-logs/samples/api/views.publish.json
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
"dispatch_action": false,
"hint": {
Expand Down Expand Up @@ -3205,7 +3208,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
{
"type": "workflow_button",
Expand Down
10 changes: 8 additions & 2 deletions json-logs/samples/api/views.push.json
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
"dispatch_action": false,
"hint": {
Expand Down Expand Up @@ -3205,7 +3208,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
{
"type": "workflow_button",
Expand Down
10 changes: 8 additions & 2 deletions json-logs/samples/api/views.update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
"dispatch_action": false,
"hint": {
Expand Down Expand Up @@ -3205,7 +3208,10 @@
},
"style": ""
},
"accessibility_label": ""
"accessibility_label": "",
"agent_prompt": "",
"agent_prompt_display": "",
"visible_to_user_ids": []
},
{
"type": "workflow_button",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ButtonElementBuilder : Builder<ButtonElement> {
private var style: String? = null
private var confirm: ConfirmationDialogObject? = null
private var accessibilityLabel: String? = null
private var agentPrompt: String? = null
private var agentPromptDisplay: String? = null
private var visibleToUserIds: List<String>? = null

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

/**
* A prompt sent to Slackbot when the button is clicked, if Slackbot AI is available to the user.
* Maximum length for this field is 4000 characters.
*
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
*/
fun agentPrompt(agentPrompt: String) {
this.agentPrompt = agentPrompt
}

/**
* Short text shown instead of the full agent_prompt in the user's Slackbot message.
* Requires agent_prompt and defaults to the button's text.
*
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
*/
fun agentPromptDisplay(agentPromptDisplay: String) {
this.agentPromptDisplay = agentPromptDisplay
}

/**
* An array of user IDs for which the button appears. If not provided, the button is visible to all users.
*
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
*/
fun visibleToUserIds(visibleToUserIds: List<String>) {
this.visibleToUserIds = visibleToUserIds
}

/**
* An array of user IDs for which the button appears. If not provided, the button is visible to all users.
*
* @see <a href="https://docs.slack.dev/reference/block-kit/block-elements/button-element">Button element documentation</a>
*/
fun visibleToUserIds(vararg visibleToUserIds: String) {
this.visibleToUserIds = visibleToUserIds.toList()
}

override fun build(): ButtonElement {
return ButtonElement.builder()
.actionId(actionId)
Expand All @@ -112,6 +153,9 @@ class ButtonElementBuilder : Builder<ButtonElement> {
.style(style)
.confirm(confirm)
.accessibilityLabel(accessibilityLabel)
.agentPrompt(agentPrompt)
.agentPromptDisplay(agentPromptDisplay)
.visibleToUserIds(visibleToUserIds)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ class ActionsBlockTest {
assertEquals(expected, result)
}

@Test
fun buttonWithAgentPrompt() {
val gson = GsonFactory.createSnakeCase()
val blocks = withBlocks {
actions {
button {
actionId("summarize_incident")
text("Summarize with Slackbot")
agentPrompt("Summarize this incident and suggest next steps.")
agentPromptDisplay("Summarize this incident")
visibleToUserIds("U123456")
}
}
}
val result = gson.toJson(blocks)
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"]}]}]"""
assertEquals(expected, result)
}

@Test
fun `multi-selects`() {
val gson = GsonFactory.createSnakeCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.slack.api.model.block.composition.PlainTextObject;
import lombok.*;

import java.util.List;

/**
* https://docs.slack.dev/reference/block-kit/block-elements/button-element
*/
Expand Down Expand Up @@ -68,4 +70,21 @@ public class ButtonElement extends BlockElement {
* Maximum length for this field is 75 characters.
*/
private String accessibilityLabel;

/**
* A prompt sent to Slackbot when the button is clicked, if Slackbot AI is available to the user.
* Maximum length for this field is 4000 characters.
*/
private String agentPrompt;

/**
* Short text shown instead of the full agent_prompt in the user's Slackbot message.
* Requires agent_prompt and defaults to the button's text.
*/
private String agentPromptDisplay;

/**
* An array of user IDs for which the button appears. If not provided, the button is visible to all users.
*/
private List<String> visibleToUserIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,35 @@ public void parseContextActionsBlock() {
assertEquals(Arrays.asList("USLACKBOT", "U0123456789"), iconButton.getVisibleToUserIds());
}

@Test
public void parseButtonWithAgentPrompt() {
String json = "{\n" +
" \"type\": \"actions\",\n" +
" \"elements\": [\n" +
" {\n" +
" \"type\": \"button\",\n" +
" \"text\": {\n" +
" \"type\": \"plain_text\",\n" +
" \"text\": \"Summarize with Slackbot\"\n" +
" },\n" +
" \"action_id\": \"summarize_incident\",\n" +
" \"agent_prompt\": \"Summarize this incident and suggest next steps.\",\n" +
" \"agent_prompt_display\": \"Summarize this incident\",\n" +
" \"visible_to_user_ids\": [\"U123456\"]\n" +
" }\n" +
" ]\n" +
"}";
ActionsBlock block = GsonFactory.createSnakeCase().fromJson(json, ActionsBlock.class);
ButtonElement button = (ButtonElement) block.getElements().get(0);
assertEquals("Summarize this incident and suggest next steps.", button.getAgentPrompt());
assertEquals("Summarize this incident", button.getAgentPromptDisplay());
assertEquals(Arrays.asList("U123456"), button.getVisibleToUserIds());
String serialized = GsonFactory.createSnakeCase().toJson(block);
assertThat(serialized, containsString("\"agent_prompt\":\"Summarize this incident and suggest next steps.\""));
assertThat(serialized, containsString("\"agent_prompt_display\":\"Summarize this incident\""));
assertThat(serialized, containsString("\"visible_to_user_ids\":[\"U123456\"]"));
}

String richTextSkinTone = "{ \"blocks\": [\n" +
" {\n" +
" \"type\": \"rich_text\",\n" +
Expand Down
Loading