Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

In some custom integrations you may want to use some keyboard shortcuts to allow quick emoji insertion.

CTLive Agent SDK offers an object hash that contains all the Unicode 11 Emoji shortnames and symbols.

LIVECHATSDK.LIVECHAT.emojiShortNames

Using a regular expression pattern we can define a special sequence of characters (like : shortname:) to search and replace with the equivalent emoji stored in the LIVECHATSDK.LIVECHAT.emojiShortNames hash.

The following code search for any shortname that matches the last typed word with preceding and following “:” character. Example :grinning_face: (big grin)

jQuery("#mytextarea").on("change keyup", 
  function() {
    var text = jQuery("#mytextarea").val();
    text = text.replace(
      new RegExp("(\\:\\w+\\:)$", "gi"),
      function(match) {
        // Emoji Match
        if (typeof LIVECHATSDK.LIVECHAT.emojiShortNames[ match.replace(/\:/g, "") ] !== "undefined") {
          return LIVECHATSDK.LIVECHAT.emojiShortNames[ match.replace(/\:/g, "") ];
        } else {
          return match;
        }
      }
    );
    jQuery("#mytextarea").val( text );
  }
);

  • No labels