-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce workflow step app functionality
- Loading branch information
Steffen Mahler
committed
Feb 28, 2022
1 parent
f6658aa
commit 486fde5
Showing
5 changed files
with
209 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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,95 @@ | ||
package slack | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
const VTWorkflowStep ViewType = "workflow_step" | ||
|
||
type ( | ||
ConfigurationModalRequest struct { | ||
ModalViewRequest | ||
} | ||
|
||
WorkflowStepCompleteResponse struct { | ||
WorkflowStepEditID string `json:"workflow_step_edit_id"` | ||
Inputs *WorkflowStepInputs `json:"inputs,omitempty"` | ||
Outputs *[]WorkflowStepOutput `json:"outputs,omitempty"` | ||
} | ||
|
||
WorkflowStepInputElement struct { | ||
Value string `json:"value"` | ||
SkipVariableReplacement bool `json:"skip_variable_replacement"` | ||
} | ||
|
||
WorkflowStepInputs map[string]WorkflowStepInputElement | ||
|
||
WorkflowStepOutput struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Label string `json:"label"` | ||
} | ||
) | ||
|
||
func NewConfigurationModalRequest(blocks Blocks, privateMetaData string, externalID string) *ConfigurationModalRequest { | ||
return &ConfigurationModalRequest{ | ||
ModalViewRequest{ | ||
Type: VTWorkflowStep, | ||
Title: nil, // slack configuration modal must not have a title! | ||
Blocks: blocks, | ||
PrivateMetadata: privateMetaData, | ||
ExternalID: externalID, | ||
}, | ||
} | ||
} | ||
|
||
func (api *Client) SaveWorkflowStepConfiguration(workflowStepEditID string, inputs *WorkflowStepInputs, outputs *[]WorkflowStepOutput) error { | ||
// More information: https://api.slack.com/methods/workflows.updateStep | ||
wscr := WorkflowStepCompleteResponse{ | ||
WorkflowStepEditID: workflowStepEditID, | ||
Inputs: inputs, | ||
Outputs: outputs, | ||
} | ||
|
||
endpoint := api.endpoint + "workflows.updateStep" | ||
jsonData, err := json.Marshal(wscr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
response := &SlackResponse{} | ||
if err := postJSON(context.Background(), api.httpclient, endpoint, api.token, jsonData, response, api); err != nil { | ||
return err | ||
} | ||
|
||
if !response.Ok { | ||
return fmt.Errorf(" %s", response.Error) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func GetInitialOptionFromWorkflowStepInput(selection *SelectBlockElement, inputs *WorkflowStepInputs, options []*OptionBlockObject) (*OptionBlockObject, bool) { | ||
if len(*inputs) == 0 { | ||
return &OptionBlockObject{}, false | ||
} | ||
if len(options) == 0 { | ||
return &OptionBlockObject{}, false | ||
} | ||
|
||
if val, ok := (*inputs)[selection.ActionID]; ok { | ||
if val.SkipVariableReplacement { | ||
return &OptionBlockObject{}, false | ||
} | ||
|
||
for _, option := range options { | ||
if option.Value == val.Value { | ||
return option, true | ||
} | ||
} | ||
} | ||
|
||
return &OptionBlockObject{}, false | ||
} |