diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-07-19 03:43:31 +0800 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-07-18 15:43:31 -0400 |
commit | 21a3219b9b1df033635631afa751742bd4c56ea0 (patch) | |
tree | 6e97722afc7fc9ff3cee1c562732bd0924cf71da /model/outgoing_webhook.go | |
parent | 8fb58b1fc9f38db22beca42dcd3e692fe5b547ba (diff) | |
download | chat-21a3219b9b1df033635631afa751742bd4c56ea0.tar.gz chat-21a3219b9b1df033635631afa751742bd4c56ea0.tar.bz2 chat-21a3219b9b1df033635631afa751742bd4c56ea0.zip |
[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
Diffstat (limited to 'model/outgoing_webhook.go')
-rw-r--r-- | model/outgoing_webhook.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/model/outgoing_webhook.go b/model/outgoing_webhook.go index 70c65bec7..59408c24e 100644 --- a/model/outgoing_webhook.go +++ b/model/outgoing_webhook.go @@ -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 +} |