diff --git a/app/command.go b/app/command.go index e1cdc627b2..b661913e80 100644 --- a/app/command.go +++ b/app/command.go @@ -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) { + 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.ChannelId = args.ChannelId post.RootId = args.RootId diff --git a/model/command_response.go b/model/command_response.go index 1ed5286de2..3a4ffebbcb 100644 --- a/model/command_response.go +++ b/model/command_response.go @@ -18,14 +18,15 @@ const ( ) type CommandResponse struct { - ResponseType string `json:"response_type"` - Text string `json:"text"` - Username string `json:"username"` - IconURL string `json:"icon_url"` - Type string `json:"type"` - Props StringInterface `json:"props"` - GotoLocation string `json:"goto_location"` - Attachments []*SlackAttachment `json:"attachments"` + ResponseType string `json:"response_type"` + Text string `json:"text"` + Username string `json:"username"` + IconURL string `json:"icon_url"` + Type string `json:"type"` + Props StringInterface `json:"props"` + GotoLocation string `json:"goto_location"` + Attachments []*SlackAttachment `json:"attachments"` + ExtraResponses []*CommandResponse `json:"extra_responses"` } func (o *CommandResponse) ToJson() string { @@ -63,5 +64,11 @@ func CommandResponseFromJson(data io.Reader) (*CommandResponse, error) { o.Attachments = StringifySlackFieldValue(o.Attachments) + if o.ExtraResponses != nil { + for _, resp := range o.ExtraResponses { + resp.Attachments = StringifySlackFieldValue(resp.Attachments) + } + } + return &o, nil } diff --git a/model/command_response_test.go b/model/command_response_test.go index 60179e3961..ae941048ea 100644 --- a/model/command_response_test.go +++ b/model/command_response_test.go @@ -131,6 +131,71 @@ func TestCommandResponseFromJson(t *testing.T) { }, 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 {