CharlesO

CharlesO

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

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.

https://help.goacoustic.com/hc/en-us/articles/360043843154--How-character-encoding-affects-SMS-message-length#a6

Marked As Solved

cevado

cevado

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

Also Liked

LostKobrakai

LostKobrakai

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()
# "😀"
adamu

adamu

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.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement