[PLT-6676] Make OutgoingWebhook to fire when post has no text content but only attachment (#6935)
* make OutgoingWebhook to fire when post has no text content but only attachment * update per comment and modify payload & test
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
8fb58b1fc9
Коммит
21a3219b9b
@@ -42,6 +42,7 @@ type OutgoingWebhookPayload struct {
|
||||
PostId string `json:"post_id"`
|
||||
Text string `json:"text"`
|
||||
TriggerWord string `json:"trigger_word"`
|
||||
FileIds string `json:"file_ids"`
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhookPayload) ToJSON() string {
|
||||
@@ -66,6 +67,7 @@ func (o *OutgoingWebhookPayload) ToFormValues() string {
|
||||
v.Set("post_id", o.PostId)
|
||||
v.Set("text", o.Text)
|
||||
v.Set("trigger_word", o.TriggerWord)
|
||||
v.Set("file_ids", o.FileIds)
|
||||
|
||||
return v.Encode()
|
||||
}
|
||||
@@ -198,8 +200,8 @@ func (o *OutgoingWebhook) PreUpdate() {
|
||||
o.UpdateAt = GetMillis()
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) HasTriggerWord(word string) bool {
|
||||
if len(o.TriggerWords) == 0 || len(word) == 0 {
|
||||
func (o *OutgoingWebhook) TriggerWordExactMatch(word string) bool {
|
||||
if len(word) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -213,7 +215,7 @@ func (o *OutgoingWebhook) HasTriggerWord(word string) bool {
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) TriggerWordStartsWith(word string) bool {
|
||||
if len(o.TriggerWords) == 0 || len(word) == 0 {
|
||||
if len(word) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -225,3 +227,27 @@ func (o *OutgoingWebhook) TriggerWordStartsWith(word string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (o *OutgoingWebhook) GetTriggerWord(word string, isExactMatch bool) (triggerWord string) {
|
||||
if len(word) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if isExactMatch {
|
||||
for _, trigger := range o.TriggerWords {
|
||||
if trigger == word {
|
||||
triggerWord = trigger
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, trigger := range o.TriggerWords {
|
||||
if strings.HasPrefix(word, trigger) {
|
||||
triggerWord = trigger
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return triggerWord
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ func TestOutgoingWebhookPayloadToFormValues(t *testing.T) {
|
||||
PostId: "PostId",
|
||||
Text: "Text",
|
||||
TriggerWord: "TriggerWord",
|
||||
FileIds: "FileIds",
|
||||
}
|
||||
v := url.Values{}
|
||||
v.Set("token", "Token")
|
||||
@@ -149,6 +150,7 @@ func TestOutgoingWebhookPayloadToFormValues(t *testing.T) {
|
||||
v.Set("post_id", "PostId")
|
||||
v.Set("text", "Text")
|
||||
v.Set("trigger_word", "TriggerWord")
|
||||
v.Set("file_ids", "FileIds")
|
||||
if got, want := p.ToFormValues(), v.Encode(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("Got %+v, wanted %+v", got, want)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user