sendVideo method

Future<Message> sendVideo(
  1. dynamic chat_id,
  2. dynamic video, {
  3. int? duration,
  4. int? width,
  5. int? height,
  6. dynamic thumb,
  7. String? caption,
  8. String? parse_mode,
  9. List<MessageEntity>? caption_entities,
  10. bool? supports_streaming,
  11. bool? disable_notification,
  12. int? reply_to_message_id,
  13. bool? allow_sending_without_reply,
  14. ReplyMarkup? reply_markup,
})
inherited

Use this method to send video files

Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.

https://core.telegram.org/bots/api#sendvideo

Implementation

Future<Message> sendVideo(dynamic chat_id, dynamic video,
    {int? duration,
    int? width,
    int? height,
    dynamic thumb,
    String? caption,
    String? parse_mode,
    List<MessageEntity>? caption_entities,
    bool? supports_streaming,
    bool? disable_notification,
    int? reply_to_message_id,
    bool? allow_sending_without_reply,
    ReplyMarkup? reply_markup}) async {
  if (chat_id is! String && chat_id is! int) {
    return Future.error(TelegramException(
        'Attribute \'chat_id\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('sendVideo');
  var body = <String, dynamic>{
    'chat_id': chat_id,
    'duration': duration,
    'width': width,
    'height': height,
    'caption': caption,
    'parse_mode': parse_mode,
    'caption_entities':
        caption_entities == null ? null : jsonEncode(caption_entities),
    'supports_streaming': supports_streaming,
    'disable_notification': disable_notification,
    'reply_to_message_id': reply_to_message_id,
    'allow_sending_without_reply': allow_sending_without_reply,
    'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup),
  };

  var multiPartFiles = <MultipartFile>[];

  if (video is io.File) {
    multiPartFiles.add(HttpClient.toMultiPartFile(video, 'video'));
  } else if (video is String) {
    body.addAll({'video': video});
  } else {
    return Future.error(TelegramException(
        'Attribute \'video\' can only be either io.File or String (Telegram file_id or image url)'));
  }

  if (thumb != null) {
    if (thumb is io.File) {
      multiPartFiles.add(HttpClient.toMultiPartFile(thumb, 'thumb'));
    } else if (thumb is String) {
      body.addAll({'thumb': thumb});
    } else {
      return Future.error(TelegramException(
          'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)'));
    }
  }

  return multiPartFiles.isEmpty
      ? Message.fromJson(await HttpClient.httpPost(requestUrl, body: body))
      : Message.fromJson(await HttpClient.httpMultipartPost(
          requestUrl, multiPartFiles,
          body: body));
}