2

Does the Dialog service support emoji inputs?

I was able to output emojis using both: HTML Entity (decimal)  HTML Entity (hex)  http://www.fileformat.info/info/unicode/char/1f37b/index.htm

However, I can't get the dialog service to understand emoji inputs. Emojis in dialog conversation

  • 1
    Leo is right. However, Why not add a filter layer between your end user application and the dialog API instance that does a string replace of emoji characters with a simple string like "happyface" or "beer" – James Ravenscroft Mar 11 '16 at 22:05
  • Cool, good idea, I'm not sure how to do that, but I'll look into it. Thanks! – Sebastian von Krumhausen Mar 12 '16 at 03:56
  • Check out the [pizza demo code](https://github.com/watson-developer-cloud/dialog-nodejs) on GitHub. What they essentially do is build a middleware in node.js that exposes the dialog endpoints to the user's browser without having to pass through important details like service credentials or the endpoint url. You could add a javascript function that gets called from app.js just before line 55 that takes the conversation input in req.body and does a string.replace(emoji, textreplacement) for each of the emojis you are interested in capturing. Then post the result off to the service as they do on – James Ravenscroft Mar 12 '16 at 06:22
  • @JamesRavenscroft See my answer for a proof that emojis are indeed supported. As you work for the IBM Watson team, please improve your documentation. The examples for Watson Dialog is really bad and it’s very difficult to get the Dialog scripts right. Lots of trial and error. – plindberg May 28 '16 at 09:04

1 Answers1

1

You most certainly can. Here’s an example:

<?xml version="1.0" encoding="UTF-8" ?>
<dialog xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<flow>
<folder label="Main">

Output an initial prompt:

  <output>
    <prompt>
      <item>Write something and I’ll echo it back to you.</item>
    </prompt>
  </output>

Get input:

  <getUserInput>
    <input>
      <grammar>
        <item>(ANYTHING)={anything}</item>
      </grammar>
      <action varName="anything" operator="SET_TO">{anything.source}</action>
      <output>
        <prompt>
          <item>{anything}</item>
        </prompt>
      </output>
    </input>
  </getUserInput>

</folder>
</flow>

Now, I guess you have tried to capture inputs the way IBM does it in all its examples. But that method silently drops many non-ASCII characters. It’s just not how you want to capture inputs. (See this SO answer for a list of some of the characters it drops.)

Here’s how I do it:

<entities>
  <entity name="ANYTHING">
    <value>
      <grammar>
        <item>!.*</item>
      </grammar>
    </value>
  </entity>
</entities>

The exclamation point means that we’re using a regular expression. (Everything after ! is the regex.) This method does not drop as many characters, but it will drop < and >. Possibly others. You can use this same script to find out which characters are safe.

And finally we’ll need the variable to capture into.

<variables>
  <var_folder name="Home">
    <var name="anything" type="TEXT" />
  </var_folder>
</variables>

</dialog>

See this gist for the complete example.

Community
  • 1
  • 1
plindberg
  • 877
  • 1
  • 9
  • 15