cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1484
Views
0
Helpful
2
Replies

Cisco Jabber Bot - HTML stanza problem

IsilAlkocoglu
Level 1
Level 1

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>`

jabberok.png

 

 

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>`  

 

jabbernok.png

 

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.

1 Accepted Solution

Accepted Solutions

dstaudt
Cisco Employee
Cisco Employee

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.

 

View solution in original post

2 Replies 2

dstaudt
Cisco Employee
Cisco Employee

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.

 

Thank you so much David for pointing me in the right direction.