-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP support WA template params #1199
Conversation
assets/static/template.go
Outdated
@@ -43,16 +43,20 @@ type TemplateTranslation struct { | |||
Locale_ i18n.Locale `json:"locale" validate:"required"` | |||
Namespace_ string `json:"namespace"` | |||
VariableCount_ int `json:"variable_count"` | |||
Components_ []map[string]any `json:"components"` | |||
Params_ map[string][]any `json:"params"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason not to use a struct for param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TemplateParam
assets/static/template.go
Outdated
@@ -43,16 +43,20 @@ type TemplateTranslation struct { | |||
Locale_ i18n.Locale `json:"locale" validate:"required"` | |||
Namespace_ string `json:"namespace"` | |||
VariableCount_ int `json:"variable_count"` | |||
Components_ []map[string]any `json:"components"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only use Content for generating a preview of the message so I guess components would be the same... couldn't these just be strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can keep using content for the preview here and make sure each template has that generate properly when syncing them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tho wouldn't we want to convert button components into quick replies etc? I kinda hate putting whatsapp specific knowledge in the engine, right in the send_msg action but I don't see any other way. Let's just try to isolate it in a single function for now that takes a template + parameters and returns a MsgOut
.
The other way to approach this would be to put the onus on the UI to render a preview of the message based on the templating data.. but then the message still looks empty in API fetches, archives etc, so I think I prefer having the engine continue to create a preview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ideally we need have the quick replies turned/matched to the buttons of the templates
I have not thought of quick replies so far, I want to make sure we support all components for templates and see how to make the QRs and buttons merged
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1199 +/- ##
==========================================
+ Coverage 87.66% 87.72% +0.06%
==========================================
Files 260 260
Lines 10869 10898 +29
==========================================
+ Hits 9528 9560 +32
+ Misses 922 917 -5
- Partials 419 421 +2 ☔ View full report in Codecov by Sentry. |
b27d1e4
to
54710ac
Compare
assets/template.go
Outdated
// TemplateParam is a parameter for template translation | ||
type TemplateParam struct { | ||
Type string `json:"type"` | ||
UUID TemplateParamUUID `json:"uuid"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that by. adding a UUID field we'll be able to support the localizations
The editor will use the UUID for the field on the UI too
Now we have to always add the UUID when we are generating the params for the template translation so we have stay consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the template asset which isn't localized and doesn't have values. Shouldn't this just be type
?
And then we have a different struct on templating
on send_msg
actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was thinking on where the UUID should be generated and I think that should be on the UI in the flow editor when the template is selected.
I will look into that again
7d544f6
to
8e80ddc
Compare
822e87c
to
5f20a37
Compare
5f20a37
to
55cc248
Compare
flows/actions/send_msg.go
Outdated
for _, att := range evaluatedAttachments { | ||
attType := strings.Split(att.ContentType(), "/")[0] | ||
if templateParam.Type() == attType { | ||
paramValue = att.URL() | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use first attachment matching the type we expect from the template params
flows/actions/send_msg.go
Outdated
if strings.HasPrefix(compKey, "button.") { | ||
paramValue = evaluatedQuickReplies[qrIndex] | ||
qrIndex++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for QRs we iterate through them and take the next available for the parameter button parameters
54c8017
to
62b2311
Compare
62b2311
to
5ed7d0d
Compare
flows/msg.go
Outdated
|
||
// TemplateParam represents a single parameter | ||
type TemplateParam struct { | ||
Type_ string `json:"type"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need type
here? Wondering if each Msg.Templating
could be stored as something like...
type ComponentVariables struct {
UUID uuids.UUID
Variables []string
}
map[string]ComponentVariables
and then the localization can be of the ComponentVariables
instead of each param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using Variables []string
we are loosing the type for the parameter/variable and that is essential to know I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well let's really think... do we need it? Where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example when we have the expected parameters as an image, video or document attachment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that's needed tho.. all of these values are just text expressions. The type is needed for the editor to know what controls to surface. If we have a header component with an image param, we'll use variable[0] for that image.
Replace TemplateParam with ComponentsVariables
Replaced by other PRs |
No description provided.