HOW to decoding emoji received via SMS?

I’ve setup a GSM mode to receive SMS, and in some cases, I get text that looks like some binary encoding.

For example,

"AT+CMGL=\"ALL\"\r\r\n+CMGL: 0,\"REC UNREAD\",\"+2348091000000\",,\"22/07/20,07:24:52+04\"\r\nD83DDE00\r\n\r\nOK\r\n"

The text in question is: D83DDE00

How can I correctly decode this?

I’ve tried different variations of the following with no luck

  def decode(data \\ "D83DDE00") do
    bin = Base.decode16!(data)
    :unicode.characters_to_binary(bin, {:utf16, :big}, :utf8)
  end

This is what I actually sent as a test: a smilling face Emoji
emoji

I’ve also tried to follow this without much luck - Add emojis and symbols to the SMS message body
In my case I need to do the reverse.

1 Like

That seems to work just fine on my end:

defmodule A do
  def decode(data \\ "D83DDE00") do
    bin = Base.decode16!(data)
    :unicode.characters_to_binary(bin, {:utf16, :big}, :utf8)
  end
end

A.decode()
# "😀"
1 Like

That’s strange seems I must have missed something…

I’ve not tried it, but since the input seems to be in utf16, you should probably decode the whole string, not just the emoji, to avoid any problems with other characters outside the ascii range too.

1 Like

i’d check using a library to handle gsm7 instead of doing it manually, i’ve never tested it but this should help

2 Likes

Definitely, I’m doing that.

The challenge I have now is determining if the received string is plain text or Hex encoded special characters like my example.