Sending email htmlBody via Data Action

Hello, I am trying to send the html body of email, which come to the Genesys via Data Action to our CRM.

In my Request Body Template, I am escaping the HTML characters using the $esc.html

"emailBody" : #if( ${input.emailBody} && ${input.emailBody} != "")"$esc.html(${input.emailBody})"#{else}null#end,

It is working without any issue, if I am testing the Data Action directly and pasting the HTML body of any email into the GUI.

But what I am aiming to do is to fill this attribute in the Architect, using the Email.Message.htmlBody like that

image

But if I do it like that, then the Data Action in the Architect always fails.

I even tried to save the variable Email.Message.htmlBody into the Participant Data and then copy the exact same text directly into the Architect like that:

And again, this is working perfectly.

Does anyone know, if the variable Email.Message.htmlBody itself has some kind of strange formating when used as an input into the Data Action or what should I do, to be able to use it correctly?

Thank you

Could you post the HTML as text so we can try to reproduce your issue?

--Jason

Hello Jason,

the HTML of the email, which I tried is following.


<div class="WordSection1">
<p>Ahoj</p>
<p> </p>
<p><b><span style="font-size:9pt;font-family:&#39;arial black&#39; , sans-serif;color:#5f5f5f">Jakub Zíta</span></b><span style="color:black"></span></p>
<p><span style="font-size:9pt;font-family:&#39;arial&#39; , sans-serif;color:#5f5f5f">Technical Consultant for Contact Centers
</span></p>
<p><span style="font-size:9pt;font-family:&#39;arial&#39; , sans-serif;color:#5f5f5f"> </span></p>
<p><span style="font-size:9pt;font-family:&#39;arial black&#39; , sans-serif;color:#c20000">ALCA</span><span style="font-size:9pt;font-family:&#39;arial black&#39; , sans-serif;color:#5f5f5f">SYS
 Czech Republic, s.r.o.</span><span style="font-size:9.5pt;color:black"> </span><span style="font-size:9.5pt;font-family:&#39;arial&#39; , sans-serif;color:#5f5f5f"><br />
</span><span style="font-size:9pt;font-family:&#39;arial&#39; , sans-serif;color:#767171">Antala Staška 511/40</span><span style="color:black"></span></p>
<p><span style="font-size:9pt;font-family:&#39;arial&#39; , sans-serif;color:#767171">140 00 Praha 4</span><span style="font-size:9.5pt;font-family:&#39;arial&#39; , sans-serif;color:#5f5f5f"><br />
<br />
</span><span style="font-size:9pt;font-family:&#39;arial&#39; , sans-serif;color:#767171">mobile:    &#43;420 736 210 875</span><span style="color:black"></span></p>
<p><span style="font-size:9.5pt;font-family:&#39;arial&#39; , sans-serif;color:#5f5f5f">e-mail:
</span><span style="font-size:11pt"><a href="mailto:jakub.zita&#64;alcasys.eu" rel="nofollow"><span style="font-size:9.5pt;font-family:&#39;arial&#39; , sans-serif;color:#0563c1">jakub.zita&#64;alcasys.eu</span></a></span><span style="font-size:9.5pt;font-family:&#39;arial&#39; , sans-serif;color:#5f5f5f">
</span><span style="font-size:11pt"></span></p>
<p> </p>
</div>

But as I mentioned, if you place it directly into the Architect as a literal, then it is working fine. The problem is just when I am using directly the Email.Message.htmlBody variable.

And also it doesn't seem to matter, what is in the email. The situation is always the same. I tried to send simple email, with just one word and also more complicated emails with styling, etc. and it is still the same - using variable is not working, placing HTML directly working fine.

Sorry for the huge delay. I tried this out and don't have any answers for what is going wrong. I am pinging a different team to see if they have any ideas. Right now I would suggest that you open a support ticket so you can gather logs from architect and see exactly what is being sent to the data action that is failing. Often that will make the problem clear.

--Jason

After some help from a coworker I think that the issue you are facing is that the html string has newlines in it, which is resulting in the request template being invalid JSON. When you paste it into the data action test mode box or hard code the value in architect those newlines appear to be treated differently than when the variable is directly used.

I came up with a couple of approaches that seem to work:

Have the requestTemplate remove any newlines (\n or \r) from the string:

"requestTemplate": "{\"emailBody\" : #if( ${input.emailBody} && ${input.emailBody} != \"\")\"$esc.html(${input.emailBody.replace(\"\n\", \"\").replace(\"\r\", \"\")})\"#{else}null#end}"

Have the requestTemplate escape the newlines so they don't cause a problem:

"requestTemplate": "{\"emailBody\" : #if( ${input.emailBody} && ${input.emailBody} != \"\")\"$esc.html(${input.emailBody.replace(\"\n\", \"\\n\").replace(\"\r\", \"\\r\")})\"#{else}null#end}"

--Jason

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.