Data Action String Contact

Hi,

I would like to contact Strings in data action and response as one field output. Is there a way to do it ?

{
"translationMap": {
"text": "$.transcripts[1].phrases[6].text",
"text1": "$.transcripts[1].phrases[7].text"
},
"translationMapDefaults": {
"text": "",
"text1": ""
},
"successTemplate": "{\n"text": ${text}}"
}

In the above script I would like to send "text" field response as "text"+"text1".

Hello,

There is maybe an easier way to do this - but here is one way using Velocity macros for data actions in successTemplate.

The macro leverages String concat method.
The text and text1 must first be parsed - to replace/remove quotes (success template receives text and text1 as \"something\").

{
  "translationMap": {
    "text": "$.transcripts[1].phrases[6].text",
    "text1": "$.transcripts[1].phrases[7].text"
  },
  "translationMapDefaults": {
    "text": "\"\"",
    "text1": "\"\""
  },
  "successTemplate": "#set($a = $text.replace($esc.quote, \"\")) #set($b = $text1.replace($esc.quote, \"\")) #set($resultString = $a.concat(\" \").concat($b)) {\n\"fromUser\": \"${resultString}\"}"
}

Regards,

1 Like

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