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

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement