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.
Marked As Solved
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
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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










