Skip to content
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

Closed
wants to merge 14 commits into from
Closed

WIP support WA template params #1199

wants to merge 14 commits into from

Conversation

norkans7
Copy link
Contributor

@norkans7 norkans7 commented Dec 1, 2023

No description provided.

@norkans7 norkans7 changed the title WIp support WA template params WIP support WA template params Dec 1, 2023
@@ -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"`
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TemplateParam

@@ -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"`
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (fc6dde4) 87.66% compared to head (3af0c28) 87.72%.

Files Patch % Lines
flows/actions/send_msg.go 82.85% 3 Missing and 3 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

// TemplateParam is a parameter for template translation
type TemplateParam struct {
Type string `json:"type"`
UUID TemplateParamUUID `json:"uuid"`
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

Comment on lines 157 to 162
for _, att := range evaluatedAttachments {
attType := strings.Split(att.ContentType(), "/")[0]
if templateParam.Type() == attType {
paramValue = att.URL()
break
}
Copy link
Contributor Author

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

Comment on lines 152 to 154
if strings.HasPrefix(compKey, "button.") {
paramValue = evaluatedQuickReplies[qrIndex]
qrIndex++
Copy link
Contributor Author

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

@norkans7 norkans7 marked this pull request as ready for review December 8, 2023 16:08
flows/msg.go Outdated

// TemplateParam represents a single parameter
type TemplateParam struct {
Type_ string `json:"type"`
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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

https://github.com/nyaruka/goflow/pull/1199/files#diff-f146c45610389d4ec808d1c8edafab8ca680779f7da5a7393ba3e8c3b86f427aR158

Copy link
Member

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.

@norkans7
Copy link
Contributor Author

Replaced by other PRs

@norkans7 norkans7 closed this Jan 25, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants