06-11-2020 06:23 AM
Using Jabber Botkit SDK, is it possible to set the reply message stanza html dynamically?
We have a web service that takes the user message as input and returns an HTML text as the output to send as the reply message to the user. We are having some problems using the marked-up text in the stanza.
<AdminConfiguredBot> setting is enabled and our Jabber version is 12.8.2.
For example, when I set the stanza as below , we have no problems and I can see the HTML tags working.
text = “hello bot!”
reply_message.stanza = xml`<message to="${to}" type="${type}">
<html xmlns="http://jabber.org/protocol/xhtml-im">
<body xmlns="http://www.w3.org/1999/xhtml">
<p><strong>${text}</strong></p>
</body>
</html></message>`
In our case, the web service returns the html formatted version, so if I get the text variable as below, HTML tags are now not working.
text = “<p><strong>hello bot!</strong></p>”
reply_message.stanza = xml`<message to="${to}" type="${type}">
<html xmlns="http://jabber.org/protocol/xhtml-im">
<body xmlns="http://www.w3.org/1999/xhtml">
${text}
</body>
</html></message>`
So, our question is whether or not the SDK allows this type of use. Do we have to set the html tags beforehand, or can we use a variable string that includes the tags? Thanks.
Solved! Go to Solution.
06-11-2020 08:06 AM
I suspect this is an artifact of the xmpp/xml package that provides the tagged template 'xml' function, probably due to some quirks with how tagged templates work: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings
Probably the substituted variables are each check for XML characters, and those characters are then XML-escaped (which is what you don't want.)
I believe the xml template function is primarily there just to provide XML escaping - if you are careful to manage that yourself, you should be able to just skip it and deal with regular strings. I.e. simply remove 'xml' from the front of the template string and just use a bare string template.
06-11-2020 08:06 AM
I suspect this is an artifact of the xmpp/xml package that provides the tagged template 'xml' function, probably due to some quirks with how tagged templates work: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings
Probably the substituted variables are each check for XML characters, and those characters are then XML-escaped (which is what you don't want.)
I believe the xml template function is primarily there just to provide XML escaping - if you are careful to manage that yourself, you should be able to just skip it and deal with regular strings. I.e. simply remove 'xml' from the front of the template string and just use a bare string template.
06-14-2020 11:18 PM
Thank you so much David for pointing me in the right direction.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide