translateMessage static method
Implementation
static Future<TPMessage?> translateMessage(
TPChannel tpChannel,
TPMessage tpMessage,
List<String>? targetLanguages,
{
Function(int? errorCode, String? errorMessage)? errorCallback
}) async
{
if (!_isInitialized(errorCallback: errorCallback)) { return null; }
if (!_checkAuthInfo(errorCallback: errorCallback)) { return null; }
Map<String, dynamic> body = Map.from({});
if((targetLanguages == null ? 0 : targetLanguages.length) > 0) {
body['targetLanguages'] = targetLanguages;
}
try {
String url = "/channels/${tpChannel.getChannelId()}/messages/${tpMessage.getMessageId()}/translate";
Map<String, dynamic> response = await HttpUtil.postJson(url, body);
Map<String, dynamic> message = response["message"];
return TPMessage(message);
} on TPException catch(e) {
Logger.log("${e.getCode()}, ${e.getMessage()}");
errorCallback?.call(e.getCode(), e.getMessage());
} catch(e){
Logger.log("$e");
errorCallback?.call(-1, e.toString());
}
return null;
}