interact: handle InteractionTypeViewSubmission and print debug state

This commit is contained in:
c9s 2022-01-21 02:01:41 +08:00
parent 2f65d5951e
commit 49e4b71776

View File

@ -2,6 +2,7 @@ package interact
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
stdlog "log" stdlog "log"
"os" "os"
@ -247,6 +248,8 @@ func (s *Slack) listen() {
case slack.InteractionTypeShortcut: case slack.InteractionTypeShortcut:
case slack.InteractionTypeViewSubmission: case slack.InteractionTypeViewSubmission:
// See https://api.slack.com/apis/connections/socket-implement#modal // See https://api.slack.com/apis/connections/socket-implement#modal
log.Debugf("InteractionTypeViewSubmission: state: %s", toJson(callback.View.State))
case slack.InteractionTypeDialogSubmission: case slack.InteractionTypeDialogSubmission:
default: default:
@ -349,8 +352,9 @@ func generateTextInputModalRequest(title string, prompt string, textFields ...Te
labelObject := slack.NewTextBlockObject("plain_text", textField.Label, false, false) labelObject := slack.NewTextBlockObject("plain_text", textField.Label, false, false)
placeHolderObject := slack.NewTextBlockObject("plain_text", textField.PlaceHolder, false, false) placeHolderObject := slack.NewTextBlockObject("plain_text", textField.PlaceHolder, false, false)
textInputObject := slack.NewPlainTextInputBlockElement(placeHolderObject, textField.Name) textInputObject := slack.NewPlainTextInputBlockElement(placeHolderObject, textField.Name)
// Notice that blockID is a unique identifier for a block // Notice that blockID is a unique identifier for a block
inputBlock := slack.NewInputBlock(textField.Name, labelObject, textInputObject) inputBlock := slack.NewInputBlock("block-"+textField.Name+"-"+uuid.NewString(), labelObject, textInputObject)
blocks.BlockSet = append(blocks.BlockSet, inputBlock) blocks.BlockSet = append(blocks.BlockSet, inputBlock)
} }
@ -362,3 +366,12 @@ func generateTextInputModalRequest(title string, prompt string, textFields ...Te
modalRequest.Blocks = blocks modalRequest.Blocks = blocks
return &modalRequest return &modalRequest
} }
func toJson(v interface{}) string {
o, err := json.MarshalIndent(v, "", " ")
if err != nil {
log.WithError(err).Errorf("json marshal error")
return ""
}
return string(o)
}