Sending an SMS with Unicode
The Vonage SMS API supports Unicode characters too, which you will need to use when communicating with customers in Chinese, Japanese and Korean.
To send an SMS that contains Unicode characters, replace the following variables in the example below:
| Key | Description |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
VONAGE_BRAND_NAME | The alphanumeric string that represents the name or number of the organization sending the message. |
TO_NUMBER | The phone number you are sending the message to. |
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named send-unicode-sms.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to send-unicode-sms.js:
vonage.sms.send({
to: SMS_TO_NUMBER,
from: SMS_SENDER_ID,
text: 'こんにちは世界',
type: 'unicode',
})
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a file named SendUnicodeMessage and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.sms with the package containing SendUnicodeMessage:
Prerequisites
Add the following to build.gradle:
Create a file named SendUnicodeMessage and add the following code to the main method:
VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();Write the code
Add the following to the main method of the SendUnicodeMessage file:
TextMessage message = new TextMessage(SMS_SENDER_ID, SMS_TO_NUMBER, "Blue Öyster Cult \uD83E\uDD18", true);
SmsSubmissionResponse responses = client.getSmsClient().submitMessage(message);
for (SmsSubmissionResponseMessage responseMessage : responses.getMessages()) {
System.out.println(message);
}Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.sms with the package containing SendUnicodeMessage:
Prerequisites
Create a file named SendSmsWithUnicode.cs and add the following code:
Add the following to SendSmsWithUnicode.cs:
Prerequisites
Create a file named send-unicode-sms.php and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);Write the code
Add the following to send-unicode-sms.php:
$response = $client->sms()->send(
new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'こんにちは世界', 'unicode')
);Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named send-unicode-sms.rb and add the following code:
Run your code
Save this file to your machine and run it:
Try it out
When you run the example above, the text message will be sent to the mobile number specified with the Unicode characters intact.
Note that Unicode messages can only contain 70 characters, rather than the usual 160. There's more information about this on the help page