Two of the most common questions I get are "Can I send out emojis in my SMS Messages using the Ytel API?" and "How do I do it?"

Below I will show you a couple of ways you can send out emojis using the Ytel API and also show you how to display them when sent to you from an outside mobile number.

The emoji mystery

It is often difficult to understand how a smiley face picture can get from one phone to another.  It is even more difficult to know how to send this smiley face to a phone number and receive one back programmatically in your code.

Let's take a look at the ❤️ emoji and break it down. Suppose you want to send the message:  "I ❤️ Emojis!"

To make things as simple as possible, I'm going to show all my REST API examples using cURL.  If you would like to see this translated to a language that interested you, you can visit our API Reference at https://docs.ytel.com/reference

Getting Started

There are a few things you need to get started:

    A Ytel API account.  Sign up here if you don't already have one.

    A phone number.  Once you create an account, select Numbers > Buy a Number and purchase one.

    Your AccountSID and Token.  These will be used to authenticate to the API and can be found in the upper left quadrant of the main dashboard after logging into https://app.ytel.com

    An emoji is an image representation of decoded UTF-8 characters.

When the heart emoji is encoded for use in a typical code structure it looks like:

  %E2%9D%A4%EF%B8%8F  

The above example would mean that if I were to send out an SMS using the Ytel API that said "I ❤️ Emojis!" I would send a cURL request that looks like:

curl --request POST \
 --url https://api.ytel.com/api/v3/sms/sendsms.json \
--header 'accept: application/json' \
--header 'authorization: Basic <AccountSID:Token>' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'From=%2B18647541234&To=%2B1949352233&Body=I%20%E2%9D%A4%EF%B8%8F%20Emojis!'

The %20 before and after the heart emoji represents a space.

A complete list of emojis and their UTF-8 codes can be found here.  You can look towards the bottom of this page and see the UTF-8 Hex Bytes corresponds to E2 9D A4, EF B8 8F, which is line with our cURL command above.

Unicode Message Length

One area of confusion is the change in message length for a SMS containing Unicode vs a message without Unicode.  We often say that a message, in general, can accept 160 characters.  This is generally true except in some circumstances.  In the GSM 7-bit default alphabet, |  , ^  , {  , }  ,  , [  , ~  , ]   and \   require an escape character and therefore are actually 2 character lengths.  These character variations mean that in some circumstances, the character length can be shorter.

All the above is understandable for ASCII, but what about Unicode and specifically emojis?  As mentioned above, the UTF-8 Hex Bytes representation for ❤️ is  %E2%9D%A4%EF%B8%8F  .  This means that one ❤️ emoji is equivalent to 18 GSM-7 characters. Since Unicode takes up more SMS space than GSM’s 7-bit binary code, it is limited to 70 characters.  We will chop up and segment Unicode messages that exceed this length.

If you don't want to look up the UTF-8 Hex Bytes for a specific emoji for whatever reason, our API will also accept the encoded UTF-8 image.  You can place the emoji right into the string, and we will do the encoding for you.

See the example below:

curl --request POST \
--url https://api.ytel.com/api/v3/sms/sendsms.json \
--header 'accept: application/json' \
--header 'authorization: Basic <AccountSID:Token>' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'From=%2B18647541234&To=%2B1949352233&Body=I%20❤️%20Emojis!'

In order to build something that has cross language compatibility, it is recommended to use the UTF-8 Hex Bytes method  %E2%9D%A4%EF%B8%8F   vs just copying and pasting and emoji.

Receiving Emojis

Receiving an emoji is even simpler. The originating device handles the encoding needed for transmission over SMS.  Point your inbound URL to an endpoint you build, save it to a database, and re-display it when needed.  If displaying it in a web browser, it will decode it, so the visual representation of the emoji is displayed.

More information on what an emoji is and how you can use Unicode are in the links below:

Unicode
Emojis

Did this answer your question?