|
| 1 | +package test_locally.api.methods; |
| 2 | + |
| 3 | +import com.slack.api.Slack; |
| 4 | +import com.slack.api.SlackConfig; |
| 5 | +import com.slack.api.methods.request.agents.conversations.AgentsConversationsSetCommandsRequest; |
| 6 | +import com.slack.api.methods.request.agents.conversations.AgentsConversationsSetPropertiesRequest; |
| 7 | +import com.slack.api.methods.request.agents.conversations.AgentsConversationsSetViewRequest; |
| 8 | +import org.junit.After; |
| 9 | +import org.junit.Before; |
| 10 | +import org.junit.Test; |
| 11 | +import util.MockSlackApiServer; |
| 12 | + |
| 13 | +import java.util.Arrays; |
| 14 | + |
| 15 | +import static com.slack.api.model.block.Blocks.asBlocks; |
| 16 | +import static com.slack.api.model.block.Blocks.section; |
| 17 | +import static com.slack.api.model.block.composition.BlockCompositions.plainText; |
| 18 | +import static org.hamcrest.CoreMatchers.is; |
| 19 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | +import static util.MockSlackApi.ValidToken; |
| 21 | + |
| 22 | +public class AgentsConversationsTest { |
| 23 | + |
| 24 | + MockSlackApiServer server = new MockSlackApiServer(); |
| 25 | + SlackConfig config = new SlackConfig(); |
| 26 | + Slack slack = Slack.getInstance(config); |
| 27 | + |
| 28 | + @Before |
| 29 | + public void setup() throws Exception { |
| 30 | + server.start(); |
| 31 | + config.setMethodsEndpointUrlPrefix(server.getMethodsEndpointPrefix()); |
| 32 | + } |
| 33 | + |
| 34 | + @After |
| 35 | + public void tearDown() throws Exception { |
| 36 | + server.stop(); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void test() throws Exception { |
| 41 | + assertThat(slack.methods(ValidToken).agentsConversationsArchive(r -> r |
| 42 | + .channelId("C123") |
| 43 | + .summaryMessageTs("123.123") |
| 44 | + ).isOk(), is(true)); |
| 45 | + assertThat(slack.methods(ValidToken).agentsConversationsCreate(r -> r |
| 46 | + .name("code-channel") |
| 47 | + .isPrivate(true) |
| 48 | + .originChannelId("C123") |
| 49 | + .originMessageTs("123.123") |
| 50 | + ).isOk(), is(true)); |
| 51 | + assertThat(slack.methods(ValidToken).agentsConversationsGetCanvas(r -> r |
| 52 | + .channel("C123") |
| 53 | + .canvasId("F123") |
| 54 | + .contentFormat("markdown") |
| 55 | + .includeResolved(true) |
| 56 | + ).isOk(), is(true)); |
| 57 | + assertThat(slack.methods(ValidToken).agentsConversationsListViews(r -> r |
| 58 | + .channelId("C123") |
| 59 | + ).isOk(), is(true)); |
| 60 | + assertThat(slack.methods(ValidToken).agentsConversationsRemoveView(r -> r |
| 61 | + .channelId("C123") |
| 62 | + .viewId("V123") |
| 63 | + ).isOk(), is(true)); |
| 64 | + assertThat(slack.methods(ValidToken).agentsConversationsSetCanvasContent(r -> r |
| 65 | + .channel("C123") |
| 66 | + .canvasId("F123") |
| 67 | + .content("# Plan") |
| 68 | + ).isOk(), is(true)); |
| 69 | + assertThat(slack.methods(ValidToken).agentsConversationsSetCommands(r -> r |
| 70 | + .channelId("C123") |
| 71 | + .commands(Arrays.asList(AgentsConversationsSetCommandsRequest.Command.builder() |
| 72 | + .name("summarize") |
| 73 | + .description("Summarize the session so far") |
| 74 | + .argumentHint("[topic]") |
| 75 | + .shouldEscape(true) |
| 76 | + .build())) |
| 77 | + ).isOk(), is(true)); |
| 78 | + assertThat(slack.methods(ValidToken).agentsConversationsSetProperties(r -> r |
| 79 | + .channelId("C123") |
| 80 | + .codeChannel(AgentsConversationsSetPropertiesRequest.CodeChannel.builder() |
| 81 | + .contextBarItems(Arrays.asList(AgentsConversationsSetPropertiesRequest.ContextBarItem.builder() |
| 82 | + .key("repo") |
| 83 | + .label("borant/billing") |
| 84 | + .icon("folder") |
| 85 | + .url("https://github.com/borant/billing") |
| 86 | + .build())) |
| 87 | + .summaryMessage(AgentsConversationsSetPropertiesRequest.SummaryMessage.builder() |
| 88 | + .messageTs("123.123") |
| 89 | + .build()) |
| 90 | + .build()) |
| 91 | + .agentResource(AgentsConversationsSetPropertiesRequest.AgentResource.builder() |
| 92 | + .url("https://github.com/borant/billing/pull/1") |
| 93 | + .resourceType("pull_request") |
| 94 | + .title("Fix billing") |
| 95 | + .provider("github") |
| 96 | + .build()) |
| 97 | + ).isOk(), is(true)); |
| 98 | + assertThat(slack.methods(ValidToken).agentsConversationsSetView(r -> r |
| 99 | + .channelId("C123") |
| 100 | + .viewKey("coverage") |
| 101 | + .name("Coverage") |
| 102 | + .content("<!doctype html><html><head></head><body></body></html>") |
| 103 | + .csp(AgentsConversationsSetViewRequest.Csp.builder() |
| 104 | + .connectDomains(Arrays.asList("https://api.example.com")) |
| 105 | + .resourceDomains(Arrays.asList("https://cdn.jsdelivr.net")) |
| 106 | + .build()) |
| 107 | + ).isOk(), is(true)); |
| 108 | + assertThat(slack.methods(ValidToken).agentsConversationsSetView(r -> r |
| 109 | + .channelId("C123") |
| 110 | + .type("block_kit") |
| 111 | + .viewKey("summary") |
| 112 | + .name("Summary") |
| 113 | + .blocks(asBlocks(section(s -> s.text(plainText("hi"))))) |
| 114 | + ).isOk(), is(true)); |
| 115 | + assertThat(slack.methods(ValidToken).agentsConversationsSetView(r -> r |
| 116 | + .channelId("C123") |
| 117 | + .type("canvas") |
| 118 | + .viewKey("plan") |
| 119 | + .name("Plan") |
| 120 | + .canvasId("F123") |
| 121 | + ).isOk(), is(true)); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void test_async() throws Exception { |
| 126 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsArchive(r -> r |
| 127 | + .channelId("C123") |
| 128 | + .summaryMessageTs("123.123") |
| 129 | + ).get().isOk(), is(true)); |
| 130 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsCreate(r -> r |
| 131 | + .name("code-channel") |
| 132 | + .isPrivate(true) |
| 133 | + .originChannelId("C123") |
| 134 | + .originMessageTs("123.123") |
| 135 | + ).get().isOk(), is(true)); |
| 136 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsGetCanvas(r -> r |
| 137 | + .channel("C123") |
| 138 | + .canvasId("F123") |
| 139 | + .contentFormat("markdown") |
| 140 | + .includeResolved(true) |
| 141 | + ).get().isOk(), is(true)); |
| 142 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsListViews(r -> r |
| 143 | + .channelId("C123") |
| 144 | + ).get().isOk(), is(true)); |
| 145 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsRemoveView(r -> r |
| 146 | + .channelId("C123") |
| 147 | + .viewId("V123") |
| 148 | + ).get().isOk(), is(true)); |
| 149 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsSetCanvasContent(r -> r |
| 150 | + .channel("C123") |
| 151 | + .canvasId("F123") |
| 152 | + .content("# Plan") |
| 153 | + ).get().isOk(), is(true)); |
| 154 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsSetCommands(r -> r |
| 155 | + .channelId("C123") |
| 156 | + .commands(Arrays.asList(AgentsConversationsSetCommandsRequest.Command.builder() |
| 157 | + .name("summarize") |
| 158 | + .description("Summarize the session so far") |
| 159 | + .argumentHint("[topic]") |
| 160 | + .shouldEscape(true) |
| 161 | + .build())) |
| 162 | + ).get().isOk(), is(true)); |
| 163 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsSetProperties(r -> r |
| 164 | + .channelId("C123") |
| 165 | + .codeChannel(AgentsConversationsSetPropertiesRequest.CodeChannel.builder() |
| 166 | + .contextBarItems(Arrays.asList(AgentsConversationsSetPropertiesRequest.ContextBarItem.builder() |
| 167 | + .key("repo") |
| 168 | + .label("borant/billing") |
| 169 | + .icon("folder") |
| 170 | + .url("https://github.com/borant/billing") |
| 171 | + .build())) |
| 172 | + .summaryMessage(AgentsConversationsSetPropertiesRequest.SummaryMessage.builder() |
| 173 | + .messageTs("123.123") |
| 174 | + .build()) |
| 175 | + .build()) |
| 176 | + .agentResource(AgentsConversationsSetPropertiesRequest.AgentResource.builder() |
| 177 | + .url("https://github.com/borant/billing/pull/1") |
| 178 | + .resourceType("pull_request") |
| 179 | + .title("Fix billing") |
| 180 | + .provider("github") |
| 181 | + .build()) |
| 182 | + ).get().isOk(), is(true)); |
| 183 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsSetView(r -> r |
| 184 | + .channelId("C123") |
| 185 | + .viewKey("coverage") |
| 186 | + .name("Coverage") |
| 187 | + .content("<!doctype html><html><head></head><body></body></html>") |
| 188 | + .csp(AgentsConversationsSetViewRequest.Csp.builder() |
| 189 | + .connectDomains(Arrays.asList("https://api.example.com")) |
| 190 | + .resourceDomains(Arrays.asList("https://cdn.jsdelivr.net")) |
| 191 | + .build()) |
| 192 | + ).get().isOk(), is(true)); |
| 193 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsSetView(r -> r |
| 194 | + .channelId("C123") |
| 195 | + .type("block_kit") |
| 196 | + .viewKey("summary") |
| 197 | + .name("Summary") |
| 198 | + .blocks(asBlocks(section(s -> s.text(plainText("hi"))))) |
| 199 | + ).get().isOk(), is(true)); |
| 200 | + assertThat(slack.methodsAsync(ValidToken).agentsConversationsSetView(r -> r |
| 201 | + .channelId("C123") |
| 202 | + .type("canvas") |
| 203 | + .viewKey("plan") |
| 204 | + .name("Plan") |
| 205 | + .canvasId("F123") |
| 206 | + ).get().isOk(), is(true)); |
| 207 | + } |
| 208 | + |
| 209 | +} |
0 commit comments