Skip to content

Dynamic template support#263

Merged
thinkingserious merged 9 commits intosendgrid:masterfrom
devchas:dynamic-template-support
Sep 5, 2018
Merged

Dynamic template support#263
thinkingserious merged 9 commits intosendgrid:masterfrom
devchas:dynamic-template-support

Conversation

@devchas
Copy link
Copy Markdown
Contributor

@devchas devchas commented Aug 10, 2018

Fixes #260

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 dynamic template support for Go library
  • Add helper method for dynamic template data
  • Add dynamic template example in examples/helpers/mail/example.go (this had to be done in a separate function because dynamic template data and substitutions may not be used in the same API call
  • Add documentation and examples in USE_CASES.md

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

SendGridDX commented Aug 10, 2018

CLA assistant check
All committers have signed the CLA.

Comment thread USE_CASES.md Outdated

# Table of Contents

* [Dynamic Template Data](#dynamic-template-data)
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.

In our UI, we are calling these Transactional Templates and the previous Transactional Templates are now called Legacy Templates.

@thinkingserious thinkingserious added difficulty: medium fix is medium in difficulty type: twilio enhancement feature request on Twilio's roadmap labels Aug 14, 2018
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 14, 2018

Codecov Report

Merging #263 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #263      +/-   ##
==========================================
+ Coverage   70.75%   70.95%   +0.19%     
==========================================
  Files           3        3              
  Lines         448      451       +3     
==========================================
+ Hits          317      320       +3     
  Misses        127      127              
  Partials        4        4
Impacted Files Coverage Δ
helpers/mail/mail_v3.go 98.11% <100%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25e917a...fee1a60. Read the comment docs.

@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 14, 2018
@Revinand
Copy link
Copy Markdown

Any update on this? When this PR will be merged?

@thinkingserious
Copy link
Copy Markdown
Contributor

Hello @Revinand,

We just launched support PHP and Python, next is C#, Java, Node.js and then Go. I can't give you a firm timeline, but it's coming soon. It's a high priority for our team.

My apologies for the delay.

With Best Regards,

Elmer

@ivannikolic
Copy link
Copy Markdown

Hi @thinkingserious,

We created some dynamic templates in SendGrid and now we depend on this pull request to be able to use them with the SendGrid's Go library.
I understand that you can't give the firm timeline, but can you just tell me the rough estimation when can we expect the feature to be available? Is it a matter of days, weeks, months?

Ivan Nikolic
ricardo.ch

@seangransee
Copy link
Copy Markdown

@ivannikolic In the meantime, I'm just using github.com/devchas/sendgrid-go/helpers/mail checked out to branch dynamic-template-support.

@thinkingserious
Copy link
Copy Markdown
Contributor

Hi @ivannikolic,

I would say it's a matter of weeks. We have C# (in progress), Java, Node.js (just needs documentation update) to go before we tackle this one.

With Best Regards,

Elmer

@devchas
Copy link
Copy Markdown
Contributor Author

devchas commented Aug 22, 2018

Hi @ivannikolic - in addition to the suggestion @seangransee made, you can always create the request body of the API call without the helper method, passing a JSON string. The dynamic templates will still work.

@ivannikolic
Copy link
Copy Markdown

@seangransee @thinkingserious @devchas Thank you all for the ideas and helpful information!

@kayue
Copy link
Copy Markdown

kayue commented Aug 31, 2018

For those who cannot wait for the PR to merge, here is a small method that can inject personalization data to a mail object, and return json

func getMailRequestBody(mail *mail.SGMailV3) ([]byte) {
    jsonData := gin.H{}
    marshal, _ := json.Marshal(mail)
    json.Unmarshal(marshal, &jsonData)
    personalizations := jsonData["personalizations"].([]interface{})

    for _, personalization := range personalizations {
        p := personalization.(map[string]interface {})
        p["dynamic_template_data"] = gin.H{
            "foo": "bar",
        }
    }

    body, _ := json.Marshal(jsonData)

    return body
}

@thinkingserious thinkingserious merged commit 8cb43f4 into sendgrid:master Sep 5, 2018
@thinkingserious
Copy link
Copy Markdown
Contributor

Hello @devchas,

Thanks again for the PR!

We appreciate your contribution and look forward to continued collaboration. Thanks!

Team SendGrid DX

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: twilio enhancement feature request on Twilio's roadmap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Dynamic Template Support

8 participants