Skip to content

Dynamic templates support#449

Merged
thinkingserious merged 7 commits intosendgrid:masterfrom
marcusborges1:dynamic-templates-support
Oct 11, 2018
Merged

Dynamic templates support#449
thinkingserious merged 7 commits intosendgrid:masterfrom
marcusborges1:dynamic-templates-support

Conversation

@marcusborges1
Copy link
Copy Markdown
Contributor

Fixes #447

Hello everyone, this is my first contribution! I'am really excited in fix any problem that I may have missed, although I believe everything is ok. 😃

Changes

  • Implemented a helper similar to what we have for the legacy templates
  • Update thed USE_CASES.md example to demonstrate the new Dynamic Templates using the helper and re-name the current example to Legacy

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Jul 30, 2018
@SendGridDX
Copy link
Copy Markdown

SendGridDX commented Jul 30, 2018

CLA assistant check
All committers have signed the CLA.

@nickneiman
Copy link
Copy Markdown

Any chance for a public void addDynamicTemplateData(Map<String, String> dynamicTemplateData) or public void setDynamicTemplateData(Map<String, String> dynamicTemplateData) method?

@thinkingserious
Copy link
Copy Markdown
Contributor

That's a good idea @nickneiman, thanks for contributing!

@Markuus13,

If you don't have time to add that feature, no problem, just let me know and I'll open a separate issue for @nickneiman's request.

@marcusborges1
Copy link
Copy Markdown
Contributor Author

@nickneiman @thinkingserious I'll add that feature today.

@pdtyreus
Copy link
Copy Markdown

I suspect that dynamicTemplateData should be a Map<String,Object> not a Map<String,String>. The API accepts nested JSON, not just strings. I did something very similar here.

@marcusborges1
Copy link
Copy Markdown
Contributor Author

@pdtyreus thanks for the contribution, that's exactly what I was thinking!
Working on it now.

@marcusborges1
Copy link
Copy Markdown
Contributor Author

Updated PR to be possible include more complex types of dynamic template data. Before was only possible to generate a structure like:

"dynamic_template_data": {
  "city": "Denver",
  "name": "Example User"
}

Now it's possible to generate something like:

"dynamic_template_data": {
  "city": "Denver",
  "name": "Example User",
  "items": [
    {
      "text": "Old Line Sneakers",
      "price": "$ 59.95"
    },
    {
      "text": "New Line Sneakers",
      "price": "$ 79.95"
    }
  ]
}

@marcusborges1
Copy link
Copy Markdown
Contributor Author

I was wondering if making public void addDynamicTemplateData(String key, Object value) a private method and exposing 3 other public methods to encapsulate that first was a good choice.

public void addDynamicTemplateData(String key, String value)
public void addDynamicTemplateData(String key, Map<String, ?> value)
public void addDynamicTemplateData(String key, List<?> value)

The idea here is to have interface less error prone when adding a dynamic template data, what do you guys think?

@nickneiman
Copy link
Copy Markdown

@Markuus13 The idea of creating a safer interface is nice but you might actually end up limiting support for some possibly valuable scenarios. Mail is using the Jackson ObjectMapper class which actually has support for converting any class (beyond String, Map, or List) to a map of properties. I'm not sure if Sendgrid wants to support that functionality but it it something worth thinking about. Short blurb on ObjectMapper: http://www.baeldung.com/jackson-object-mapper-tutorial

@JsonProperty("dynamic_template_data")
public Map<String,Object> getDynamicTemplateData() {
if(dynamicTemplateData == null)
return Collections.<String,Object>emptyMap();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick: It's generally safer to include curly brackets for all if statements. It can help protect against a future developer accidentally introducing a bug if another line is added to the if statement.

Alternatively, a more succinct way of writing this method would be:

    return (dynamicTemplateData == null) ? Collections.<String, Object>emptyMap() : dynamicTemplateData;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @dgranahan!
I use curly brackets in if statements per default on my projects, but I didn't use here because I saw others methods on this class following this standard. I'll update the PR with this change. 👍

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap difficulty: medium fix is medium in difficulty labels Aug 4, 2018
@booi
Copy link
Copy Markdown

booi commented Aug 9, 2018

Any idea when this will be merged?

@thinkingserious
Copy link
Copy Markdown
Contributor

Thanks for all the comments and votes everyone! They help move this issue up the queue in our backlog. I can't make any promises, but I'm looking to get this one out real soon.

If anyone has time for a code review, that would be greatly appreciated and save a bit of time.

With Best Regards,

Elmer

dynamicTemplateData.put(key, value);
} else {
dynamicTemplateData.put(key, value);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick: you can save yourself a couple lines of code if you write this method like:

if (dynamicTemplateData == null) {
  dynamicTemplateData = new HashMap<String,Object>();
}
dynamicTemplateData.put(key, value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for taking the time to review @dgranahan!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved.

@pacey
Copy link
Copy Markdown

pacey commented Aug 14, 2018

Good work on supporting this guys! Any idea on a timeframe on when it could be merged and then released?

@thinkingserious
Copy link
Copy Markdown
Contributor

Hi @pacey!

Thanks for the kind words!

I can't give a firm timeframe, but I can say this is a high priority PR for us and should be merged soon.

Your comment/vote helps increase the position in our backlog queue.

With Best Regards,

Elmer

@Octember
Copy link
Copy Markdown

Any idea when this will be finished? 7 days with no activity does not bode well for those of us waiting for this to get merged.

@marshallpierce
Copy link
Copy Markdown

I've had trivial PRs waiting in this project for months, so I wouldn't hold your breath. Apply workarounds and move on...

@af4ro
Copy link
Copy Markdown
Contributor

af4ro commented Aug 20, 2018

@Markuus13 would it be fine if I pushed minor readability updates to speed up the process and help @thinkingserious merge this faster according to Sendgrid's requirements?

We are trying our best to merge this in no later than the end of this week and I'm trying to help out from within the SendGrid team.

Please let me know if you would be fine with that and thank you for the amazing PR!

@thinkingserious
Copy link
Copy Markdown
Contributor

thinkingserious commented Aug 21, 2018

HI @marshallpierce, @Octember,

We just expanded our team today! We are committed to improving our developer experience at SendGrid and we greatly appreciate your past contributions and hope you will continue to collaborate with us.

My apologies for the delays, they are my fault. We just released support for the PHP and Python SDKs, C# is next, followed by this SDK, so I'm hopeful this one will be released shortly.

With Best Regards,

Elmer

@suciuandrei94
Copy link
Copy Markdown

Hello, first of all thanks a lot for the fix @Markuus13 , second when is this getting merged into the library?It is really urgent for me to get this feature ASAP @thinkingserious

@af4ro af4ro added status: ready for deploy code ready to be released in next deploy and removed status: code review request requesting a community code review or review from Twilio labels Aug 21, 2018
@adam6806
Copy link
Copy Markdown

@suciuandrei94 just extend the Personalization class and copy the substitution code and change it to reflect the correct dynamic template json. It's very straightforward. I did so I could move on until this gets merged. @Markuus13 came here looking to make a PR and saw you already had it covered ;) @thinkingserious do you guys hire remote workers? I just left Denver. Almost applied for an internship there a while back but ended up getting something else.

@thinkingserious
Copy link
Copy Markdown
Contributor

Hi @adam6806,

Please send us an email to [email protected] to continue the conversation. Thanks!

@samufort
Copy link
Copy Markdown

Can we have some updates for this PR ? Thanks !

@tbohnen
Copy link
Copy Markdown

tbohnen commented Sep 26, 2018

@thinkingserious Any eta on when this will be merged?

@booi
Copy link
Copy Markdown

booi commented Sep 29, 2018

It seems like java will not have first class support from sendgrid. I am disappointed that we all basically have to build/extend this ourselves.

Email should not be this difficult and we will begin to look at other providers that bother to support their paying customers.

@suciuandrei94
Copy link
Copy Markdown

In my opinion this is getting ridiculous, being a developer myself this looks to me like 30 minutes fix. If it takes this long to do a simple fix, I wonder what will happen when something serious comes up.

@thinkingserious
Copy link
Copy Markdown
Contributor

@samufort, @booi, @suciuandrei94,

Thank you for taking the time to check in, I appreciate it!

This SDK is next on the list to get updated with Dynamic Template helpers. I was hoping to have that done by now, but I could not get it done. Every day that goes by with this unreleased seriously disturbs me :( I hope you can accept my sincere apology, I know it's frustrating. Out of the 7 languages we support, Java, in particular, is very important to us.

On another related note, our team is finally in the process of expanding and I'm excited beyond measure because I know this will allow us to support all of you much better. Thank you for your continued patience, your time is valuable to us!

In the meantime, any other code reviews on this PR are very much appreciated and help make sure we get this release right the first time. If not, no worries, we'll still get it done ASAP.

With Best Regards,

Elmer

@kgawrys
Copy link
Copy Markdown

kgawrys commented Oct 11, 2018

@thinkingserious have you made any progress regarding merging this PR ? I would love to have that in official library without hacking or building my own version.

@mmazi
Copy link
Copy Markdown

mmazi commented Oct 11, 2018

FWIW, I'm using this simple custom subclass instead of com.sendgrid.Personalization and it works:

    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
    public static class DynamicTemplatePersonalization extends Personalization {

        @JsonProperty
        private Map<String, Object> dynamicTemplateData = new HashMap<>();

        public void addDynamicTemplateData(String key, Object value) {
            dynamicTemplateData.put(key, value);
        }
    }

@thinkingserious thinkingserious merged commit bd65fc7 into sendgrid:master Oct 11, 2018
@thinkingserious
Copy link
Copy Markdown
Contributor

Hello @Markuus13,

Thanks again for the PR!

We want to show our appreciation by sending you some swag. Could you please fill out this form so we can send it to you? Thanks!

Team SendGrid DX

@thinkingserious
Copy link
Copy Markdown
Contributor

This has been released as part of v4.3.0. Thanks to all for the patience and support!

We should have another release fairly soon, you can subscribe here to be notified by email.

@marcusborges1
Copy link
Copy Markdown
Contributor Author

Hello @thinkingserious,
It was a pleasure to contribute!
I already filled out the form, thanks!

@nieldw
Copy link
Copy Markdown

nieldw commented Nov 2, 2018

Hey @tbohnen , this was released in v4.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

difficulty: medium fix is medium in difficulty status: ready for deploy code ready to be released in next deploy type: community enhancement feature request not on Twilio's roadmap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Dynamic Template Support