Message length and characters
For now, every message is one SMS of up to 160 characters, written in the SMS alphabet, GSM-7. Longer messages and emoji aren't supported yet: the API refuses them with a clear error instead of splitting or garbling your text.
Try it
The counter counts exactly as the API does.
The rules
- 160 characters at most. Most characters count as 1.
- A few count as 2. These nine characters take two places each:
^{}\[~]|€. Ten square brackets use 20 of the 160 places. - A promotion's opt-out line counts. A
promotionalmessage to Kenya ends withSTOP*456*9*5#on its own line, added by SemaLink unless your text already has it. That's 14 places with the line break, so the promotion's own text can be up to 146. - Only GSM-7 characters. Emoji, most accented letters and other alphabets can't be sent yet.
A text that breaks rule 1 gets message_too_long, with characters and max_characters. A text that breaks rule 4 gets unsupported_characters, which lists each character with a replacement you can use.
Swapped for you
Before counting, SemaLink tidies the text the same way the app does. These are never errors:
| You send | It becomes |
|---|---|
Curly quotes ‘ ’ “ ” | Straight quotes ' " |
Long dashes – — and the minus sign | - |
The ellipsis … | ... (3 characters) |
Bullets • and middle dots | - |
| Tabs, non-breaking and other unusual spaces | A plain space |
| Full-width letters and digits | The normal ones |
| Invisible characters (zero-width spaces and the like) | Removed |
| Windows line endings | One line break |
| Spaces and line breaks at the start or end | Removed |
So text pasted from Word, Google Docs or a phone usually just works. The length that counts is the length after these swaps, and the message's text shows what was sent.
What's in GSM-7
| Kind | Characters |
|---|---|
| Letters and digits | A to Z, a to z, 0 to 9 |
| Punctuation | . , : ; ! ? ' " ( ) - _ / * + = < > # % & @ and space |
| Line breaks | A new line counts as 1 |
| Currency | $ £ ¥ ¤, and € (counts 2) |
| Accented letters | à ä å Ä Å é è É ì ñ Ñ ò ö Ö Ø ø ù ü Ü Ç Æ æ ß |
| Greek capitals | Δ Φ Γ Λ Ω Π Ψ Σ Θ Ξ |
| Others | ¡ ¿ § |
| Count 2 | ^ { } \ [ ~ ] | € |
KES, M-Pesa, Swahili and English text all fit: Asante! Malipo yako ya KES 1,500 yamepokelewa. is plain GSM-7.
What can't be sent yet
| Character | Replacement the API suggests |
|---|---|
| Emoji | Remove it ("") |
Accented letters outside GSM-7, such as á ê í ô ú ā | The plain letter |
ĩ ũ ŋ (some Kenyan names and languages) | i u ng' |
Symbols such as © ® ™ ½ | (c) (R) TM 1/2 |
Letters with no plain version, such as ł œ | l oe |
| Other alphabets: Greek lower case, Arabic, Amharic and others | Remove it, or reword |
Check a text with the API
POST /v1/messages/estimate counts a text exactly as sending would, and sends nothing. message.fits says whether it can go as it is; when it can't, message.problems says why and nothing is priced (every cost is null).
curl https://api.semalink.africa/v1/messages/estimate \
-H "Authorization: Bearer $SEMALINK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "0712345678",
"text": "Café open ☕"
}'2
3
4
5
6
7
const response = await fetch('https://api.semalink.africa/v1/messages/estimate', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SEMALINK_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ to: '0712345678', text: 'Café open ☕' }),
});
const { message } = await response.json();
console.log(message.fits, message.problems, message.unsupported_characters);2
3
4
5
6
7
8
9
10
11
import os
import requests
response = requests.post(
"https://api.semalink.africa/v1/messages/estimate",
headers={"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}"},
json={"to": "0712345678", "text": "Café open ☕"},
timeout=30,
)
message = response.json()["message"]
print(message["fits"], message["problems"], message["unsupported_characters"])2
3
4
5
6
7
8
9
10
11
12
13
<?php
$ch = curl_init('https://api.semalink.africa/v1/messages/estimate');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SEMALINK_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(['to' => '0712345678', 'text' => 'Café open ☕']),
]);
$message = json_decode(curl_exec($ch), true)['message'];
var_dump($message['fits']);
print_r($message['unsupported_characters']);2
3
4
5
6
7
8
9
10
11
12
13
14
{
"object": "estimate",
"livemode": true,
"type": "service",
"country": "KE",
"message": {
"encoding": "gsm7",
"characters": 10,
"characters_left": 150,
"parts": 1,
"max_parts": 1,
"fits": false,
"problems": [
{ "code": "unsupported_characters", "message": "It has characters outside the SMS alphabet: see unsupported_characters." }
],
"unsupported_characters": [
{ "character": "á", "code_point": "U+00E1", "name": "accented letter", "replacement": "a" },
{ "character": "☕", "code_point": "U+2615", "name": "emoji", "replacement": "" }
],
"footer": null
},
"cost_per_message": null,
"recipients": [
{ "input": "0712345678", "to": "+254712345678", "valid": true, "country": "KE", "network": "safaricom", "cost": null, "rejection": null }
],
"totals": { "recipients": 1, "valid": 1, "rejected": 0, "sms": 1, "cost": null }
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
characters counts each unsupported character as its replacement, so it's the length the fixed text will have. With "type": "promotional", footer shows the opt-out line and characters includes it. to is optional: leave it out to check only the text.
Fix what the API flags
Both the estimate and the 422 unsupported_characters error list each character with a replacement: "" means remove it, and null means there's no safe one, so a person should reword. Apply the replacements, then send:
# Use the replacements in your own code (Node.js, Python or PHP tabs), or read
# them with jq:
# ... | jq -r '.message.unsupported_characters[] | "\(.character) -> \(.replacement)"'2
3
export function applyReplacements(text, unsupported) {
let fixed = text;
for (const { character, replacement } of unsupported) {
if (replacement !== null) fixed = fixed.split(character).join(replacement);
}
return fixed.trim();
}
// applyReplacements('Café open ☕', estimate.message.unsupported_characters) === 'Cafe open'2
3
4
5
6
7
8
9
def apply_replacements(text, unsupported):
for c in unsupported:
if c["replacement"] is not None:
text = text.replace(c["character"], c["replacement"])
return text.strip()
# apply_replacements("Café open ☕", estimate["message"]["unsupported_characters"]) == "Cafe open"2
3
4
5
6
7
<?php
function applyReplacements(string $text, array $unsupported): string
{
foreach ($unsupported as $c) {
if ($c['replacement'] !== null) {
$text = str_replace($c['character'], $c['replacement'], $text);
}
}
return trim($text);
}
// applyReplacements('Café open ☕', $estimate['message']['unsupported_characters']) === 'Cafe open'2
3
4
5
6
7
8
9
10
11
12
A replacement can change the meaning (a name spelled without its accent), so for text people will read closely, show the fix to a person first.
Coming later
Longer messages (several SMS joined into one on the phone) and special characters (emoji and other alphabets, in the ucs2 encoding) aren't available yet. If that changes, the changelog will say so. Until then the limits above apply in the sandbox and live alike.