denis-taran / smshelpers

Helper methods to work with SMS / text messages
Other
8 stars 7 forks source link

Split message? #2

Open alexkozler opened 6 years ago

alexkozler commented 6 years ago

First of all, thank you for the library! Second, is there any way you would be able to make this library actually output a list of string parts and not just count the parts?

denis-taran commented 6 years ago

Hi Alex, I will update the NuGet package this weekend and add an additional method to get list of message parts.

alexkozler commented 6 years ago

@kraaden Awesome! How hard would it be to incorporate some kind of word-wrap option into that? One of my biggest challenges sending SMS is not only making sure I send properly sized GSM-7/UCS-2 "parts" but also trying to figure out how to make sure words and URLs aren't chopped in half between parts.

I was thinking I could try and check if the last character of part1 was whitespace, and if not, push it to part2 instead, but then I risk part2 being too big... rinse and repeat. If it was an option when initially splitting, it would be so much easier.

There are only 2 or 3 other .NET libraries here on GitHub that do what yours here does, and as far as I'm aware none of them are able to do any kind of word-wrap, so it'd be a first.

denis-taran commented 6 years ago

Usually you just send long messages as a concatenated SMS and then all parts will be automatically combined into a single message on the destination headset, so you don't need to split your messages using word-wrap or something else. All major providers like Twilio supports this:

https://support.twilio.com/hc/en-us/articles/223181508-Does-Twilio-support-concatenated-SMS-messages-or-messages-over-160-characters-

alexkozler commented 6 years ago

Its true some services like Twilio try to concatenate, but some of the providers I use don't guarantee it at all, and if they do its only for ~2 messages. Plus you have to rely on the receiving carrier and phone to piece them back together.

Verizon, for example, only properly concatenates texts within their own network. That's why libraries like yours that help determine how messages are split are so helpful.

alexkozler commented 6 years ago

@kraaden I saw you doing some commits, do you have any plan to push your changes up to your NuGet package? https://www.nuget.org/packages/sms.helpers/1.0.0

denis-taran commented 6 years ago

Yes, it's almost done and once finished I will push it to the Nuget package. There is still at least one bug that I need to fix.

denis-taran commented 6 years ago

You can test word wrap splitting now, just install new version of the package:

Install-Package sms.helpers -Version 2.0.1-beta

and call

new SmsHelpers().SplitMessageWithWordWrap(myTextMessage);
alexkozler commented 6 years ago

Thank you. I'm extremely impressed you went through all that effort for my one request. I'll try it out as soon as I can in the morning :)

alexkozler commented 6 years ago

@kraaden Something interesting I'm running into is that I'm splitting up a lonnnngg string to send as multiple seperate messages. So if I split a 300 character message up, but only the first portion contains "GsmUnicode", the other 2 message parts don't need to be limited to GsmUnicode's character limit.

Take this message for example: Hello 😋😭 🛀🚧 😋😭 🛀🚧 😋😭 🛀🚧 😋😭 🛀🚧 😋😭 🛀🚧 😋😭 This is a long message. This is a long message. This is a long message. This is a long message. This is a long message.

Note how the first "part" when splitting contains a lot of emoji that must be encoded and sent within the limits of unicode/UCS2. The 2nd and 3rd "part" do not contain unicode/UCS2 but they are still limited to smaller limit. In practice on an actual phone, the first part would be sent as 1 message, and the 2nd and 3rd parts could have been combined sent as 1 single message with normal GSM-7 encoding.

For reference, what I'm doing, and what I assume others might use this library for, is to split a message into parts and then do a For Each on the parts and send each individual part through an API like Twilio, Zipwhip, Bandwidth, Messente, etc. Because of this, we wouldn't really need to worry about the multi-part message limit either (like dropping from 160 characters to 157). We could just accept the limit for a single message as your library is letting us send message parts individually.

denis-taran commented 6 years ago

I added another parameter to the method SplitMessageWithWordWrap, so you can prevent length reduction for text messages if you send them as non-concatenated. Just install the newest version

Install-Package sms.helpers -Version 2.0.2-beta

and call

var result = new SmsHelpers().SplitMessageWithWordWrap(message, false);

Unfortunately, I don't have time to add more features to the library like text splitting with mixed SMS encodings for non-concatenated messages, because I'm quite busy right now.

Zeek2 commented 5 years ago

I have a fix for emoji issue (and an explanation of the bug), see my posts today in https://github.com/janpieterz/Sms.Splitter/issues/2 ;)