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:
jQuery("#mytextarea").on("change keyup", function() { var text = jQuery("#mytextarea").val(); text = text.replace(/:(\w+):$/gi, function(all, code) { // Emoji Match return LIVECHATSDK.LIVECHAT.emojiShortNames[code] || code; } ); jQuery("#mytextarea").val( text ); } );