Debian Codegraph @

workflow_step.go

raw symbols SCIP
1 package slack
2
3 import (
4 "context"
5 "encoding/json"
6 )
7
8 const VTWorkflowStep ViewType = "workflow_step"
9
10 type (
11 ConfigurationModalRequest struct {
12 ModalViewRequest
13 }
14
15 WorkflowStepCompleteResponse struct {
16 WorkflowStepEditID string `json:"workflow_step_edit_id"`
17 Inputs *WorkflowStepInputs `json:"inputs,omitempty"`
18 Outputs *[]WorkflowStepOutput `json:"outputs,omitempty"`
19 }
20
21 WorkflowStepInputElement struct {
22 Value string `json:"value"`
23 SkipVariableReplacement bool `json:"skip_variable_replacement"`
24 }
25
26 WorkflowStepInputs map[string]WorkflowStepInputElement
27
28 WorkflowStepOutput struct {
29 Name string `json:"name"`
30 Type string `json:"type"`
31 Label string `json:"label"`
32 }
33 )
34
35 func NewConfigurationModalRequest(blocks Blocks, privateMetaData string, externalID string) *ConfigurationModalRequest {
36 return &ConfigurationModalRequest{
37 ModalViewRequest{
38 Type: VTWorkflowStep,
39 Title: nil, // slack configuration modal must not have a title!
40 Blocks: blocks,
41 PrivateMetadata: privateMetaData,
42 ExternalID: externalID,
43 },
44 }
45 }
46
47 func (api *Client) SaveWorkflowStepConfiguration(workflowStepEditID string, inputs *WorkflowStepInputs, outputs *[]WorkflowStepOutput) error {
48 return api.SaveWorkflowStepConfigurationContext(context.Background(), workflowStepEditID, inputs, outputs)
49 }
50
51 func (api *Client) SaveWorkflowStepConfigurationContext(ctx context.Context, workflowStepEditID string, inputs *WorkflowStepInputs, outputs *[]WorkflowStepOutput) error {
52 // More information: https://api.slack.com/methods/workflows.updateStep
53 wscr := WorkflowStepCompleteResponse{
54 WorkflowStepEditID: workflowStepEditID,
55 Inputs: inputs,
56 Outputs: outputs,
57 }
58
59 endpoint := api.endpoint + "workflows.updateStep"
60 jsonData, err := json.Marshal(wscr)
61 if err != nil {
62 return err
63 }
64
65 response := &SlackResponse{}
66 if err := postJSON(ctx, api.httpclient, endpoint, api.token, jsonData, response, api); err != nil {
67 return err
68 }
69
70 if !response.Ok {
71 return response.Err()
72 }
73
74 return nil
75 }
76
77 func GetInitialOptionFromWorkflowStepInput(selection *SelectBlockElement, inputs *WorkflowStepInputs, options []*OptionBlockObject) (*OptionBlockObject, bool) {
78 if len(*inputs) == 0 {
79 return &OptionBlockObject{}, false
80 }
81 if len(options) == 0 {
82 return &OptionBlockObject{}, false
83 }
84
85 if val, ok := (*inputs)[selection.ActionID]; ok {
86 if val.SkipVariableReplacement {
87 return &OptionBlockObject{}, false
88 }
89
90 for _, option := range options {
91 if option.Value == val.Value {
92 return option, true
93 }
94 }
95 }
96
97 return &OptionBlockObject{}, false
98 }