[PLT-8438] Include incoming webhook display name in post props (#7997)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
1aac5a9c97
Коммит
d9b8c4db76
@@ -118,6 +118,10 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
|
||||
if webhookResp.ResponseType == model.OUTGOING_HOOK_RESPONSE_TYPE_COMMENT {
|
||||
postRootId = post.Id
|
||||
}
|
||||
if len(webhookResp.Props) == 0 {
|
||||
webhookResp.Props = make(model.StringInterface)
|
||||
}
|
||||
webhookResp.Props["webhook_display_name"] = hook.DisplayName
|
||||
if _, err := a.CreateWebhookPost(hook.CreatorId, channel, *webhookResp.Text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type, postRootId); err != nil {
|
||||
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err)
|
||||
}
|
||||
@@ -542,18 +546,6 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
|
||||
channelName := req.ChannelName
|
||||
webhookType := req.Type
|
||||
|
||||
text = a.ProcessSlackText(text)
|
||||
req.Attachments = a.ProcessSlackAttachments(req.Attachments)
|
||||
|
||||
// attachments is in here for slack compatibility
|
||||
if len(req.Attachments) > 0 {
|
||||
if len(req.Props) == 0 {
|
||||
req.Props = make(model.StringInterface)
|
||||
}
|
||||
req.Props["attachments"] = req.Attachments
|
||||
webhookType = model.POST_SLACK_ATTACHMENT
|
||||
}
|
||||
|
||||
var hook *model.IncomingWebhook
|
||||
if result := <-hchan; result.Err != nil {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.invalid.app_error", nil, "err="+result.Err.Message, http.StatusBadRequest)
|
||||
@@ -561,6 +553,20 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
|
||||
hook = result.Data.(*model.IncomingWebhook)
|
||||
}
|
||||
|
||||
if len(req.Props) == 0 {
|
||||
req.Props = make(model.StringInterface)
|
||||
}
|
||||
|
||||
req.Props["webhook_display_name"] = hook.DisplayName
|
||||
|
||||
text = a.ProcessSlackText(text)
|
||||
req.Attachments = a.ProcessSlackAttachments(req.Attachments)
|
||||
// attachments is in here for slack compatibility
|
||||
if len(req.Attachments) > 0 {
|
||||
req.Props["attachments"] = req.Attachments
|
||||
webhookType = model.POST_SLACK_ATTACHMENT
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
var cchan store.StoreChannel
|
||||
|
||||
|
||||
@@ -33,13 +33,15 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
Text: "text",
|
||||
},
|
||||
},
|
||||
"webhook_display_name": hook.DisplayName,
|
||||
}, model.POST_SLACK_ATTACHMENT, "")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
for _, k := range []string{"from_webhook", "attachments"} {
|
||||
for _, k := range []string{"from_webhook", "attachments", "webhook_display_name"} {
|
||||
if _, ok := post.Props[k]; !ok {
|
||||
t.Log("missing one props: " + k)
|
||||
t.Fatal(k)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user