Khoa Nguyen
Khoa Nguyen

Reputation: 91

How to check and encode input emojis from Facebook messenger?

I'm building a Facebook messenger bot in Python. And everything works fine. But if I send emojis as text from Facebook chat to API, then it goes wrong. This is an example when I send emojis from Facebook.

{'message': {'mid': 'mid.1475846223244:e7eea53884', 'seq': 10863, 'text': '👍🏽'},

So the received_message = message['message']['text']. What I want is whenever I send a (emoji) non text message from Facebook, I can scan and encode it before I send it to my API. I have read documents before asking this question but most of them are given emojis from user and not all a scanner and encode any emojis (if I miss something, please correct me because i'm a newbie). Tell me if I need to update my question.

Upvotes: 0

Views: 4182

Answers (2)

Simone Rondelli
Simone Rondelli

Reputation: 408

You should use the escaped version of the corresponding code point. This is a technique that allow you to express the whole Unicode range using only ASCII characters.

EG. The Emoji 💩 can be represented in Java as "\uD83D\uDCA9" or in Python as u"\U0001F4A9". http://www.fileformat.info/info/unicode/char/1f4a9/index.htm

NB: some emojis are composed by multiple code points such as flags or families. Please find here the complete list of Unicode Emojis http://unicode.org/emoji/charts/full-emoji-list.html

Upvotes: 0

Laurent LAPORTE
Laurent LAPORTE

Reputation: 22992

You may use a mapping between unicode code-points and ASCII representation. See this kind of table here: http://lolhug.com/facebook-emoticons/

The official Emoticons table is here: http://unicode-table.com/en/blocks/emoticons/

The library Emoji can help you to convert your Emojis.

Upvotes: 1

Related Questions