From 3f0580a6ed2da5057347354646c10aad72e72d4f Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Thu, 7 Dec 2023 19:40:15 +0200 Subject: [PATCH] Use predictable quick replies indexes --- flows/actions/send_msg.go | 9 ++++++--- flows/actions/testdata/send_msg.json | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flows/actions/send_msg.go b/flows/actions/send_msg.go index e9b60fec3..411b6f6c5 100644 --- a/flows/actions/send_msg.go +++ b/flows/actions/send_msg.go @@ -1,6 +1,7 @@ package actions import ( + "strconv" "strings" "github.com/nyaruka/gocommon/i18n" @@ -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 { @@ -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)) + } paramValue = evaluatedQuickReplies[qrIndex] - qrIndex++ } else if templateParam.Type() != "text" { paramValue = "" for _, att := range evaluatedAttachments { diff --git a/flows/actions/testdata/send_msg.json b/flows/actions/testdata/send_msg.json index 394e6c52d..4df17dfa1 100644 --- a/flows/actions/testdata/send_msg.json +++ b/flows/actions/testdata/send_msg.json @@ -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", @@ -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",