summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/outgoing_webhook.go32
-rw-r--r--model/outgoing_webhook_test.go2
2 files changed, 31 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
+}
diff --git a/model/outgoing_webhook_test.go b/model/outgoing_webhook_test.go
index 725423cdf..431b1f6c1 100644
--- a/model/outgoing_webhook_test.go
+++ b/model/outgoing_webhook_test.go
@@ -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)
}