GH-12702 v2: Add new command response parameter: "skip_slack_p… (#13420)
Add new command response parameter: "skip_slack_parsing". Skips Slack magic if set to "true". (#12702)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
4314a0427f
Коммит
566f28be0a
@@ -434,16 +434,13 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
|
|||||||
post.AddProp("from_webhook", "true")
|
post.AddProp("from_webhook", "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not process text if this is a code block
|
// Process Slack text replacements if the response does not contain "skip_slack_parsing": true.
|
||||||
skipSlackParsing := command.Trigger == "code"
|
if !response.SkipSlackParsing {
|
||||||
|
|
||||||
// Process Slack text replacements
|
|
||||||
if !skipSlackParsing {
|
|
||||||
response.Text = a.ProcessSlackText(response.Text)
|
response.Text = a.ProcessSlackText(response.Text)
|
||||||
response.Attachments = a.ProcessSlackAttachments(response.Attachments)
|
response.Attachments = a.ProcessSlackAttachments(response.Attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := a.CreateCommandPost(post, args.TeamId, response, skipSlackParsing); err != nil {
|
if _, err := a.CreateCommandPost(post, args.TeamId, response, response.SkipSlackParsing); err != nil {
|
||||||
return post, err
|
return post, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,5 +40,5 @@ func (me *CodeProvider) DoCommand(a *App, args *model.CommandArgs, message strin
|
|||||||
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
}
|
}
|
||||||
rmsg := " " + strings.Join(strings.Split(message, "\n"), "\n ")
|
rmsg := " " + strings.Join(strings.Split(message, "\n"), "\n ")
|
||||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: rmsg}
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: rmsg, SkipSlackParsing: true}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,7 +221,11 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
|||||||
Text: "<!here>",
|
Text: "<!here>",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set and unset SkipSlackParsing here seems the nicest way as no separate response objects are created for every testcase.
|
||||||
|
resp.SkipSlackParsing = true
|
||||||
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
|
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
|
||||||
|
resp.SkipSlackParsing = false
|
||||||
|
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, resp.Text, post.Message, "/code text should not be converted to Slack links")
|
assert.Equal(t, resp.Text, post.Message, "/code text should not be converted to Slack links")
|
||||||
|
|||||||
@@ -18,17 +18,18 @@ 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"`
|
||||||
ChannelId string `json:"channel_id"`
|
ChannelId string `json:"channel_id"`
|
||||||
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"`
|
||||||
TriggerId string `json:"trigger_id"`
|
TriggerId string `json:"trigger_id"`
|
||||||
Attachments []*SlackAttachment `json:"attachments"`
|
SkipSlackParsing bool `json:"skip_slack_parsing"` // Set to `true` to skip the Slack-compatibility handling of Text.
|
||||||
ExtraResponses []*CommandResponse `json:"extra_responses"`
|
Attachments []*SlackAttachment `json:"attachments"`
|
||||||
|
ExtraResponses []*CommandResponse `json:"extra_responses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CommandResponse) ToJson() string {
|
func (o *CommandResponse) ToJson() string {
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ func TestCommandResponseFromHTTPBody(t *testing.T) {
|
|||||||
{"text/plain", "foo", "foo"},
|
{"text/plain", "foo", "foo"},
|
||||||
{"application/json", `{"text": "foo"}`, "foo"},
|
{"application/json", `{"text": "foo"}`, "foo"},
|
||||||
{"application/json; charset=utf-8", `{"text": "foo"}`, "foo"},
|
{"application/json; charset=utf-8", `{"text": "foo"}`, "foo"},
|
||||||
|
{"application/json", `{"text": "` + "```" + `haskell\nlet\n\nf1 = [ 3 | a <- [1]]\nf2 = [ 4 | b <- [2]]\nf3 = \\p -> 5\n\nin 1\n` + "```" + `", "skip_slack_parsing": true}`,
|
||||||
|
"```haskell\nlet\n\nf1 = [ 3 | a <- [1]]\nf2 = [ 4 | b <- [2]]\nf3 = \\p -> 5\n\nin 1\n```",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
response, err := CommandResponseFromHTTPBody(test.ContentType, strings.NewReader(test.Body))
|
response, err := CommandResponseFromHTTPBody(test.ContentType, strings.NewReader(test.Body))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user