editMessageCaption method

Future<Message> editMessageCaption({
  1. dynamic chatId,
  2. int? messageId,
  3. String? inlineMessageId,
  4. String? caption,
  5. String? parseMode,
  6. InlineKeyboardMarkup? replyMarkup,
})

Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).

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

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

Implementation

Future<Message> editMessageCaption(
    {dynamic chatId,
    int? messageId,
    String? inlineMessageId,
    String? caption,
    String? parseMode,
    InlineKeyboardMarkup? replyMarkup}) async {
  if (inlineMessageId == null && (chatId == null || messageId == null)) {
    return Future.error(TelegramException(
        'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\''));
  }
  if (chatId != null && (chatId is! String && chatId is! int)) {
    return Future.error(TelegramException(
        'Attribute \'chatId\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('editMessageCaption');
  var body = <String, dynamic>{
    'chat_id': chatId,
    'message_id': messageId,
    'inline_message_id': inlineMessageId,
    'caption': caption,
    'parse_mode': parseMode,
    'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
  };
  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);
  }
}