Using the Vonage Contact Center Javascript Engine

The Vonage Contact Center Javascript Engine is a special type of web service that accepts some JavaScript, run the script and returns the results. You can then write these results to Data Sources for use later in the call plan.

To use the Vonage Contact Center Javascript Engine in web service interactions that you define using a template, the template must contain $(JavascriptEngineUrl) in the Url element.

Using the Vonage Contact Center Javascript Engine, you can manipulate existing data for your purposes.

For example, a customer currently uses an Announcer to announce a caller's postcode, which is stored in a Data Source, but wants to only announce the first three characters of the postcode. The customer can use the Vonage Contact Center Javascript Engine to run a JavaScript method that extracts the first three characters of the provided postcode.

To use the Vonage Contact Center Javascript Engine, you must create a Data Connector that uses a Web Service interface. For more information about using a Web Service interface, see Retrieving data from a Web Service. Provide the following values in Interaction Definition:

  • In the Url element, type $(JavascriptEngineUrl). $(JavascriptEngineUrl) is a special configuration value that holds the address of the Vonage Contact Center Javascript Engine.
  • Create a Content-Type header to enable the Javascript Engine to execute correctly.
    • Inside the <Request> element, create the following <Headers> element:
      <Headers><Header><Key>Content-Type</Key><Value>application/json</Value></Header></Headers>
  • In the Body element, type the JavaScript method that manipulates the values as required.
    • In the following example, the JavaScript extracts the first three characters of the value stored in the Postcode Data Source:
      <Body><![CDATA[{"script": "var str = \"$(Postcode)\"; result = str.substring(0, 3);"}]]></Body>
    • In the following example, the JavaScript adds three zeros to the front of the value stored in the Order Number Data Source:
      <Body><![CDATA[{"script": "result = \"000\" + \"$(Order Number)\";"}]]></Body>

To use the returned value in a subsequent applet, store the value in a Data Source. For information about storing returned values in a Data Source, see Retrieving data from and sending data to a Web Service.

When you finish creating the Data Connector applet, click Update.

A message appears. This message states that the JavaScript you provide in the Body element must now be approved by Vonage Contact Center.

Double quotes, tabs, or newline characters in Data Source value

The EscapeDoubleQuotes formatter reformats data source values. When using the Vonage Contact Center Javascript Engine, you can use the EscapeDoubleQuotes formatter to escape any double-quotes, tabs, or newline characters within data sources in your JavaScript methods. 

If the value of a data source contains a double quote ...

for example, a JSON object returned by an earlier call to a web service:
{ "type" : "postcode", "name" : "AB12 3CD" }

... you can add the EscapeDoubleQuotes suffix to the end of the data source name:

{ "script" : "x = '$(AddressDetail:EscapeDoubleQuotes)';" }

Adding the suffix escapes any double-quotes in the data source value. The reformatted value contains escaped double-quotes:

{ "script" : "x = { \\\"type\\\" : \\\"postcode\\\", \\\"name\\\" : \\\"AB12 3CD\\\" };" }

Support and documentation feedback

For general assistance, please contact Customer Support.

For help using this documentation, please send an email to docs_feedback@vonage.com. We're happy to hear from you. Your contribution helps everyone at Vonage! Please include the name of the page in your email.