diff options
author | Wim <wim@42.be> | 2022-04-25 23:50:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 23:50:10 +0200 |
commit | 67adad3e08fe17d5f7e87468ea47aa76e1662255 (patch) | |
tree | 91314fac90d39254e66ae794decfcd21c10a7b20 /vendor/github.com/slack-go/slack/workflow_step.go | |
parent | 2fca3c756373577eab4e0120ccce62eecc1f5ad8 (diff) | |
download | matterbridge-msglm-67adad3e08fe17d5f7e87468ea47aa76e1662255.tar.gz matterbridge-msglm-67adad3e08fe17d5f7e87468ea47aa76e1662255.tar.bz2 matterbridge-msglm-67adad3e08fe17d5f7e87468ea47aa76e1662255.zip |
Update dependencies (#1813)
Diffstat (limited to 'vendor/github.com/slack-go/slack/workflow_step.go')
-rw-r--r-- | vendor/github.com/slack-go/slack/workflow_step.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/vendor/github.com/slack-go/slack/workflow_step.go b/vendor/github.com/slack-go/slack/workflow_step.go new file mode 100644 index 00000000..bcc892c5 --- /dev/null +++ b/vendor/github.com/slack-go/slack/workflow_step.go @@ -0,0 +1,98 @@ +package slack + +import ( + "context" + "encoding/json" +) + +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 { + return api.SaveWorkflowStepConfigurationContext(context.Background(), workflowStepEditID, inputs, outputs) +} + +func (api *Client) SaveWorkflowStepConfigurationContext(ctx context.Context, 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(ctx, api.httpclient, endpoint, api.token, jsonData, response, api); err != nil { + return err + } + + if !response.Ok { + return response.Err() + } + + 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 +} |