summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/slack-go/slack/interactions.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/slack-go/slack/interactions.go')
-rw-r--r--vendor/github.com/slack-go/slack/interactions.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/github.com/slack-go/slack/interactions.go b/vendor/github.com/slack-go/slack/interactions.go
index c7f59217..2515e290 100644
--- a/vendor/github.com/slack-go/slack/interactions.go
+++ b/vendor/github.com/slack-go/slack/interactions.go
@@ -56,6 +56,65 @@ type InteractionCallback struct {
DialogSubmissionCallback
ViewSubmissionCallback
ViewClosedCallback
+
+ // FIXME(kanata2): just workaround for backward-compatibility.
+ // See also https://github.com/slack-go/slack/issues/816
+ RawState json.RawMessage `json:"state,omitempty"`
+
+ // BlockActionState stands for the `state` field in block_actions type.
+ // NOTE: InteractionCallback.State has a role for the state of dialog_submission type,
+ // so we cannot use this field for backward-compatibility for now.
+ BlockActionState *BlockActionStates `json:"-"`
+}
+
+type BlockActionStates struct {
+ Values map[string]map[string]BlockAction `json:"values"`
+}
+
+func (ic *InteractionCallback) MarshalJSON() ([]byte, error) {
+ type alias InteractionCallback
+ tmp := alias(*ic)
+ if tmp.Type == InteractionTypeBlockActions {
+ if tmp.BlockActionState == nil {
+ tmp.RawState = []byte(`{}`)
+ } else {
+ state, err := json.Marshal(tmp.BlockActionState.Values)
+ if err != nil {
+ return nil, err
+ }
+ tmp.RawState = []byte(`{"values":` + string(state) + `}`)
+ }
+ } else if ic.Type == InteractionTypeDialogSubmission {
+ tmp.RawState = []byte(tmp.State)
+ }
+ // Use pointer for go1.7
+ return json.Marshal(&tmp)
+}
+
+func (ic *InteractionCallback) UnmarshalJSON(b []byte) error {
+ type alias InteractionCallback
+ tmp := struct {
+ Type InteractionType `json:"type"`
+ *alias
+ }{
+ alias: (*alias)(ic),
+ }
+ if err := json.Unmarshal(b, &tmp); err != nil {
+ return err
+ }
+ *ic = InteractionCallback(*tmp.alias)
+ ic.Type = tmp.Type
+ if ic.Type == InteractionTypeBlockActions {
+ if len(ic.RawState) > 0 {
+ err := json.Unmarshal(ic.RawState, &ic.BlockActionState)
+ if err != nil {
+ return err
+ }
+ }
+ } else if ic.Type == InteractionTypeDialogSubmission {
+ ic.State = string(ic.RawState)
+ }
+ return nil
}
type Container struct {