sendMediaGroup method

Future<List<Message>> sendMediaGroup(
  1. dynamic chatId,
  2. List<InputMedia> media, {
  3. int? messageThreadId,
  4. bool? disableNotification,
  5. bool? protectContent,
  6. int? replyToMessageId,
  7. bool? allowSendingWithoutReply,
})

Use this method to send a group of photos or videos as an album

On success, an array of the sent Messages is returned.

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

Implementation

Future<List<Message>> sendMediaGroup(dynamic chatId, List<InputMedia> media,
    {int? messageThreadId,
    bool? disableNotification,
    bool? protectContent,
    int? replyToMessageId,
    bool? allowSendingWithoutReply}) 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('sendMediaGroup');
  var body = <String, dynamic>{
    'chat_id': chatId,
    'message_thread_id': messageThreadId,
    'media': jsonEncode(media),
    'disable_notification': disableNotification,
    'protect_content': protectContent,
    'reply_to_message_id': replyToMessageId,
    'allow_sending_without_reply': allowSendingWithoutReply,
  };
  var multiPartFiles =
      media.map((it) => it.mediaFile).whereType<MultipartFile>().toList();
  if (media is List<InputMediaWithThumbnail>) {
    multiPartFiles.addAll(media
        .map((it) => it.thumbnailFile)
        .whereType<MultipartFile>()
        .toList());
  }
  var response = multiPartFiles.isNotEmpty
      ? await HttpClient.httpMultipartPost(requestUrl, multiPartFiles,
          body: body)
      : await HttpClient.httpPost(requestUrl, body: body);

  return response
      .map<Message>((message) => Message.fromJson(message))
      .toList();
}