Sms_part_counter - Counts the character usage of a SMS using GSM7Bit/UCS-2 encoding charset

Released my first Elixir Package a few days ago. I wrote it last year while creating an SMS aggregation platform with Elixir. Since we had to charge our clients based on the number of SMSes they sent, we needed to count the SMS. Now it’s a bit tricky because you might have already noticed that for longer SMSes, you don’t get charged for one SMS but for multiple. The reason is that while sending the long SMS is divided into parts and you’re billed for each part you send. The division is done because the network can work with 1120 bits of data at a time (early implementation limitations, GSM is old).

Now you might think, we can roughly fit ~140 chars in 1120 bits, just count the chars and we’ll have the part count. Well, that is not entirely true because of encoding. We can fit 153 chars of ISO 8859-1 or ISO 8859-15 encoding but only 70 chars for UTF-8. Also, the total maximum length of an SMS changes from 459 to 201. Checking for the max length was out of scope for this package. So the detection of encoding was done. This might sound complicated but it was a fairly simple thing.

I’d like to know the thoughts of the experienced devs on this forum. I know it’s a very niche use case and lib, but the code is very simple and short :slight_smile: Thanks!

Links:

4 Likes