DEV Community

Sergey Shinder
Sergey Shinder

Posted on

One curly apostrophe made every delivery text three messages long

We send a text message to every customer on the morning of their delivery, about forty thousand a day. Our SMS provider bills per segment, and in October our bill was a little under three times what it had been in September. Volume had gone up by six percent.

The provider's delivery reports had the answer in one column. Every delivery text that month had been sent in three segments. In September every one had been sent in one.

An SMS segment holds 160 characters if every character in the message is in the GSM 7 bit alphabet. If even one character is not, the whole message has to be encoded as UCS-2, and a segment then holds 70 characters. A longer message is split into parts that carry a small header, which leaves 153 characters a part in GSM 7 bit and 67 in UCS-2. Our delivery text was 141 characters, which fits in one GSM segment and needs three in UCS-2.

At the end of September the content team moved our message templates into the CMS they use for emails, so that they could edit them without a release. The CMS editor turns straight quotes into typographic ones. We'll became We’ll, and the right single quotation mark is not in the GSM alphabet. Our integration passed the text to the provider as it was, the provider chose the encoding the text required, and every message was delivered and read exactly as written. The only place the change showed was the invoice.

Templates are now checked when they are saved. The check counts characters against the GSM alphabet, counts the characters from its extension table, such as the euro sign and square brackets, as two, and shows the editor how many segments the message will take. A template that grows beyond one segment needs a second person to approve it. Before sending, our integration replaces typographic quotes and dashes with their plain versions. It does not touch customers' names, so a text to Łukasz is still sent in UCS-2, because spelling his name correctly is worth two more segments. We now chart segments per message from the provider's reports, and alert when the daily average moves.

One character in a template changed the encoding of every message it was used in, and the message read the same on every phone.

– Sergey Shinder

Top comments (0)