Skip to content

Commit

Permalink
Drop support for localizing template variables in send_msg actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 20, 2024
1 parent 13265f7 commit 92f612e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 119 deletions.
8 changes: 2 additions & 6 deletions flows/actions/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package actions
import (
"github.com/nyaruka/gocommon/i18n"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/flows/events"
Expand Down Expand Up @@ -91,12 +90,9 @@ func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flow
locales := []i18n.Locale{run.Session().MergedEnvironment().DefaultLocale(), run.Session().Environment().DefaultLocale()}
translation := template.FindTranslation(dest.Channel, locales)
if translation != nil {
// TODO in future we won't be localizing template variables
localizedVariables, _ := run.GetTextArray(uuids.UUID(a.UUID()), "template_variables", a.TemplateVariables, nil)

// evaluate the variables
evaluatedVariables := make([]string, len(localizedVariables))
for i, varExp := range localizedVariables {
evaluatedVariables := make([]string, len(a.TemplateVariables))
for i, varExp := range a.TemplateVariables {
v, _ := run.EvaluateTemplate(varExp, logEvent)
evaluatedVariables[i] = v
}
Expand Down
119 changes: 6 additions & 113 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,100 +491,6 @@
"parent_refs": []
}
},
{
"description": "Msg with a matching template with localized variables",
"action": {
"type": "send_msg",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"text": "Hi Ryan Lewis, who's a good boy?",
"template": {
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation"
},
"template_variables": [
"@contact.name",
"boy"
]
},
"localization": {
"spa": {
"ad154980-7bf7-4ab8-8728-545fd6378912": {
"template_variables": [
"@contact.name",
"niño"
]
}
}
},
"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": "Hola Ryan Lewis, quien es un niño excelente?",
"templating": {
"template": {
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation"
},
"components": [
{
"name": "body",
"type": "body/text",
"variables": {
"1": 0,
"2": 1
}
}
],
"variables": [
{
"type": "text",
"value": "Ryan Lewis"
},
{
"type": "text",
"value": "niño"
}
]
},
"locale": "spa"
}
}
],
"templates": [
"Hi Ryan Lewis, who's a good boy?",
"@contact.name",
"boy",
"@contact.name",
"niño"
],
"localizables": [
"Hi Ryan Lewis, who's a good boy?",
"@contact.name",
"boy"
],
"inspection": {
"dependencies": [
{
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation",
"type": "template"
}
],
"issues": [],
"results": [],
"waiting_exits": [],
"parent_refs": []
}
},
{
"description": "Msg with template but no variables",
"action": {
Expand Down Expand Up @@ -803,16 +709,7 @@
]
},
"localization": {
"spa": {
"ad154980-7bf7-4ab8-8728-545fd6378912": {
"template_variables": [
"@contact.name",
"niño",
"Sip",
"Nop"
]
}
}
"spa": {}
},
"events": [
{
Expand All @@ -826,9 +723,9 @@
"uuid": "57f1078f-88aa-46f4-a59a-948a5739c03d",
"name": "My Android Phone"
},
"text": "Actualizar\n\nHola, Ryan Lewis, tu género está guardado como niño.",
"text": "Actualizar\n\nHola, Ryan Lewis, tu género está guardado como boy.",
"quick_replies": [
"Sip",
"Yeah",
"No"
],
"templating": {
Expand Down Expand Up @@ -860,11 +757,11 @@
},
{
"type": "text",
"value": "niño"
"value": "boy"
},
{
"type": "text",
"value": "Sip"
"value": "Yeah"
}
]
},
Expand All @@ -879,11 +776,7 @@
"@contact.name",
"boy",
"Yeah",
"Nope",
"@contact.name",
"niño",
"Sip",
"Nop"
"Nope"
],
"localizables": [
"Hey Ryan Lewis, your gender is saved as boy.",
Expand Down

0 comments on commit 92f612e

Please sign in to comment.