-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the type of the message to save a lot of money 💸 #69
Conversation
Without specifying the type, the default is unicode and messages are split at 70 chars according to the official documentation : https://developer.vonage.com/en/messaging/sms/guides/concatenation-and-encoding The default type is defined in class `VonageMessage` message line 26 as `public $type = 'text';`
The tests seem to be failing. |
My bad @taylorotwell, tests are fixed now. |
I want this fix to be released next week. What about upgrading to vonage-php-sdk-core v4.x? https://github.com/Vonage/vonage-php-sdk-core/releases/tag/4.0.0 |
🤞 Every day we lose several hundred euros because of this bug 😭 It could be really nice if it is released right now ! |
Hi all, I just released this as v3.1.1. Remember that you can always pin a previous version of a package in composer from before the breakage. That way you don't have to wait for a release. |
You rock @driesvints, thank you very much! |
@potsky @driesvints FYI: This is a little breaking change as the error previously caused |
Can we check if message has a Unicode characters before hitting the API ? |
@Brenneisen you're right. Given that the @driesvints I am going to check if we can do this right now |
That should be possible. |
I'll open a new PR with this check. If the provided @driesvints for a future upgrade of this package to support SDK v4, keep in mind that the behaviour above is a trick because of a bug before in this package. You will need to document in the |
I'm going to revert all of this as well as the original #65 PR that introduced the original issue. We'll revisit this for v4 of the SDK. |
This reverts commit 63d208f.
Released v3.1.2 with how things were. |
@potsky @ankurk91 @Brenneisen if you all could confirm things are okay again that'd be great. |
@driesvints it is perfect. Message type is kept correctly and if message is fully GSM-charset compliant, it only counts for 1 message in the billing 👍 |
Moreover, if you put a unicode char in the message and set the message type to text, Vonage will replace the unicode char by ? instead of raising an error. Thank you 🙏 |
I can also confirm that it is sending 1 SMS instead of 2 now. |
@ankurk91 @potsky I'll be issuing a new draft PR shortly to address this. The timing has been a little unfortunate, because the encoding detection was flawed, then removed, then reintroduced. Of the feedback of several users, the new PR will do the following:
Cheers, |
Hi @SecondeJK! Thank you for your message and upgrading to sdk v4 is a good thing. Just a note: I don't know if you plan to use the built in We have developed our own detector following their documentation, if it can help: /**
* @see https://developer.vonage.com/en/messaging/sms/guides/concatenation-and-encoding
*/
private const ONE_BYTE_CHARS = [
'!', '"', '#', '$', '%', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '_', '¡', '£', '¥', '§', '¿', '&', '¤',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'Ä', 'Å', 'Æ', 'Ç', 'É', 'Ñ', 'Ø', 'ø', 'Ü', 'ß', 'Ö', 'à', 'ä', 'å', 'æ', 'è', 'é', 'ì', 'ñ', 'ò', 'ö', 'ù', 'ü', 'Δ', 'Φ', 'Γ', 'Λ', 'Ω', 'Π', 'Ψ',
'Σ', 'Θ', 'Ξ', ' ', "\n",
];
private const TWO_BYTES_CHARS = ['|', '^', '€', '{', '}', '[', ']', '~', '\\'];
public static function checkMessageLength(string $message): void
{
$length = 0;
$charsNotSupported = [];
foreach (mb_str_split($message) as $char) {
if (in_array($char, self::ONE_BYTE_CHARS)) {
++$length;
} elseif (in_array($char, self::TWO_BYTES_CHARS)) {
$length += 2;
} else {
$length += 2;
$charsNotSupported[] = $char;
}
}
if ($length > 160) {
Debug::log('SMS message is too long', [
'message' => $message,
'length' => $length,
'charsNotSupported' => $charsNotSupported,
]);
} elseif (!empty($charsNotSupported)) {
Debug::log('SMS chars not supported in GSM charset', [
'message' => $message,
'chars' => $charsNotSupported,
]);
}
} |
Thanks for this @potsky |
Without specifying the type, the default is unicode and messages are split at 70 chars according to the official documentation : https://developer.vonage.com/en/messaging/sms/guides/concatenation-and-encoding
The default type is defined in class
VonageMessage
message line 26 aspublic $type = 'text';
In screen below: