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( 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 ); } );