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

Include header images from template messages as attachments on preview message #1262

Merged
merged 2 commits into from
Jun 6, 2024

Conversation

rowanseymour
Copy link
Member

No description provided.

Copy link

codecov bot commented Jun 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.87%. Comparing base (17ca9c3) to head (fdbdcc8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1262      +/-   ##
==========================================
+ Coverage   81.85%   81.87%   +0.01%     
==========================================
  Files         278      278              
  Lines       17588    17592       +4     
==========================================
+ Hits        14397    14403       +6     
+ Misses       2610     2609       -1     
+ Partials      581      580       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"name": "cat_fact"
},
"template_variables": [
"http://example.com/cat2.jpg",
Copy link
Member Author

Choose a reason for hiding this comment

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

@norkans7 @ericnewcomer wondering if this shouldn't be "image/jpeg:http://example.com/cat2.jpg" so that these image variables are more consistent with how we do msg media in general.. and then the onus is on courier to transform it like it would a regular attachment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I adjusted courier side for that in nyaruka/courier#752

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I've updated this PR to assume that variable values look like attachments

variable := variables[index]
if variable.Type == "text" {
previewContent = strings.ReplaceAll(previewContent, fmt.Sprintf("{{%s}}", key), variable.Value)
} else if variable.Type == "image" && variable.Value != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about videos or documents? which are the other type that can be supported

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good point we should make this work for all header types since we're doing this work

}

variables[i] = &flows.TemplatingVariable{Type: v.Type(), Value: value}
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about having this ignore attachments that don't match the header type, e.g. ignore video/mp4:http://... if variable is type image... but the empty values will cause a send failure anyway and I think it will be more obvious to the user what the problem is if we just try to send the wrong attachment type and let WhatsApp complain about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I avoided the mismatch by using the attachment type in https://github.com/nyaruka/courier/pull/752/files should I keep using the parameter type instead?
Of course both approaches would fail to send if the parameter type is not the same as the one on the template

Copy link
Member Author

Choose a reason for hiding this comment

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

I think your change is fine.. in the case that someone updates their template but doesn't update the flow using it, we'll send a param of the wrong type to whatsapp, and I assume they'll send back a fairly clear error message.

@rowanseymour rowanseymour merged commit bded631 into main Jun 6, 2024
7 checks passed
@rowanseymour rowanseymour deleted the templates_with_images branch June 6, 2024 15:05
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 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