-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SlackOptionsResponse model for Dialog Options handling (#277)
- Loading branch information
1 parent
66878b4
commit 40fcfe8
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
slack-base/src/main/java/com/hubspot/slack/client/models/BaseSlackOptionsResponse.java
This file contains 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 |
---|---|---|
@@ -1,4 +1,14 @@ | ||
package com.hubspot.slack.client.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.hubspot.slack.client.models.interaction.BlocksLoadOptionsResponse; | ||
import com.hubspot.slack.client.models.interaction.SlackOptionsResponse; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = SlackOptionsResponse.class, name = SlackOptionsResponse.TYPE), | ||
@JsonSubTypes.Type(value = BlocksLoadOptionsResponse.class, name = BlocksLoadOptionsResponse.TYPE), | ||
}) | ||
public interface BaseSlackOptionsResponse { | ||
} |
This file contains 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
92 changes: 92 additions & 0 deletions
92
...ase/src/main/java/com/hubspot/slack/client/models/interaction/SlackOptionsResponseIF.java
This file contains 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,92 @@ | ||
package com.hubspot.slack.client.models.interaction; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.immutables.value.Value.Derived; | ||
import org.immutables.value.Value.Immutable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import com.hubspot.immutables.style.HubSpotStyle; | ||
import com.hubspot.slack.client.models.BaseSlackOptionsResponse; | ||
import com.hubspot.slack.client.models.actions.Option; | ||
import com.hubspot.slack.client.models.dialog.form.elements.SlackFormOption; | ||
import com.hubspot.slack.client.models.dialog.form.elements.SlackFormOptionGroup; | ||
|
||
@Immutable | ||
@HubSpotStyle | ||
@JsonNaming(SnakeCaseStrategy.class) | ||
@JsonInclude(Include.NON_NULL) | ||
public interface SlackOptionsResponseIF extends BaseSlackOptionsResponse { | ||
String TYPE = "slack_options_response"; | ||
|
||
// NOTE: slack annoyingly has a different model for dialog options and attachment options | ||
// https://api.slack.com/dialogs | https://api.slack.com/docs/message-menus | ||
|
||
static SlackOptionsResponse emptyAttachmentOptions() { | ||
return SlackOptionsResponse | ||
.builder() | ||
.setAttachmentOptions(Collections.emptyList()) | ||
.build(); | ||
} | ||
|
||
static SlackOptionsResponse ofAttachmentOptions(List<Option> options) { | ||
return SlackOptionsResponse.builder().setAttachmentOptions(options).build(); | ||
} | ||
|
||
static SlackOptionsResponse emptyDialogOptions() { | ||
return SlackOptionsResponse | ||
.builder() | ||
.setDialogOptions(Collections.emptyList()) | ||
.build(); | ||
} | ||
|
||
static SlackOptionsResponse ofDialogOptions( | ||
List<SlackFormOption> dialogOptions | ||
) { | ||
return SlackOptionsResponse.builder().setDialogOptions(dialogOptions).build(); | ||
} | ||
|
||
static SlackOptionsResponse emptyDialogOptionGroups() { | ||
return SlackOptionsResponse | ||
.builder() | ||
.setDialogOptionGroups(Collections.emptyList()) | ||
.build(); | ||
} | ||
|
||
static SlackOptionsResponse ofDialogOptionGroups( | ||
List<SlackFormOptionGroup> optionGroups | ||
) { | ||
return SlackOptionsResponse.builder().setDialogOptionGroups(optionGroups).build(); | ||
} | ||
|
||
Optional<List<Option>> getAttachmentOptions(); | ||
|
||
// attachment option groups aren't yet supported in the slack-client | ||
|
||
Optional<List<SlackFormOption>> getDialogOptions(); | ||
|
||
Optional<List<SlackFormOptionGroup>> getDialogOptionGroups(); | ||
|
||
@Derived | ||
@Nullable | ||
default Object getOptions() { | ||
return Stream.of(getAttachmentOptions(), getDialogOptions()) | ||
.findFirst() | ||
.orElse(null) | ||
.orElse(null); | ||
} | ||
|
||
@Derived | ||
@Nullable | ||
default Object getOptionGroups() { | ||
return getDialogOptionGroups().orElse(null); | ||
} | ||
} |