summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/interactions.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-09-07 22:46:58 +0200
committerGitHub <noreply@github.com>2019-09-07 22:46:58 +0200
commita3bee01e0af3394c19360b98fd2db1b647f49299 (patch)
treeffc5778361d55d592a718354a37c9251e75fc7f6 /vendor/github.com/nlopes/slack/interactions.go
parent1dc93ec4f001edd01daccbe408767d4878be25a3 (diff)
downloadmatterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.tar.gz
matterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.tar.bz2
matterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.zip
Update dependencies (#886)
Diffstat (limited to 'vendor/github.com/nlopes/slack/interactions.go')
-rw-r--r--vendor/github.com/nlopes/slack/interactions.go68
1 files changed, 67 insertions, 1 deletions
diff --git a/vendor/github.com/nlopes/slack/interactions.go b/vendor/github.com/nlopes/slack/interactions.go
index addc2864..5433463d 100644
--- a/vendor/github.com/nlopes/slack/interactions.go
+++ b/vendor/github.com/nlopes/slack/interactions.go
@@ -1,8 +1,20 @@
package slack
+import (
+ "encoding/json"
+)
+
// InteractionType type of interactions
type InteractionType string
+// ActionType type represents the type of action (attachment, block, etc.)
+type actionType string
+
+// action is an interface that should be implemented by all callback action types
+type action interface {
+ actionType() actionType
+}
+
// Types of interactions that can be received.
const (
InteractionTypeDialogCancellation = InteractionType("dialog_cancellation")
@@ -10,6 +22,7 @@ const (
InteractionTypeDialogSuggestion = InteractionType("dialog_suggestion")
InteractionTypeInteractionMessage = InteractionType("interactive_message")
InteractionTypeMessageAction = InteractionType("message_action")
+ InteractionTypeBlockActions = InteractionType("block_actions")
)
// InteractionCallback is sent from slack when a user interactions with a button or dialog.
@@ -27,6 +40,59 @@ type InteractionCallback struct {
Message Message `json:"message"`
Name string `json:"name"`
Value string `json:"value"`
- ActionCallback
+ MessageTs string `json:"message_ts"`
+ AttachmentID string `json:"attachment_id"`
+ ActionCallback ActionCallbacks `json:"actions"`
DialogSubmissionCallback
}
+
+// ActionCallback is a convenience struct defined to allow dynamic unmarshalling of
+// the "actions" value in Slack's JSON response, which varies depending on block type
+type ActionCallbacks struct {
+ AttachmentActions []*AttachmentAction
+ BlockActions []*BlockAction
+}
+
+// UnmarshalJSON implements the Marshaller interface in order to delegate
+// marshalling and allow for proper type assertion when decoding the response
+func (a *ActionCallbacks) UnmarshalJSON(data []byte) error {
+ var raw []json.RawMessage
+ err := json.Unmarshal(data, &raw)
+ if err != nil {
+ return err
+ }
+
+ for _, r := range raw {
+ var obj map[string]interface{}
+ err := json.Unmarshal(r, &obj)
+ if err != nil {
+ return err
+ }
+
+ if _, ok := obj["block_id"].(string); ok {
+ action, err := unmarshalAction(r, &BlockAction{})
+ if err != nil {
+ return err
+ }
+
+ a.BlockActions = append(a.BlockActions, action.(*BlockAction))
+ return nil
+ }
+
+ action, err := unmarshalAction(r, &AttachmentAction{})
+ if err != nil {
+ return err
+ }
+ a.AttachmentActions = append(a.AttachmentActions, action.(*AttachmentAction))
+ }
+
+ return nil
+}
+
+func unmarshalAction(r json.RawMessage, callbackAction action) (action, error) {
+ err := json.Unmarshal(r, callbackAction)
+ if err != nil {
+ return nil, err
+ }
+ return callbackAction, nil
+}