sendFileMessage static method
Future<TPMessage?>
sendFileMessage(
- TPChannel tpChannel,
- String text,
- String type,
- File file,
- List<String>? mentions,
- String? parentMessageId,
- Map<String, dynamic>? metaData, {
- List<String>? translationLanguages,
- dynamic errorCallback(
- int? errorCode,
- String? errorMessage
)?,
})
Implementation
static Future<TPMessage?> sendFileMessage(
TPChannel tpChannel,
String text,
String type,
File file,
List<String>? mentions,
String? parentMessageId,
Map<String, dynamic>? metaData,
{
List<String>? translationLanguages,
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({"text": text, "type": type});
if((parentMessageId == null ? 0 : parentMessageId.length) > 0) { body['parentMessageId'] = parentMessageId; }
if((mentions == null ? 0 : mentions.length) > 0) { body['mentions'] = mentions!.join(","); }
if((metaData == null ? 0 : metaData.length) > 0) { body["data"] = convert.jsonEncode(metaData); }
if((translationLanguages == null ? 0 : translationLanguages.length) > 0) {
body['translationTargetLanguages'] = translationLanguages!.join(",");
}
try {
String url = "/channels/${tpChannel.getChannelId()}/messages/send";
Map<String, dynamic> response = await HttpUtil.postMultipart(url, body, file);
Map<String, dynamic> message = response["message"];
return TPMessage(message);
} on TPException catch(e) {
Logger.log("$e");
if(errorCallback != null) { errorCallback(e.getCode(), e.getMessage()); }
} catch(e){
Logger.log("$e");
if(errorCallback != null) { errorCallback(-1, e.toString()); }
}
return null;
}