jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.67k stars 310 forks source link

Alexa Display Templates ASCII character Error #252

Closed soltrinox closed 4 years ago

soltrinox commented 5 years ago

I'm submitting a...

Expected Behavior

Alexa Display Templates https://www.jovo.tech/docs/amazon-alexa/visual-output#body-templates

Getting error with & sign , this is not problem with standard this.tell or this.ask , I had to change my speech output to AND vs. & .

Current Behavior

I get an error when have ampersand & symbol is in display text and speech output.

aswetlow commented 5 years ago

Hey @soltrinox

yeah, it works for tell, but it's a workaround in the toSSML method. It always replaces & to AND for every language, which is bad. We need a more generic way. I will keep that in mind for v2.

A quick workaround for now would be to replace it on your own. text.replace(/&/g, 'and')

IGx89 commented 5 years ago

Jovo defaults to RichText instead of PlainText when adding text to display templates, so you'll need to make sure to XML escape any text you put in them. We ran into this same issue, and ended up solving it by using the xml-escape module (that's what Jovo uses behind the scenes to allow your tell and ask calls to work).

Example:

const xmlEscape = require('xml-escape');
...
const template = this.alexaSkill().templateBuilder('BodyTemplate3')
    .setToken(token)
    .setTitle(title)
    .setTextContent(`<b><font size="5">${xmlEscape(clazz.name)}</font></b>`);

this.alexaSkill().showDisplayTemplate(template);

Official XML special character guidelines from Amazon: https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#xml-special-characters. The xml-escape module handles the first five character replacements -- the final two we'll likely never encounter.

aswetlow commented 4 years ago

Closing this due to inactivity.