SOLVED

Send SMS with an emoji using Twilio webhook, comes through as plain text only?

Go to solution
KevinTruong
Level 2

Send SMS with an emoji using Twilio webhook, comes through as plain text only?

Hi all

Does anyone use Twilio for sending SMS messages from Marketo? I have an issue that's stumping me.

We want to send SMS messages that have emojis in them eg 🌼 https://www.compart.com/en/unicode/U+1F33C

We send these messages from Marketo -> Twilio via a webhook. In this webhook are Marketo tokens which is where we configure the content of the message.

This webhook passes the payload to Twilio in plain text, which strips out the emojis. If I try to add them in unicode or HTML formats ( U+1F33C or 🌼), Twilio still treats them as plain text and fails to send them as emojis. So eg an SMS saying "Here is a flower 🌼" turns into "Here is a flower U+1F33C". 

I can't tell if this is an issue with how Marketo sends the information or how Twilio is receiving it. I've lodged tickets with both platforms but hoping someone has come across this before?

3 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

The format “U+1F33C” is not an encoding. It’s the way we discuss Unicode codepoints specifically independent of any encoding.

 

HTML encoding doesn’t make sense here because you aren’t sending HTML.

 

Twilio’s Message resource expects a URL-encoded (i.e. percent-encoded) payload.

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

I mean you can easily put up a test program where the token can be anything you want. Much easier to get help if you don’t redact the important part.

 

Twilio doesn’t need to tell you anything because they expect URL-encoded. They’re fine.

 

Marketo is removing the text because the platform doesn’t support emoji literals (or any unencoded surrogate pairs, actually — I’ve blogged about this recently) in string fields.

 

So you need to pre-encode the value and then set Request Token Encoding to None.

 

SanfordWhiteman_1-1702453511876.png

 

SanfordWhiteman_0-1702453240118.png

 

 

View solution in original post

KevinTruong
Level 2

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

@SanfordWhiteman I think it has finally clicked for me. Posting up my final solution in case it helps anyone else reading this:

 

I found this site https://www.url-encode-decode.com/ that allows me to URL-encode a full SMS message with text and multiple emojis in one go:

 

KevinTruong_0-1702879480787.png

 

This pre-URL-encoded string can be pasted into a single token in Marketo making it compatible with my webhook format:

 

From=[phonenumber]&MessagingServiceSid=[account]={{lead.Mobile Phone Number:default=edit me}}&Body= Hi {{lead.First Name}}, {{my.SMS Message Body1}}

 

As long as the webhook is then set to Request Token Encoding = None as you say so it doesn't try to encode again, Twilio accepts it and sends the emojis properly.

 

Thanks so much for your help, I finally got there.

View solution in original post

12 REPLIES 12
SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

The format “U+1F33C” is not an encoding. It’s the way we discuss Unicode codepoints specifically independent of any encoding.

 

HTML encoding doesn’t make sense here because you aren’t sending HTML.

 

Twilio’s Message resource expects a URL-encoded (i.e. percent-encoded) payload.

KevinTruong
Level 2

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

Thanks @SanfordWhiteman. I'm not familiar with percent encoding, what do I need to do to send an emoji in a Marketo token to Twilio using their webhook?

SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

If you set the webhook to use Form/Url request encoding, Marketo automatically URL-encodes any tokens.

 

Please show the config of your webhook and the tokens on the Tokens tab.

KevinTruong
Level 2

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

Request encoding is already set to Form/URL:

Capture.PNG

 

We then enter the content of the SMS into the token called "SMS Message Body 1" which is just a normal text token:

Capture2.PNG

 

We then send the SMS using the Call Webhook flow step. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

You obfuscated the text of the token, which is part of what we need to see.

KevinTruong
Level 2

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

The exact text of the token we're using isn't suitable for public but imagine it is something like this:

 

Hello, here is a flower 🌼

 

It is a normal text token so the text characters work fine, however Marketo will delete the emoji from the token when I try to paste it in as is. Marketo support say I need to escape the emoji characters in some way that Twilio will accept, but Twilio support can't give details on what that is supposed to be.

SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

I mean you can easily put up a test program where the token can be anything you want. Much easier to get help if you don’t redact the important part.

 

Twilio doesn’t need to tell you anything because they expect URL-encoded. They’re fine.

 

Marketo is removing the text because the platform doesn’t support emoji literals (or any unencoded surrogate pairs, actually — I’ve blogged about this recently) in string fields.

 

So you need to pre-encode the value and then set Request Token Encoding to None.

 

SanfordWhiteman_1-1702453511876.png

 

SanfordWhiteman_0-1702453240118.png

 

 

KevinTruong
Level 2

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

How does this work in the context of an emoji in a sentence?

 

So say the end result is we want is to send an SMS saying "Hello, here is a flower 🌼"

 

Our webhook is currently configured to deliver this payload:

 

From=[phonenumber]&MessagingServiceSid=[account]={{lead.Mobile Phone Number:default=edit me}}&Body= Hi {{lead.First Name}}, {{my.SMS Message Body1}}

 

If I'm understanding you correctly, I have to create a separate token for the emoji only, so the webhook would need to look like this?

 

From=[phonenumber]&MessagingServiceSid=[account]={{lead.Mobile Phone Number:default=edit me}}&Body= Hi {{lead.First Name}}, {{my.SMS Message Body1}} {{flower emoji}}

 

And then if we wanted to have multiple emojis throughout the text eg "Hello, here is a flower 🌼 and a heart 💛 and a present 🎁" the webhook would have to look like:

 

From=[phonenumber]&MessagingServiceSid=[account]={{lead.Mobile Phone Number:default=edit me}}&Body= Hi {{lead.First Name}}, {{my.SMS Message Body1}} {{flower emoji}} {{my.SMS Message Body2}} {{heart emoji}} {{my.SMS Message Body3}} {{gift emoji}}

 

Is that correct? What would the request encoding be if the text portions require Form/URL and the emojis need none?

SanfordWhiteman
Level 10 - Community Moderator

Re: Send SMS with an emoji using Twilio webhook, comes through as plain text only?

You need to have the whole payload pre-URL-encoded. It doesn’t matter if you use one or many tokens, they all need to be URL-encoded.

 

Unfortunately, this means your {{lead.First Name}} token will break if there are any reserved characters that require URL-encoding — or more properly, IRI-encoded, as I’m pretty sure Twilio doesn’t mind a part-encoded string. For example, if the First Name contains a literal plus sign, equals sign, or ampersand.