Cisco Spark Messages with Emoji CharactersJune 5, 2017
Anyone that utilizes text messages on mobile devices are likely familiar with emojis. There's certainly good reason for this, since emojis help convey reactions and the feelings of a message better than just plain text. For example, it can be much easier to decipher the intent or tone of a message depending on the emojis used.
Cisco Spark can send & receive messages that contain emoji characters, and not just on mobile devices, but also on Mac and Windows machines. Go ahead and try it now on your laptop or workstation. When typing in Cisco Spark on a Mac, to send a message with emoji characters, the emoji quick-type panel shortcut can be accessed by simultaneously pressing Command + Control + Spacebar. To access emoji selections on Windows, the on-screen (touch) keyboard will first need to be enabled. To do this, right click the taskbar and select the Show touch keyboard button option. This will place a keyboard icon within the Windows taskbar notification area. Click this icon and a keyboard will appear on the screen. Next to space and Ctrl, click the smiling face to access the emoji selections.
Cisco Spark bots can also send and receive emoji characters. There's some different ways this can be done. One method is to simply use the actual emoji characters directly in the content of an API call or application code, since they’re perfectly valid characters in the Spark API. It’s important to note, the API call will need to include charset=utf-8 in the Content-type header. Here’s an example jQuery code snippet and resulting Spark message when sending actual emoji characters in a /messages API call:
Some programmers may want to automate things further by referencing the actual Unicode value for a corresponding emoji in their bot code. The code points for the available emoji characters and sequences are listed on the Unicode reference site and can also be found in several public GitHub repositories. As you see listed on the reference website, the corresponding Unicode hex value for “ ” is U+1F916 and for “ ” is U+1F984. However, in order to utilize these codes in a Spark bot application, we’ll need to find the surrogate pair for each of those hex values.
The reason for surrogate pairs is that in a hex value, u+FFFF is as big as you can get, and represents 65535 in base10 encoding. That's the biggest integer that exists; there's no valid number larger than it. In other words, imagine a computer that can't count any higher than 65535. So, once we got to more than 65535 characters, we need to start combining two characters. To make an analogy, the computer ran out of fingers to count on, so it started counting toes – as in the number 11 is "10 fingers and one toe". A very helpful primer on the subject of character sets and why encoding is needed can be found here.
Taking those surrogate pair values inside a REST call request to the Spark /messages API, the corresponding emojis will display inside the Spark message, just like the first example:
Remember, emojis are not only fun, but can really help make your Spark bot messages have a more human touch. Feel empowered to use them abundantly! Or, if you’re a bot, “abundantly \uD83E\uDD21\uD83D\uDC3F\uD83C\uDF55”! If you have any questions, feel free to reach out to us at firstname.lastname@example.org or join the DevSupport Spark space. Follow us on Twitter to stay updated.