Skip to content

Commit

Permalink
Use predictable quick replies indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 7, 2023
1 parent 5ed7d0d commit 3f0580a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions flows/actions/send_msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actions

import (
"strconv"
"strings"

"github.com/nyaruka/gocommon/i18n"
Expand Down Expand Up @@ -130,8 +131,6 @@ func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flow
}

func getTemplatingMsg(action *SendMsgAction, run flows.Run, urn urns.URN, channelRef *assets.ChannelReference, templateTranslation *flows.TemplateTranslation, evaluatedAttachments []utils.Attachment, evaluatedQuickReplies []string, unsendableReason flows.UnsendableReason, logEvent flows.EventCallback) *flows.MsgOut {
qrIndex := 0

localizedVariables, _ := run.GetTextArray(uuids.UUID(action.Templating.UUID), "variables", action.Templating.Variables, nil)
evaluatedVariables := make([]string, len(localizedVariables))
for i, variable := range localizedVariables {
Expand All @@ -150,8 +149,12 @@ func getTemplatingMsg(action *SendMsgAction, run flows.Run, urn urns.URN, channe
var paramValue string
var err error
if strings.HasPrefix(compKey, "button.") {

qrIndex, err := strconv.Atoi(strings.TrimPrefix(compKey, "button."))
if err != nil {
logEvent(events.NewError(err))

Check warning on line 155 in flows/actions/send_msg.go

View check run for this annotation

Codecov / codecov/patch

flows/actions/send_msg.go#L155

Added line #L155 was not covered by tests
}
paramValue = evaluatedQuickReplies[qrIndex]
qrIndex++
} else if templateParam.Type() != "text" {
paramValue = ""
for _, att := range evaluatedAttachments {
Expand Down
8 changes: 4 additions & 4 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -873,14 +873,14 @@
"value": "boy"
}
],
"button.1": [
"button.0": [
{
"type": "text",
"uuid": "31cd12f7-5a8d-4421-a289-d47cdfb7cff1",
"value": "no_used"
}
],
"button.2": [
"button.1": [
{
"type": "text",
"uuid": "67ed8f42-4fce-4e8a-b788-8a7afc9b02ea",
Expand Down Expand Up @@ -968,14 +968,14 @@
"value": "http://example.com/rojo.jpg"
}
],
"button.1": [
"button.0": [
{
"type": "text",
"uuid": "31cd12f7-5a8d-4421-a289-d47cdfb7cff1",
"value": "Si"
}
],
"button.2": [
"button.1": [
{
"type": "text",
"uuid": "67ed8f42-4fce-4e8a-b788-8a7afc9b02ea",
Expand Down

0 comments on commit 3f0580a

Please sign in to comment.