editMessageMedia method

Future<Message> editMessageMedia({
  1. dynamic chat_id,
  2. int? message_id,
  3. String? inline_message_id,
  4. InputMedia? media,
  5. String? parse_mode,
  6. InlineKeyboardMarkup? reply_markup,
})
inherited

Use this method to edit audio, document, photo, or video messages

If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, file can't be uploaded. Use previously uploaded file via its file_id or specify a URL.

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

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

Implementation

Future<Message> editMessageMedia(
    {dynamic chat_id,
    int? message_id,
    String? inline_message_id,
    InputMedia? media,
    String? parse_mode,
    InlineKeyboardMarkup? reply_markup}) async {
  if (inline_message_id == null && (chat_id == null || message_id == null)) {
    return Future.error(TelegramException(
        'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\''));
  }
  if (chat_id != null && (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('editMessageMedia');
  var body = <String, dynamic>{
    'chat_id': chat_id,
    'message_id': message_id,
    'inline_message_id': inline_message_id,
    'media': media == null ? null : jsonEncode(media),
    'parse_mode': parse_mode,
    'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup),
  };
  var res = await HttpClient.httpPost(requestUrl, body: body);
  if (res == true) {
    return Future.error(
        TelegramException('Edited message is NOT sent by the bot'));
  } else {
    return Message.fromJson(res);
  }
}