sendVideo method

Future<Message> sendVideo(
  1. dynamic chatId,
  2. dynamic video, {
  3. int? messageThreadId,
  4. int? duration,
  5. int? width,
  6. int? height,
  7. dynamic thumbnail,
  8. String? caption,
  9. String? parseMode,
  10. List<MessageEntity>? captionEntities,
  11. bool? hasSpoiler,
  12. bool? supportsStreaming,
  13. bool? disableNotification,
  14. bool? protectContent,
  15. int? replyToMessageId,
  16. bool? allowSendingWithoutReply,
  17. ReplyMarkup? replyMarkup,
})

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 chatId, dynamic video,
    {int? messageThreadId,
    int? duration,
    int? width,
    int? height,
    dynamic thumbnail,
    String? caption,
    String? parseMode,
    List<MessageEntity>? captionEntities,
    bool? hasSpoiler,
    bool? supportsStreaming,
    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('sendVideo');
  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,
    'supports_streaming': supportsStreaming,
    '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 (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 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));
}