How to relay Emojis through Flowroute SMS API with Perl

This post will probably only help me. I don’t know if anyone out there is using Flowroute for SMS. And if you are, you’re probably not using Perl. So this is another post that is meant for my future self and maybe one other person on the Internet.

If you’re looking for SMS integration, I highly recommend Flowroute.

I am writing a game to be played at an upcoming TEDx event. The game is played simultaneously over voice and SMS and when the game is over, I wanted to allow players to send messages to each other – proxied through the game engine so the users do not know each other’s mobile numbers.

Naturally, I wanted to support Emojis (and any Unicode) through this messaging, but I was really struggling to get them to work. The messages would look like this:

It ended up being the way Perl was encoding JSON. Using the standard JSON encode command did not work:

use JSON;
my $json = encode_json \%data;

I then found a great article comparing Mojo::JSON and Cpanel::JSON::XS. It turns out I had the same problem with Mojo::JSON

use Mojo::JSON;
my $json = Mojo::JSON::encode_json(\%data);

But then I tried Cpanel::JSON::XS and hooray!

Cpanel::JSON::XS
my $json = Cpanel::JSON::XS->new()->encode(\%data);

Anyway, if you’re struggling with UTF-8 and Unicode and Emojis when it comes to messaging APIs, sometimes the JSON encoding package you use can make all the difference in the world!

 

1 thought on “How to relay Emojis through Flowroute SMS API with Perl

Leave a Reply

Your email address will not be published. Required fields are marked *