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

Add Dynamic Template Support #724

Merged

Conversation

carl-hartshorn
Copy link
Contributor

@carl-hartshorn carl-hartshorn commented Aug 16, 2018

Closes #716

Checklist

  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the [Contribution Guide] and my PR follows them.
  • I updated my branch with the master branch.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation about the functionality in the appropriate .md file
  • I have added in line documentation to the code I modified

Short description of what this PR does:

  • Add DynamicTemplateData property to Personalization
  • Add helper methods to SendGridMessage:
    • AddDynamicTemplateDataValue
    • AddDynamicTemplateDataValues
  • Add new MailHelper methods for creating dynamic template emails
    • CreateSingleDynamicTemplateEmail
    • CreateSingleDynamicTemplateEmailToMultipleRecipients
    • CreateMultipleDynamicTemplateEmailsToMultipleRecipients

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

SendGridDX commented Aug 16, 2018

CLA assistant check
All committers have signed the CLA.

@JaEdmuva
Copy link

@thinkingserious Please, is this coming out any soon?

@thinkingserious
Copy link
Contributor

Hi @JaEdmuva,

Yes, we have just released helpers for PHP and now we working to release the Python helpers. C# is next :)

With Best Regards,

Elmer

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap difficulty: hard fix is hard in difficulty labels Aug 16, 2018
@GlennGeelen
Copy link

Just a little suggest at https://github.com/sendgrid/sendgrid-csharp/pull/724/files#diff-a590903d5d8f3627d1e50f903d70631cR71

If the DynamicTemplateData property would be of type Dictionary<string, object> it would be possible to also give lists and child objects. So if I have a template that looks like this:

<table>
  {{#each list}}
  <tr>
    <td>{{this.title}}</td>
  </tr>
</table>

I could do something like:

var msg = new SendGridMessage
    {
      ...
      Personalizations = new System.Collections.Generic.List<Personalization>()
      {
        new Personalization
        {
          ...
          DynamicTemplateData = new System.Collections.Generic.Dictionary<string, object>()
          {
            { "list", new List<dynamic>()
              {
                new {title = "Title 1"},
                new {title = "Title 2"}
              }
            }
          }
        }
      }

I couldn't get the tests to work, else I would have made a PR myself. The scenario above worked for my template and I think it's not that big of a change. What do you think?

@carl-hartshorn
Copy link
Contributor Author

@GlennGeelen yeah that sounds like a good idea to me, especially with the deep object replacement support, I'll look into updating my PR accordingly. Cheers 😄

@puco
Copy link

puco commented Aug 21, 2018

Shouldn't DynamicTemplateData be just an object that should be serialized using a configurable / exposed JsonSerializerSettings.

@carl-hartshorn
Copy link
Contributor Author

@puco I like that idea, please see the latest commit. I've gone for simplicity initially and not added JsonSerializerSettings. I have added a test though which shows that adding [JsonProperty("snake_case_property_name")] for example to the DynamicTemplateData object works.

@carl-hartshorn
Copy link
Contributor Author

carl-hartshorn commented Aug 29, 2018

Hey @thinkingserious, I was just wondering if your comment here #716 (comment) means this PR is redundant?

@thinkingserious
Copy link
Contributor

Not at all @carl-hartshorn,

I working from your PR :)

@carl-hartshorn
Copy link
Contributor Author

@thinkingserious ah brilliant 😁 thank you

@Pieter-1337
Copy link

Pieter-1337 commented Aug 31, 2018

@thinkingserious , @carl-hartshorn Hi, can we already use this PR ? When I try to add dynamic template data to a new personalization, it has no parameter for it. I am currently using a workaround which enables me to pass strings, integers etc but I am currently not able to use objects in my templates

@thinkingserious thinkingserious merged commit 49f9e41 into sendgrid:master Sep 5, 2018
@thinkingserious
Copy link
Contributor

Hello @carl-hartshorn,

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
Contributor

Hello @Pieter-1337,

You can use this PR, but you might want to wait until I publish it on Nuget. The final step before I do that is to QA each of the relevant cases in USE_CASES.md.

With Best Regards,

Elmer

@CuriousCurmudgeon
Copy link

@thinkingserious Is there an expected turnaround time on that? My team is currently evaluating SendGrid for a project and I'm trying to set expectations around when this will be available.

Also, thanks to you and @carl-hartshorn for taking care of this!

@nlatin
Copy link

nlatin commented Sep 7, 2018

@thinkingserious yes we are waiting for this realese.. few days?

@thinkingserious
Copy link
Contributor

@nlatin,

Yes, I don't think it should be more than a few working days.

@ThomasChristmann
Copy link

Did this actually make it into the 9.10. release as the change log suggests? I've updated to 9.10 and am referencing it, but none of the changes are there (no methods on MailHelper, not property on Personalizations, etc)

@CuriousCurmudgeon
Copy link

@ThomasChristmann It did make it. I'm using it right now. Check out SendGridMessage#SetTemplateData and SendGridMessage#SetTemplateId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: hard fix is hard in difficulty status: code review request requesting a community code review or review from Twilio 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
10 participants