Actions on Google SDK V2 Preview: SSML Utilities
One of the new additions to V2 is a set of discrete utilities that do specific tasks. These are so set apart, that the Actions team has requested feedback on whether they should be in separate NPM packages altogether. One such utility is for working with SSML. It’s a useful addition, as its one of those utilities that everyone needs to write at some point. This utility has two capabilities: create SSML tags, and sanitizing input for the SSML.
SSML Sanitzation Utility
The sanitization takes place through tagged template literals. Template literals are strings with data interpolated inside, whereas tagged template literals take a function and manipulate the strings and data, generally returning an assembled string.
The Actions SDK V2 SSML utility takes a template string and returns SSML that is properly escaped, and with excess whitespace removed. The escaping makes sure that an errant
> doesn’t cause issues with Assistant parsing the SSML (it is XML, afterall). The whitespace removal allows for easier-to-read SSML in the fulfillment code. Here’s an example directly from the Actions SDK itself.
Could you do this yourself? Sure. Do you want to write it each time? No, no you don’t.
There’s one more utility:
ssml.create. This function takes an object and creates an SSML string:
The primary use of this function is for JSX support. JSX uses
ssml.create as the JSX factory, which transforms JSX code to a string. With this syntax, you can more easily create long SSML, including something like this:
Interested in more of this tour of what new the Actions SDK V2 has that will soon be available in a stable release? Follow along, and get notifications of new posts by following me on Twitter.