diff --git a/flows/actions/base.go b/flows/actions/base.go index fb6e8b107..b7265d6d5 100644 --- a/flows/actions/base.go +++ b/flows/actions/base.go @@ -81,7 +81,7 @@ func (a *baseAction) Validate() error { return nil } func (a *baseAction) LocalizationUUID() uuids.UUID { return uuids.UUID(a.UUID_) } // helper function for actions that send a message (text + attachments) that must be localized and evalulated -func (a *baseAction) evaluateMessage(run flows.Run, languages []i18n.Language, actionText string, actionAttachments []string, actionQuickReplies []string, logEvent flows.EventCallback) (string, []utils.Attachment, []string, i18n.Language) { +func (a *baseAction) evaluateMessage(run flows.Run, languages []i18n.Language, actionText string, actionAttachments []string, actionQuickReplies []string, logEvent flows.EventCallback) (*flows.MsgContent, i18n.Language) { // localize and evaluate the message text localizedText, txtLang := run.GetTextArray(uuids.UUID(a.UUID()), "text", []string{actionText}, languages) evaluatedText, _ := run.EvaluateTemplate(localizedText[0], logEvent) @@ -126,7 +126,7 @@ func (a *baseAction) evaluateMessage(run flows.Run, languages []i18n.Language, a lang = qrsLang } - return evaluatedText, evaluatedAttachments, evaluatedQuickReplies, lang + return &flows.MsgContent{Text: evaluatedText, Attachments: evaluatedAttachments, QuickReplies: evaluatedQuickReplies}, lang } // helper to save a run result and log it as an event diff --git a/flows/actions/send_broadcast.go b/flows/actions/send_broadcast.go index 081830879..d34f421c4 100644 --- a/flows/actions/send_broadcast.go +++ b/flows/actions/send_broadcast.go @@ -74,12 +74,8 @@ func (a *SendBroadcastAction) Execute(run flows.Run, step flows.Step, logModifie for _, language := range languages { languages := []i18n.Language{language, run.Flow().Language()} - evaluatedText, evaluatedAttachments, evaluatedQuickReplies, _ := a.evaluateMessage(run, languages, a.Text, a.Attachments, a.QuickReplies, logEvent) - translations[language] = &flows.BroadcastTranslation{ - Text: evaluatedText, - Attachments: evaluatedAttachments, - QuickReplies: evaluatedQuickReplies, - } + content, _ := a.evaluateMessage(run, languages, a.Text, a.Attachments, a.QuickReplies, logEvent) + translations[language] = content } // if we don't have any recipients, noop diff --git a/flows/actions/send_msg.go b/flows/actions/send_msg.go index 6a7e6ad69..5555f17c1 100644 --- a/flows/actions/send_msg.go +++ b/flows/actions/send_msg.go @@ -74,7 +74,7 @@ func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flow unsendableReason = flows.UnsendableReasonContactStatus } - evaluatedText, evaluatedAttachments, evaluatedQuickReplies, lang := a.evaluateMessage(run, nil, a.Text, a.Attachments, a.QuickReplies, logEvent) + content, lang := a.evaluateMessage(run, nil, a.Text, a.Attachments, a.QuickReplies, logEvent) locale := currentLocale(run, lang) destinations := run.Contact().ResolveDestinations(a.AllURNs) @@ -101,7 +101,7 @@ func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flow } if msg == nil { - msg = flows.NewMsgOut(urn, channelRef, evaluatedText, evaluatedAttachments, evaluatedQuickReplies, nil, a.Topic, locale, unsendableReason) + msg = flows.NewMsgOut(urn, channelRef, content.Text, content.Attachments, content.QuickReplies, nil, a.Topic, locale, unsendableReason) } logEvent(events.NewMsgCreated(msg)) @@ -110,7 +110,7 @@ func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flow // if we couldn't find a destination, create a msg without a URN or channel and it's up to the caller // to handle that as they want if len(destinations) == 0 { - msg := flows.NewMsgOut(urns.NilURN, nil, evaluatedText, evaluatedAttachments, evaluatedQuickReplies, nil, a.Topic, locale, flows.UnsendableReasonNoDestination) + msg := flows.NewMsgOut(urns.NilURN, nil, content.Text, content.Attachments, content.QuickReplies, nil, a.Topic, locale, flows.UnsendableReasonNoDestination) logEvent(events.NewMsgCreated(msg)) } diff --git a/flows/msg.go b/flows/msg.go index 7240e07c2..85fc8261d 100644 --- a/flows/msg.go +++ b/flows/msg.go @@ -189,17 +189,17 @@ func NewMsgTemplating(template *assets.TemplateReference, namespace string, comp return &MsgTemplating{Template: template, Namespace: namespace, Components: components, Variables: variables} } -// BroadcastTranslation is the broadcast content in a particular language -type BroadcastTranslation struct { +// MsgContent is message content in a particular language +type MsgContent struct { Text string `json:"text"` Attachments []utils.Attachment `json:"attachments,omitempty"` QuickReplies []string `json:"quick_replies,omitempty"` } -type BroadcastTranslations map[i18n.Language]*BroadcastTranslation +type BroadcastTranslations map[i18n.Language]*MsgContent // ForContact is a utility to help callers select the translation for a contact -func (b BroadcastTranslations) ForContact(e envs.Environment, c *Contact, baseLanguage i18n.Language) (*BroadcastTranslation, i18n.Language) { +func (b BroadcastTranslations) ForContact(e envs.Environment, c *Contact, baseLanguage i18n.Language) (*MsgContent, i18n.Language) { // first try the contact language if it is valid if c.Language() != i18n.NilLanguage && slices.Contains(e.AllowedLanguages(), c.Language()) { t := b[c.Language()] diff --git a/flows/msg_test.go b/flows/msg_test.go index 750d156b9..477f466b0 100644 --- a/flows/msg_test.go +++ b/flows/msg_test.go @@ -123,9 +123,9 @@ func TestIVRMsgOut(t *testing.T) { func TestBroadcastTranslations(t *testing.T) { bcastTrans := flows.BroadcastTranslations{ - "eng": &flows.BroadcastTranslation{Text: "Hello"}, - "fra": &flows.BroadcastTranslation{Text: "Bonjour"}, - "spa": &flows.BroadcastTranslation{Text: "Hola"}, + "eng": &flows.MsgContent{Text: "Hello"}, + "fra": &flows.MsgContent{Text: "Bonjour"}, + "spa": &flows.MsgContent{Text: "Hola"}, } baseLanguage := i18n.Language("eng")