sendAnimation method
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound)
On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
Implementation
Future<Message> sendAnimation(dynamic chatId, dynamic animation,
{int? messageThreadId,
int? duration,
int? width,
int? height,
dynamic thumbnail,
String? caption,
String? parseMode,
List<MessageEntity>? captionEntities,
bool? hasSpoiler,
bool? disableNotification,
bool? protectContent,
int? replyToMessageId,
bool? allowSendingWithoutReply,
ReplyMarkup? replyMarkup}) async {
if (chatId is! String && chatId is! int) {
return Future.error(TelegramException(
'Attribute \'chatId\' can only be either type of String or int'));
}
var requestUrl = _apiUri('sendAnimation');
var body = <String, dynamic>{
'chat_id': chatId,
'message_thread_id': messageThreadId,
'duration': duration,
'width': width,
'height': height,
'caption': caption,
'parse_mode': parseMode,
'caption_entities':
captionEntities == null ? null : jsonEncode(captionEntities),
'has_spoiler': hasSpoiler,
'disable_notification': disableNotification,
'protect_content': protectContent,
'reply_to_message_id': replyToMessageId,
'allow_sending_without_reply': allowSendingWithoutReply,
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
var multiPartFiles = <MultipartFile>[];
if (animation is io.File) {
multiPartFiles.add(HttpClient.toMultiPartFile(animation, 'animation'));
} else if (animation is String) {
body.addAll({'animation': animation});
} else {
return Future.error(TelegramException(
'Attribute \'animation\' can only be either io.File or String (Telegram fileId or image url)'));
}
if (thumbnail != null) {
if (thumbnail is io.File) {
multiPartFiles.add(HttpClient.toMultiPartFile(thumbnail, 'thumbnail'));
} else if (thumbnail is String) {
body.addAll({'thumbnail': thumbnail});
} else {
return Future.error(TelegramException(
'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)'));
}
}
return multiPartFiles.isEmpty
? Message.fromJson(await HttpClient.httpPost(requestUrl, body: body))
: Message.fromJson(await HttpClient.httpMultipartPost(
requestUrl, multiPartFiles,
body: body));
}