I need to send SMS using Sinch API with Arabic text. My SMS message contains- English, Arabic and Numerical number.
What I tried
- I have read documentation for Sinch but they didn't provide any detailed documentation regarding how to use UTF-16BE and header encoding while sending this message.
- I also contacted their support team but they didn't either provided detailed solution about that. And whatever they mentioned didn't worked.
Below is the code that I have tried
String arabicFormattedMessage = "Some English Text \n\n"+"رجى الاتصال بالامتثال التجاري وحماية المستهلك (ككب) من دائرة التنمية الاقتصادية في 12345678 لمزيد من التفاصيل، إذا لم يتم الاتصال في غضون 5 أيام عمل.";
jsonObject.put("message", arabicFormattedMessage );
String messageBody = new String(jsonObject.toString().getBytes(),"UTF-16BE");
String contentTypeHeader = "application/json; charset=UTF-16BE";
headers.put("authorization", base64AuthHeader);
headers.put("content-type", contentTypeHeader);
headers.put("x-timestamp", timeStampHeader);
//headers.put("encoding", "UTF-16BE"); Tried with and without this, but still not working.
Response I have recd
Sinch responseCode: 400
Sinch Response: message object is invalid. toNumber object is invalid.
As Requested in comments, Below is the working example with English Only:
JSONObject jsonObject = new JSONObject();
String formattedMessage = "some english message";
jsonObject.put("message", formattedMessage );
final String messageBody = jsonObject.toString();
final String base64AuthHeader = "basic" + " " + base64AppDetails;
String contentTypeHeader = "application/json; charset=UTF-8";
final String timeStampHeader = DateUtil.getFormattedTimeString(new Date());
headers.put("authorization", base64AuthHeader);
headers.put("content-type", contentTypeHeader);
headers.put("x-timestamp", timeStampHeader);
HTTP POST Request
HttpClient.sendHttpPostRequest(url, messageBody, headers);
After successful call, I get message id in response from Sinch