How do I reference and create dynamic emails with Sendgrid? - sendgrid

I'm at a loss with the documentation here.
I'm trying to create a basic hello world email template, with some simple email substitutions - and I can't work out the syntax.
The documentation here suggests using a -igetreplaced- syntax, and gives the following example:
<html>
<head></head>
<body>
<p>Hello -name-,<br>
Thank you for your interest in our products. I have set up an appointment to call you at -time- EST to discuss your needs in more detail. If you would like to reschedule this call, please visit the following link: `reschedule`
Regards,
-salesContact-
-contactPhoneNumber-<br>
</p>
</body>
</html>
An accompanying SMTP API JSON header might look something like this:
{
"to": [
"example#example.com",
"example#example.com"
],
"sub": {
"-name-": [
"John",
"Jane"
],
"-customerID-": [
"1234",
"5678"
],
"-salesContact-": [
"Jared",
"Ben"
],
"-contactPhoneNumber-": [
"555.555.5555",
"777.777.7777"
],
"-time-": [
"3:00pm",
"5:15pm"
]
}
}
I've tried pasting these in to the template code editor, but it doesn't work.
Can someone point me to the right documentation for getting the syntax correct?

The syntax is Handlebars.
Use it like this:
Hello {{name}}
with data:
{
"name": "Bob"
}

Related

Having an issue with Dialogflow API WebhookResponse V2 for Actions for Google

I'm testing Actions for Google, so I created some simple Sinatra application which looks something like:
require 'sinatra'
require 'json'
post '/google_assistant_api' do
content_type :json
case intent_name
when "input_welcome"
decorated_response
when "Recipe name"
basic_card
end
end
private
def decorated_response
{
source: "test source",
speech: "speech",
display_text: "something"
}.to_json
end
def intent_name
parsed_request["queryResult"]["intent"]["displayName"]
end
def parsed_request
#parsed_request ||= JSON.parse(request.body.read)
end
def basic_card
{
"fulfillmentText": "ACTIONS_ON_GOOGLE",
"fulfillmentMessages": [
{
"platform": "PLATFORM_UNSPECIFIED",
"text": {
"text": [
"string text"
]
},
"image": {
"imageUri": "https://avatars3.githubusercontent.com/u/119195?
s=400&v=4"
},
"basicCard": {
"title": "title string",
"subtitle": "subtitle",
"formattedText": "formatted text",
"image": {
"imageUri": "https://avatars3.githubusercontent.com/u/119195"
},
"buttons": []
}
}
],
"source": "source string"
}.to_json
end
Please note that I'm using V2 of the API and testing using google assistant:
I tried many other response formats based on https://gist.github.com/manniru/f52af230669bd3ed2e69ffe4a76ab309 with no luck. I keep getting:
Sorry! there was no response from the Agent. Please try later.
Is there anyone who tried non nodejs response with luck? I would appreciate any sample response as the simple response seems to be working, however as for the basic card I'm having no luck.
Dialogflow's v2 API uses a different format for webhook requests and responses which is documented here:
Dialogflow v2 Webhook Request
Dialogflow v2 Webhook Response
It appears that your code is using the old format.

User snippets not working in VScode

Hi guys I'm using VScode and trying to get some user snippets to work.
I've tried adding them to both the javascriptreact.json file and the javascript.json file... and even the html.json file but with no success.
I know VSCode uses Emmet, and am confused as to whether user snippets work with emmet rather than intellisense, and if so am I putting this in the wrong file?
Cheers in advance for any help!
I am trying to overwrite the default div. span. img. etc. by adding the following snippets:
"Expand ReactQL Div": {
"prefix: "div.",
"body": [
"<div className={css.:1}>:2</div>;"
],
"description": "expand div"
},
"Expand ReactQL img": {
"prefix: "img.",
"body": [
"<img src={:1} alt=":2" className={css.:3} />;"
],
"description": "expand img"
},
"Expand ReactQL span": {
"prefix: "span.",
"body": [
"<span className={css.1:}>:2</span>;"
],
"description": "expand span"
}
I'd imagine you have solved this one, but for anyone else,
There a few issues with your snippets:
Missing " within your prefix definition, the : is also enclosed in quotes.
{css.:1} syntax works like so ${1:css}
An example:
"Expand ReactQL Div": {
"prefix": "div.",
"body": [
"<div className=${1:css}>${2}</div>"
],
"description": "expand div"
},
Demo of snippet in action

Unable to verify JobPosting in SDTT

Get frustrated with Schema.org’s JobPosting. I found Google Structured Data Testing Tool said:
100000 (The attribute baseSalary.itemtype has an invalid value.)
I have tried using this inside or outside of JobPosting as follows:
"#type":"MonetaryAmount",
"EmployeeRole":{
"baseSalary": "100000"
}
However, I found more than one problem.
<script type="application/ld+json">{
"#context": "http://schema.org",
"#type": "JobPosting",
"baseSalary":"100000",
"datePosted":"2017-06-18T15:14:57+00:00",
"validThrough":"2017-12-31T00:00:00+00:00",
"title":"Sales And Marketing Manager",
"description":"Responsible for Corporate and Travel Agent Room Sales for the hotel",
"educationRequirements":"S-1 Management",//educationRequirements
"employmentType":"Kontrak 1 Tahun",//employmentType
"experienceRequirements":"100 Tahun",//experienceRequirements
"industry":"Perpajakan Daerah Sumedang",//industry
"qualifications":"Single, Fresh Graduates dan suka ternak bebek",//qualifications
"responsibilities":"Tukang mbersihin kadang embek",//responsibilities
"skills":"Bisa menjahit, ngetik 40 jari",//skills
"workHours":"Jam 10 s/d 70",//workHours
"hiringOrganization":{
"#type":"Organization",
"name":"Equity Jimbaran Resort And Villa",
"sameAs":"http://equityhoteljimbaran.com",
"url":"http://equityhoteljimbaran.com"
},
"jobLocation":{
"#type":"Place",
"address":{
"#type":"PostalAddress",
"addressRegion":"Bali",
"addressCountry":"ID",
"streetAddress":"Jl.Muara 3, KM.18, Blok4, RT04/05, Tanjung Perak",//streetAddress
"addressLocality":"Jimbaran",//addressLocality
"postalCode":"56161"//postalCode
}
}
}
}
</script>
After long distance, finally, I find the solution:
<script type="application/ld+json">{
"#context": "http://schema.org",
"#type": "JobPosting",
"baseSalary":{
"#type":"MonetaryAmount",
"value":"100000",
"currency":"USD"
},
"datePosted":"2017-06-18T15:14:57+00:00",
"validThrough":"2017-12-31T00:00:00+00:00",
"title":"Sales And Marketing Manager",
"description":"Responsible for Corporate and Travel Agent Room Sales for the hotel",
"educationRequirements":"S-1 Management",//educationRequirements
"employmentType":"Kontrak 1 Tahun",//employmentType
"experienceRequirements":"100 Tahun",//experienceRequirements
"industry":"Perpajakan Daerah Sumedang",//industry
"qualifications":"Single, Fresh Graduates dan suka ternak bebek",//qualifications
"responsibilities":"Tukang mbersihin kadang embek",//responsibilities
"skills":"Bisa menjahit, ngetik 40 jari",//skills
"workHours":"Jam 10 s/d 70",//workHours
"hiringOrganization":{
"#type":"Organization",
"name":"Equity Jimbaran Resort And Villa",
"sameAs":"http://equityhoteljimbaran.com",
"url":"http://equityhoteljimbaran.com"
},
"jobLocation":{
"#type":"Place",
"address":{
"#type":"PostalAddress",
"addressRegion":"Bali",
"addressCountry":"ID",
"streetAddress":"Jl.Muara 3, KM.18, Blok4, RT04/05, Tanjung Perak",//streetAddress
"addressLocality":"Jimbaran",//addressLocality
"postalCode":"56161"//postalCode
}
}
}
}
</script>
From the structure data above,baseSalary expects type of MonetaryAmount, where the value is the amount of the salary, as follow:
"baseSalary":{
"#type":"MonetaryAmount",
"value":"100000",
},
However, when the baseSalary has been added and verified, Google, again, gave me error in currency which I placed it inside baseSalary:
"baseSalary":{
"#type":"MonetaryAmount",
"value":"100000",
"currency":"USD"
},
Done successfully.
This is an answer to #huykon225 question about microdata above, because I can't find that this question is answered in microdata context anywhere although the internet is full of corrected versions of json. Frustrated me, just took an hour or more to sort it...
Replace this in the original code:
<span itemprop="salaryCurrency">USD</span> <span itemprop="baseSalary">100000</span>
With this:
<div itemprop="baseSalary" itemscope="" itemtype="https://schema.org/MonetaryAmount">
<span itemprop="currency">USD</span>
<span itemprop="value">100000</span>
</div>

Flexible content modules in Silverstripe

We are looking at using Silverstripe CMS and want to be able to have modules which can be reordered.
We have come from a Wordpress setup and mostly use the flexible content ACF field. Modules (e.g. text, masthead or video) need to be able to be re-ordered.
We use our CMS's as an API so these modules are output as a section to the page or post:
[
{
"id": 10,
"title": "Post title",
"slug": "post_slug",
"path": "/post_slug",
"template": "campaign",
"published": "2017-05-25 06:09:36",
"image": null,
"seo": {
"title": "",
"description": "",
"image": {
},
},
"sections": [
{
"type": "masthead",
"Title": "",
"video": false,
"image": [
],
"showCta": false,
"cta": [
]
},
{
"type": "video_text",
"video_text": [
{
"type": "video",
"video_url": "https://www.youtube.com/watch?v=asdfa",
"video_length": "07:38",
"video_preview": false
},
{
"type": "text",
"title": "Video Title",
"content": "Video text content",
"call_to_action": false,
"cta": [
]
}
]
},
{
"type": "text",
"title": "Text Title",
"content": "",
"alignment": "centre",
"call_to_action": false,
"cta": {
"text": "CTA button",
"link_type": "internal_link",
"internal_link": "about",
"external_link": "",
"section_id": [
]
}
},
]
}
]
Does Silverstripe have it's own way of handling modules / do I need to ditch this flexible content modules method? How do others handle flexible content modules in Silverstripe?
Both silverstripe-blocks and silverstripe-elemental works very well in their own regard but I don't think they will achieve what you want. These modules don't really give you the power to use pre-defined templates. You can hook the templates in but the code will be massive. I not sure if there is an open source module for that yet.
From your JSON code, in order to have those Sections to render something like this below;
<section id="Sections">
<div id="video_text" class="section">
<iframe width="560" height="315" src="https://www.youtube.com/watch?v=asdfa" frameborder="0" allowfullscreen></iframe>
</section>
<div id="text" class="section">
<h2>Text Title</h2>
<a class='text-center btn btn-default' href="/about/">CTA button</a>
</section>
</sections>
You might want to do this.
Use DataObjects (DO) for you Sections, easy for re-ordering.
Create an abstract DO, BlockSection, with fields like Title(Varchar), Content(HTMLText), Sort(Int) and most importantly has_one to Page.
For the video use can name the DO VideoBlockSection and it extends BlockSection,
TextBlockSection for the other one. Don't forget the $singular_name for each DO (useful for nice class naming in the Grid)
On Page getCMSFields add the Grid to manage the Sections. You need to add GridFieldSortableRows and GridFieldAddNewMultiClass and now you can add you Section on each Page.
Add has_many from Page to BlockSection and a method that will render the Blocks and outputs the html.
Page.php
private static $has_many = array(
"Sections" => "BlockSection",
);
function SectionContent()
$aContent = ArrayList::create();
$oSections = $this->Sections();
if (count($oSections )) {
foreach ( $oSections as $oSection ) {
$aContent->push(ArrayData::create([
"Section" => $oSection,
"Content" => $oSection->renderWith([$oSection->ClassName, get_parent_class($oSection)]),
]));
}
}
return $aContent;
For the VideoBlockSection the template array list will be VideoBlockSection and BlockSection
VideoBlockSection.ss
<div id="video_text_{$ID}" class="section">
<iframe width="560" height="315" src="{$URL}" frameborder="0" allowfullscreen></iframe>
</section>
In you specific case, because you are using an API you need to use a wrapper to render the Template.
It needs to match [section][type] to a Template (renderWith) video_text to VideoBlockSection
Lastly in Page.ss
<% loop $SectionContent %>
{$Content}
<% end_loop %>
This was a proof of concept but its working for me so refactoring, speed and memory usage was not considered (but its working).
This way I had to ditch the unnecessary so called "page types" which I find not to be reusable in most cases.
This works 100% for me and I use it together with Bootstrap 3. I use it to create CTAs, parallax scroll, Google Map Section (multiple maps on one page), Thumbnails. Specify image resize method (Cropped, ByWidth, ByHeight).
DO NOT ditch that flexible content modules method.
I am working on an open source module which works with SS4 and Bootstrap 4 (with possibilities of using any other html framework)

Sending HTML content in the email body in Jasperserver's scheduled reports

I'm generating the reports in JasperServer and using the Rest api to schedule the report. The rest api is given below:
curl
-XPUT "http://hostURL/jasperserver/rest_v2/jobs"
--data '{
"trigger":{
"simpleTrigger":{
"occurrenceCount":"1",
"startType":"1",
"timezone":"Asia/Calcutta",
"misfireInstruction":"0",
"version":"0"
}
},
"outputTimeZone":"Asia/Calcutta",
"username":"jasperadmin",
"outputFormats":{
"outputFormat":[
"PDF"
]
},
"source":{
"parameters":{
"parameterValues":{
"parameter1":[
"value"
],
"parameter2":[
"value"
],
}
},
"reportUnitURI":"/reports/Report"
},
"baseOutputFilename":"MyReport",
"mailNotification":{
"messageText":"<p> Greeting,<br>Please find your statements.<p>",
"toAddresses":{
"address":[
"myemail#xyz.com"
]
},
"includingStackTraceWhenJobFails":"false",
"skipEmptyReports":"false",
"subject":"Account Statement",
"skipNotificationWhenJobFails":"false",
"resultSendType":"SEND_ATTACHMENT"
},
"repositoryDestination":{
"usingDefaultReportOutputFolderURI":"false",
"folderURI":"/Reports/GeneratedReports",
"saveToRepository":"true",
"overwriteFiles":"true",
"sequentialFilenames":"false"
},
"label":"Report_20160929591135"
}'
-H "authorization:Basic amFzcGVyYWRtaW46amFzcGVyYWRtaW4="
-H "content-type:application/job+json"
The API works perfectly. But the HTML content that I send in the messageText is not rendered and shows up as plain string. Is there any way I could send HTML content in the messageText. Do I have to make changes in some property files?
As far as I know, Jaspersoft Server is not capable of sending HTML Emails as it is using basic Java Strings.
You basically have to edit the source code and change it to your liking.
For the line breaks maybe just use \n ?