editMessageCaption method

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

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 chat_id,
    int? message_id,
    String? inline_message_id,
    String? caption,
    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('editMessageCaption');
  var body = <String, dynamic>{
    'chat_id': chat_id,
    'message_id': message_id,
    'inline_message_id': inline_message_id,
    'caption': caption,
    '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);
  }
}