Skip to content
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

add workflow events #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import com.hubspot.slack.client.models.events.user.SlackMemberJoinedChannelEvent;
import com.hubspot.slack.client.models.events.user.SlackMemberLeftChannelEvent;
import com.hubspot.slack.client.models.events.user.SlackUserChangeEvent;
import com.hubspot.slack.client.models.events.workflow.WorkflowDeletedEvent;
import com.hubspot.slack.client.models.events.workflow.WorkflowPublishedEvent;
import com.hubspot.slack.client.models.events.workflow.WorkflowStepDeletedEvent;
import com.hubspot.slack.client.models.events.workflow.WorkflowStepExecuteEvent;
import com.hubspot.slack.client.models.events.workflow.WorkflowUnpublishedEvent;

public enum SlackEventType {

Expand Down Expand Up @@ -90,8 +95,12 @@ public enum SlackEventType {
TOKENS_REVOKED(SlackTokensRevokedEvent.class),
URL_VERIFICATION,
USER_CHANGE(SlackUserChangeEvent.class),
UNKNOWN
;
WORKFLOW_DELETED(WorkflowDeletedEvent.class),
WORKFLOW_PUBLISHED(WorkflowPublishedEvent.class),
WORKFLOW_STEP_DELETED(WorkflowStepDeletedEvent.class),
WORKFLOW_STEP_EXECUTE(WorkflowStepExecuteEvent.class),
WORKFLOW_UNPUBLISHED(WorkflowUnpublishedEvent.class),
UNKNOWN;

private final Class<? extends SlackEvent> eventClass;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.hubspot.slack.client.models.events.json;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.hubspot.slack.client.models.events.SlackEvent;
import com.hubspot.slack.client.models.events.SlackEventType;
import com.hubspot.slack.client.models.events.SlackMessageSubtype;
import java.io.IOException;

public class EventDeserializer extends StdDeserializer<SlackEvent> {
private static final String TYPE_FIELD = "type";
Expand All @@ -21,7 +19,7 @@ public EventDeserializer() {
}

@Override
public SlackEvent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
public SlackEvent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
ObjectCodec codec = p.getCodec();
JsonNode node = codec.readTree(p);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hubspot.slack.client.models.events.workflow;

import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.workflows.WorkflowConfiguration;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonDeserialize(as = WorkflowDeletedEvent.class)
public interface WorkflowDeletedEventIF extends WorkflowEventBase {

WorkflowConfiguration getWorkflowDraftConfiguration();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hubspot.slack.client.models.events.workflow;

import com.hubspot.slack.client.models.events.SlackEvent;

public interface WorkflowEventBase extends SlackEvent {

String getWorkflowId();

String getEventTs();

@Override
default String getTs() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hubspot.slack.client.models.events.workflow;

import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.workflows.WorkflowConfiguration;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonDeserialize(as = WorkflowPublishedEvent.class)
public interface WorkflowPublishedEventIF extends WorkflowEventBase {

WorkflowConfiguration getWorkflowPublishedConfiguration();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hubspot.slack.client.models.events.workflow;

import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.workflows.WorkflowConfiguration;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonDeserialize(as = WorkflowStepDeletedEvent.class)
public interface WorkflowStepDeletedEventIF extends WorkflowEventBase {

WorkflowConfiguration getWorkflowDraftConfiguration();

WorkflowConfiguration getWorkflowPublishedConfiguration();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hubspot.slack.client.models.events.workflow;

import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.events.SlackEvent;
import com.hubspot.slack.client.models.workflows.WorkflowStep;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonDeserialize(as = WorkflowStepExecuteEvent.class)
public interface WorkflowStepExecuteEventIF extends SlackEvent {

WorkflowStep getWorkflowStep();

String getCallbackId();

@Override
default String getTs() {
return null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hubspot.slack.client.models.events.workflow;

import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.workflows.WorkflowConfiguration;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonDeserialize(as = WorkflowUnpublishedEvent.class)
public interface WorkflowUnpublishedEventIF extends WorkflowEventBase {

WorkflowConfiguration getWorkflowDraftConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum InteractiveCallbackType {
BLOCK_ACTIONS,
VIEW_SUBMISSION,
SHORTCUT,
WORKFLOW_STEP_EDIT,
UNKNOWN
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
@Type(value = DialogSubmission.class, name = "dialog_submission"),
@Type(value = ViewSubmission.class, name = "view_submission"),
@Type(value = MessageAction.class, name = "message_action"),
@Type(value = Shortcut.class, name = "shortcut")
@Type(value = Shortcut.class, name = "shortcut"),
@Type(value = WorkflowStepEdit.class, name="workflow_step_edit")
}
)
public interface SlackInteractiveCallback {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hubspot.slack.client.models.interaction;

import com.fasterxml.jackson.annotation.JsonInclude;
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.SlackChannel;
import com.hubspot.slack.client.models.workflows.WorkflowStep;
import org.immutables.value.Value.Immutable;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface WorkflowStepEditIF extends SlackInteractiveCallback {
String getTriggerId();

WorkflowStep getWorkflowStep();

@Override
default SlackChannel getChannel() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hubspot.slack.client.models.workflows;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import org.immutables.value.Value;

@Value.Immutable
@HubSpotStyle
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface AppStepIF {

String getAppId();
String getWorkflowStepId();
String getCallbackId();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hubspot.slack.client.models.workflows;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import java.util.Map;
import org.immutables.value.Value;
import org.immutables.value.Value.Default;

@Value.Immutable
@HubSpotStyle
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface InputIF {

// according to the docs, this can be any valid JSON value. https://api.slack.com/reference/workflows/workflow_step
JsonNode getValue();

Map<String, Object> getVariables();
@Default
default boolean getSkipVariableReplacement() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hubspot.slack.client.models.workflows;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import org.immutables.value.Value;

@Value.Immutable
@HubSpotStyle
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface OutputIF {

String getName();
String getLabel();
OutputType getType();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hubspot.slack.client.models.workflows;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;

public enum OutputType {
CHANNEL,
TEXT,
UNKNOWN,
USER;

@JsonCreator
public static OutputType fromSlackName(String slackName) {
return Arrays.stream(OutputType.values())
.filter(enumVal -> enumVal.toString().equalsIgnoreCase(slackName))
.findFirst()
.orElse(UNKNOWN);
}

@JsonValue
public String toSlackName() {
return this.toString().toLowerCase();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hubspot.slack.client.models.workflows;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import java.util.List;
import org.immutables.value.Value;

@Value.Immutable
@HubSpotStyle
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface WorkflowConfigurationIF {

String getVersionId();
List<AppStep> getAppSteps();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hubspot.slack.client.models.workflows;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
@HubSpotStyle
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface WorkflowStepIF {

Optional<String> getWorkflowId();
Optional<String> getStepId();

Optional<String> getWorkflowInstanceId();

Optional<String> getWorkflowStepExecuteId();

Optional<String> getStepName();
Optional<String> getStepImageUrl();

Map<String, Input> getInputs();

List<Output> getOutputs();

}
Loading