Skip to content

Commit

Permalink
Merge pull request #1160 from nyaruka/truncate_lang_qrs
Browse files Browse the repository at this point in the history
Truncate quick replies that are too long
  • Loading branch information
rowanseymour authored Feb 8, 2023
2 parents 665640e + df9a3d4 commit afbaafc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flows/actions/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/nyaruka/gocommon/dates"
"github.com/nyaruka/gocommon/stringsx"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/assets"
Expand All @@ -26,6 +27,9 @@ const resultExtraMaxBytes = 10000
// max length of a message attachment (type:url)
const maxAttachmentLength = 2048

// max length of a quick reply
const maxQuickReplyLength = 64

// common category names
const (
CategorySuccess = "Success"
Expand Down Expand Up @@ -118,7 +122,7 @@ func (a *baseAction) evaluateMessage(run flows.Run, languages []envs.Language, a
logEvent(events.NewErrorf("quick reply text evaluated to empty string, skipping"))
continue
}
evaluatedQuickReplies = append(evaluatedQuickReplies, evaluatedQuickReply)
evaluatedQuickReplies = append(evaluatedQuickReplies, stringsx.TruncateEllipsis(evaluatedQuickReply, maxQuickReplyLength))
}

// although it's possible for the different parts of the message to have different languages, we want to resolve
Expand Down
33 changes: 33 additions & 0 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,39 @@
}
]
},
{
"description": "Quick replies truncated if they evaluate to something too long",
"action": {
"type": "send_msg",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"text": "Hi there",
"quick_replies": [
"yes",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
]
},
"events": [
{
"type": "msg_created",
"created_on": "2018-10-18T14:20:30.000123456Z",
"step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c",
"msg": {
"uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d",
"urn": "tel:+12065551212?channel=57f1078f-88aa-46f4-a59a-948a5739c03d&id=123",
"channel": {
"uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d",
"name": "My Android Phone"
},
"text": "Hi there",
"quick_replies": [
"yes",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed ..."
],
"locale": "eng-US"
}
}
]
},
{
"description": "Msg text that includes globals",
"action": {
Expand Down

0 comments on commit afbaafc

Please sign in to comment.