Skip to content

Commit

Permalink
Merge pull request #109 from nyaruka/collate_for_triggers
Browse files Browse the repository at this point in the history
Use input collation when matching msg triggers
  • Loading branch information
rowanseymour authored Aug 23, 2023
2 parents db0c88b + bd52d00 commit 47ba7c7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/models/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/lib/pq"
"github.com/nyaruka/gocommon/dbutil"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/triggers"
"github.com/nyaruka/goflow/utils"
Expand Down Expand Up @@ -125,12 +126,12 @@ func FindMatchingMsgTrigger(oa *OrgAssets, contact *flows.Contact, text string)
only := false
if len(words) > 0 {
// our keyword is our first word
keyword = strings.ToLower(words[0])
keyword = words[0]
only = len(words) == 1
}

candidates := findTriggerCandidates(oa, KeywordTriggerType, func(t *Trigger) bool {
return t.Keyword() == keyword && (t.MatchType() == MatchFirst || (t.MatchType() == MatchOnly && only))
return envs.CollateEquals(oa.Env(), t.Keyword(), keyword) && (t.MatchType() == MatchFirst || (t.MatchType() == MatchOnly && only))
})

// if we have a matching keyword trigger return that, otherwise we move on to catchall triggers..
Expand Down Expand Up @@ -220,7 +221,6 @@ type triggerMatch struct {
// include (2) + exclude (1) = 3
// include (2) = 2
// exclude (1) = 1
//
const triggerScoreByChannel = 4
const triggerScoreByInclusion = 2
const triggerScoreByExclusion = 1
Expand Down

0 comments on commit 47ba7c7

Please sign in to comment.