[MM-9938] Add support for multiple responses from a slash command (#9836)
* slash command response now supports multiple posts * change wording of Posts to ExtraResponses
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
246ff89391
Коммит
a50e8ac5b9
@@ -277,6 +277,18 @@ func (a *App) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError) {
|
func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError) {
|
||||||
|
a.HandleCommandResponsePost(command, args, response, builtIn)
|
||||||
|
|
||||||
|
if response.ExtraResponses != nil {
|
||||||
|
for _, resp := range response.ExtraResponses {
|
||||||
|
a.HandleCommandResponsePost(command, args, resp, builtIn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) HandleCommandResponsePost(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError) {
|
||||||
post := &model.Post{}
|
post := &model.Post{}
|
||||||
post.ChannelId = args.ChannelId
|
post.ChannelId = args.ChannelId
|
||||||
post.RootId = args.RootId
|
post.RootId = args.RootId
|
||||||
|
|||||||
@@ -18,14 +18,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CommandResponse struct {
|
type CommandResponse struct {
|
||||||
ResponseType string `json:"response_type"`
|
ResponseType string `json:"response_type"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
IconURL string `json:"icon_url"`
|
IconURL string `json:"icon_url"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Props StringInterface `json:"props"`
|
Props StringInterface `json:"props"`
|
||||||
GotoLocation string `json:"goto_location"`
|
GotoLocation string `json:"goto_location"`
|
||||||
Attachments []*SlackAttachment `json:"attachments"`
|
Attachments []*SlackAttachment `json:"attachments"`
|
||||||
|
ExtraResponses []*CommandResponse `json:"extra_responses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CommandResponse) ToJson() string {
|
func (o *CommandResponse) ToJson() string {
|
||||||
@@ -63,5 +64,11 @@ func CommandResponseFromJson(data io.Reader) (*CommandResponse, error) {
|
|||||||
|
|
||||||
o.Attachments = StringifySlackFieldValue(o.Attachments)
|
o.Attachments = StringifySlackFieldValue(o.Attachments)
|
||||||
|
|
||||||
|
if o.ExtraResponses != nil {
|
||||||
|
for _, resp := range o.ExtraResponses {
|
||||||
|
resp.Attachments = StringifySlackFieldValue(resp.Attachments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &o, nil
|
return &o, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,71 @@ func TestCommandResponseFromJson(t *testing.T) {
|
|||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"multiple responses returned",
|
||||||
|
`
|
||||||
|
{
|
||||||
|
"text": "message 1",
|
||||||
|
"extra_responses": [
|
||||||
|
{"text": "message 2"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
&CommandResponse{
|
||||||
|
Text: "message 1",
|
||||||
|
ExtraResponses: []*CommandResponse{
|
||||||
|
&CommandResponse{
|
||||||
|
Text: "message 2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"multiple responses returned, with attachments",
|
||||||
|
`
|
||||||
|
{
|
||||||
|
"text": "message 1",
|
||||||
|
"attachments":[{"fields":[{"title":"foo","value":"bar","short":true}]}],
|
||||||
|
"extra_responses": [
|
||||||
|
{
|
||||||
|
"text": "message 2",
|
||||||
|
"attachments":[{"fields":[{"title":"foo 2","value":"bar 2","short":false}]}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
&CommandResponse{
|
||||||
|
Text: "message 1",
|
||||||
|
Attachments: []*SlackAttachment{
|
||||||
|
{
|
||||||
|
Fields: []*SlackAttachmentField{
|
||||||
|
{
|
||||||
|
Title: "foo",
|
||||||
|
Value: "bar",
|
||||||
|
Short: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ExtraResponses: []*CommandResponse{
|
||||||
|
&CommandResponse{
|
||||||
|
Text: "message 2",
|
||||||
|
Attachments: []*SlackAttachment{
|
||||||
|
{
|
||||||
|
Fields: []*SlackAttachmentField{
|
||||||
|
{
|
||||||
|
Title: "foo 2",
|
||||||
|
Value: "bar 2",
|
||||||
|
Short: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user